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

#stub_imminence_has_areas_for_postcode(postcode, areas) ⇒ Object


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

def stub_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

#stub_imminence_has_places(latitude, longitude, details) ⇒ Object


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

def stub_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

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


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

def stub_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


35
36
37
38
39
# File 'lib/gds_api/test_helpers/imminence.rb', line 35

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