-
Notifications
You must be signed in to change notification settings - Fork 14
/
places_manager.rb
48 lines (43 loc) · 1.8 KB
/
places_manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "gds_api/test_helpers/json_client_helper"
module GdsApi
module TestHelpers
module PlacesManager
# Generally true. If you are initializing the client differently,
# you could redefine/override the constant or stub directly.
PLACES_MANAGER_API_ENDPOINT = Plek.find("places-manager")
def stub_places_manager_has_places(latitude, longitude, details)
query_hash = { "lat" => latitude, "lng" => longitude, "limit" => "5" }
response_data = {
status: "ok",
content: "places",
places: details["details"],
}
stub_places_manager_places_request(details["slug"], query_hash, response_data)
end
def stub_places_manager_has_multiple_authorities_for_postcode(addresses, slug, postcode, limit)
query_hash = { "postcode" => postcode, "limit" => limit }
response_data = {
status: "address-information-required",
content: "addresses",
addresses:,
}
stub_places_manager_places_request(slug, query_hash, response_data)
end
def stub_places_manager_has_places_for_postcode(places, slug, postcode, limit, local_authority_slug)
query_hash = { "postcode" => postcode, "limit" => limit }
query_hash.merge!(local_authority_slug:) if local_authority_slug
response_data = {
status: "ok",
content: "places",
places:,
}
stub_places_manager_places_request(slug, query_hash, response_data)
end
def stub_places_manager_places_request(slug, query_hash, return_data, status_code = 200)
stub_request(:get, "#{PLACES_MANAGER_API_ENDPOINT}/places/#{slug}.json")
.with(query: query_hash)
.to_return(status: status_code, body: return_data.to_json, headers: {})
end
end
end
end