-
Notifications
You must be signed in to change notification settings - Fork 14
/
places_manager_api_pact_test.rb
88 lines (82 loc) · 2.95 KB
/
places_manager_api_pact_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "test_helper"
require "gds_api/places_manager"
describe "GdsApi::PlacesManager pact tests" do
include PactTest
describe "#places" do
let(:api_client) { GdsApi::PlacesManager.new(places_manager_api_host) }
it "responds with all responses for the given dataset" do
places_manager_api
.given("a service exists called number-plate-supplier with places")
.upon_receiving("the request to retrieve relevant places for the current dataset for a lat/lon")
.with(
method: :get,
path: "/places/number-plate-supplier.json",
headers: GdsApi::JsonClient.default_request_headers,
query: { lat: "-2.01", lng: "53.1", limit: "5" },
)
.will_respond_with(
status: 200,
body: {
status: "ok",
contents: "places",
places: Pact.each_like(
{
access_notes: nil,
address1: "Yarrow Road Tower Park",
address2: nil,
data_set_version: 473,
email: nil,
fax: nil,
general_notes: nil,
geocode_error: nil,
location: { longitude: -1.9552618901330387, latitude: 50.742754933617285 },
name: "Breeze Motor Co Ltd",
override_lat: nil,
override_lng: nil,
phone: "01202 713000",
postcode: "BH12 4QY",
service_slug: "number-plate-supplier",
gss: nil,
source_address: "Yarrow Road Tower Park Poole BH12 4QY",
text_phone: nil,
town: "Yarrow",
url: nil,
},
),
},
headers: {
"Content-Type" => "application/json; charset=utf-8",
},
)
api_client.places("number-plate-supplier", "-2.01", "53.1", "5")
end
it "responds with a choice of addresses for disambiguation of split postcodes" do
places_manager_api
.given("a service exists called register office exists with places, and CH25 9BJ is a split postcode")
.upon_receiving("the request to retrieve relevant places for the current dataset for CH25 9BJ")
.with(
method: :get,
path: "/places/register-office.json",
headers: GdsApi::JsonClient.default_request_headers,
query: { postcode: "CH25 9BJ", limit: "5" },
)
.will_respond_with(
status: 200,
body: {
status: "address-information-required",
contents: "addresses",
addresses: Pact.each_like(
{
address: "HOUSE 1",
local_authority_slug: "achester",
},
),
},
headers: {
"Content-Type" => "application/json; charset=utf-8",
},
)
api_client.places_for_postcode("register-office", "CH25 9BJ")
end
end
end