Guest User

Untitled

a guest
Feb 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. describe 'POST search' do
  2. it 'renders search' do
  3. request.headers['Content-Type'] = 'application/json'
  4. request.headers['Accept'] = 'application/json'
  5.  
  6. post :search, body: {name: {query_type: 'match', value: ['xy']} }.to_json
  7.  
  8. expect(response.status).to eq(200)
  9. expect(response.body.include?('TWEEDLE'))
  10. end
  11. end
  12.  
  13. def search
  14. page_params = pagination_params
  15.  
  16. query_hash = QueryPreprocessor.params_to_query_with_types(JSON.parse(request.body.read).deep_symbolize_keys)
  17. logger.info "query_hash: #{query_hash}"
  18. es_query_json = Elastic::QueryBuilder.facility_search_v1(query_hash, page_params).to_json
  19. logger.info "es query: #{es_query_json}"
  20.  
  21. facilities = facility_helper.search es_query_json
  22. json_response build_facilities_response(facilities)
  23. rescue ApiError => e
  24. render json: e.response, status: e.status
  25. end
  26.  
  27. def pagination_params
  28. page_params = {}
  29. page_params['size_params'] = params[:size] || 50
  30. page_params['from_params'] = params[:from] || 0
  31. page_params['sort_params'] = params[:sort]
  32. page_params['order_params'] = params[:order]
  33. page_params
  34. end
Add Comment
Please, Sign In to add comment