Module: GdsApi::TestHelpers::Imminence

Defined in:
lib/gds_api/test_helpers/imminence.rb

Constant Summary collapse

IMMINENCE_API_ENDPOINT =

Generally true. If you are initializing the client differently, you could redefine/override the constant or stub directly.

Plek.current.find('imminence')

Instance Method Summary collapse

Instance Method Details

#imminence_has_areas_for_postcode(postcode, areas) ⇒ Object


15
16
17
18
19
20
21
22
23
24
# File 'lib/gds_api/test_helpers/imminence.rb', line 15

def imminence_has_areas_for_postcode(postcode, areas)
  results = {
    "_response_info" => { "status" => "ok" },
    "total" => areas.size, "startIndex" => 1, "pageSize" => areas.size,
    "currentPage" => 1, "pages" => 1, "results" => areas
  }

  stub_request(:get, %r{\A#{IMMINENCE_API_ENDPOINT}/areas/#{postcode}\.json}).
    to_return(body: results.to_json)
end

#imminence_has_places(latitude, longitude, details) ⇒ Object


10
11
12
13
# File 'lib/gds_api/test_helpers/imminence.rb', line 10

def imminence_has_places(latitude, longitude, details)
  query_hash = { "lat" => latitude, "lng" => longitude, "limit" => "5" }
  stub_imminence_places_request(details['slug'], query_hash, details['details'])
end

#imminence_has_places_for_postcode(places, slug, postcode, limit) ⇒ Object


26
27
28
29
# File 'lib/gds_api/test_helpers/imminence.rb', line 26

def imminence_has_places_for_postcode(places, slug, postcode, limit)
  query_hash = { "postcode" => postcode, "limit" => limit }
  stub_imminence_places_request(slug, query_hash, places)
end

#stub_imminence_places_request(slug, query_hash, return_data, status_code = 200) ⇒ Object


31
32
33
34
35
# File 'lib/gds_api/test_helpers/imminence.rb', line 31

def stub_imminence_places_request(slug, query_hash, return_data, status_code = 200)
  stub_request(:get, "#{IMMINENCE_API_ENDPOINT}/places/#{slug}.json").
  with(query: query_hash).
  to_return(status: status_code, body: return_data.to_json, headers: {})
end