defra_ruby_address 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +82 -6
- data/Rakefile +2 -2
- data/bin/console +2 -6
- data/lib/defra_ruby/address/helmert_transformation.rb +102 -0
- data/lib/defra_ruby/address/response.rb +1 -2
- data/lib/defra_ruby/address/services/base_service.rb +2 -2
- data/lib/defra_ruby/address/services/easting_northing_to_lat_lon_service.rb +18 -0
- data/lib/defra_ruby/address/services/lat_lon_to_easting_northing_service.rb +20 -0
- data/lib/defra_ruby/address/services/os_api_address_lookup_v1_service.rb +100 -0
- data/lib/defra_ruby/address/services/os_places_address_lookup_service.rb +11 -14
- data/lib/defra_ruby/address/transverse_mercator_projection.rb +151 -0
- data/lib/defra_ruby/address/version.rb +1 -1
- data/lib/defra_ruby/address.rb +5 -0
- metadata +11 -181
- data/spec/defra_ruby/address/configuration_spec.rb +0 -18
- data/spec/defra_ruby/address/response_spec.rb +0 -70
- data/spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb +0 -73
- data/spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb +0 -73
- data/spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb +0 -72
- data/spec/defra_ruby/address_spec.rb +0 -30
- data/spec/examples.txt +0 -27
- data/spec/fixtures/ea_address_facade_v1_1_blank.json +0 -8
- data/spec/fixtures/ea_address_facade_v1_1_not_found.json +0 -14
- data/spec/fixtures/ea_address_facade_v1_1_valid.json +0 -83
- data/spec/fixtures/ea_address_facade_v1_blank.json +0 -13
- data/spec/fixtures/ea_address_facade_v1_not_found.json +0 -8
- data/spec/fixtures/ea_address_facade_v1_valid.json +0 -45
- data/spec/fixtures/os_places_address_lookup_blank.json +0 -5
- data/spec/fixtures/os_places_address_lookup_not_found.json +0 -6
- data/spec/fixtures/os_places_address_lookup_valid.json +0 -56
- data/spec/spec_helper.rb +0 -83
- data/spec/support/defra_ruby_address.rb +0 -4
- data/spec/support/dotenv.rb +0 -4
- data/spec/support/pry.rb +0 -7
- data/spec/support/shared_examples/handle_request_errors.rb +0 -32
- data/spec/support/simplecov.rb +0 -17
- data/spec/support/webmock.rb +0 -4
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: defra_ruby_address
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Defra
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rest-client
|
|
@@ -24,132 +23,6 @@ dependencies:
|
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '2.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: defra_ruby_style
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: dotenv
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: github_changelog_generator
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: pry-byebug
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: rake
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: rspec
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '3.0'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '3.0'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: rubocop
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - ">="
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '0'
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - ">="
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: '0'
|
|
125
|
-
- !ruby/object:Gem::Dependency
|
|
126
|
-
name: simplecov
|
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - ">="
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '0'
|
|
132
|
-
type: :development
|
|
133
|
-
prerelease: false
|
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
-
requirements:
|
|
136
|
-
- - ">="
|
|
137
|
-
- !ruby/object:Gem::Version
|
|
138
|
-
version: '0'
|
|
139
|
-
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: webmock
|
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
|
142
|
-
requirements:
|
|
143
|
-
- - "~>"
|
|
144
|
-
- !ruby/object:Gem::Version
|
|
145
|
-
version: '3.4'
|
|
146
|
-
type: :development
|
|
147
|
-
prerelease: false
|
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - "~>"
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: '3.4'
|
|
153
26
|
description: Provides a single source of functionality for querying Defra's various
|
|
154
27
|
address lookup services.
|
|
155
28
|
email:
|
|
@@ -167,42 +40,24 @@ files:
|
|
|
167
40
|
- lib/defra_ruby/address.rb
|
|
168
41
|
- lib/defra_ruby/address/configuration.rb
|
|
169
42
|
- lib/defra_ruby/address/ea_address_facade_request.rb
|
|
43
|
+
- lib/defra_ruby/address/helmert_transformation.rb
|
|
170
44
|
- lib/defra_ruby/address/no_match_error.rb
|
|
171
45
|
- lib/defra_ruby/address/response.rb
|
|
172
46
|
- lib/defra_ruby/address/services/base_service.rb
|
|
173
47
|
- lib/defra_ruby/address/services/ea_address_facade_v1_1_service.rb
|
|
174
48
|
- lib/defra_ruby/address/services/ea_address_facade_v1_service.rb
|
|
49
|
+
- lib/defra_ruby/address/services/easting_northing_to_lat_lon_service.rb
|
|
50
|
+
- lib/defra_ruby/address/services/lat_lon_to_easting_northing_service.rb
|
|
51
|
+
- lib/defra_ruby/address/services/os_api_address_lookup_v1_service.rb
|
|
175
52
|
- lib/defra_ruby/address/services/os_places_address_lookup_service.rb
|
|
53
|
+
- lib/defra_ruby/address/transverse_mercator_projection.rb
|
|
176
54
|
- lib/defra_ruby/address/version.rb
|
|
177
|
-
- spec/defra_ruby/address/configuration_spec.rb
|
|
178
|
-
- spec/defra_ruby/address/response_spec.rb
|
|
179
|
-
- spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb
|
|
180
|
-
- spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb
|
|
181
|
-
- spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb
|
|
182
|
-
- spec/defra_ruby/address_spec.rb
|
|
183
|
-
- spec/examples.txt
|
|
184
|
-
- spec/fixtures/ea_address_facade_v1_1_blank.json
|
|
185
|
-
- spec/fixtures/ea_address_facade_v1_1_not_found.json
|
|
186
|
-
- spec/fixtures/ea_address_facade_v1_1_valid.json
|
|
187
|
-
- spec/fixtures/ea_address_facade_v1_blank.json
|
|
188
|
-
- spec/fixtures/ea_address_facade_v1_not_found.json
|
|
189
|
-
- spec/fixtures/ea_address_facade_v1_valid.json
|
|
190
|
-
- spec/fixtures/os_places_address_lookup_blank.json
|
|
191
|
-
- spec/fixtures/os_places_address_lookup_not_found.json
|
|
192
|
-
- spec/fixtures/os_places_address_lookup_valid.json
|
|
193
|
-
- spec/spec_helper.rb
|
|
194
|
-
- spec/support/defra_ruby_address.rb
|
|
195
|
-
- spec/support/dotenv.rb
|
|
196
|
-
- spec/support/pry.rb
|
|
197
|
-
- spec/support/shared_examples/handle_request_errors.rb
|
|
198
|
-
- spec/support/simplecov.rb
|
|
199
|
-
- spec/support/webmock.rb
|
|
200
55
|
homepage: https://github.com/DEFRA/defra-ruby-address
|
|
201
56
|
licenses:
|
|
202
57
|
- The Open Government Licence (OGL) Version 3
|
|
203
58
|
metadata:
|
|
204
59
|
allowed_push_host: https://rubygems.org
|
|
205
|
-
|
|
60
|
+
rubygems_mfa_required: 'true'
|
|
206
61
|
rdoc_options: []
|
|
207
62
|
require_paths:
|
|
208
63
|
- lib
|
|
@@ -210,39 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
210
65
|
requirements:
|
|
211
66
|
- - ">="
|
|
212
67
|
- !ruby/object:Gem::Version
|
|
213
|
-
version: '
|
|
68
|
+
version: '3.2'
|
|
214
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
70
|
requirements:
|
|
216
71
|
- - ">="
|
|
217
72
|
- !ruby/object:Gem::Version
|
|
218
73
|
version: '0'
|
|
219
74
|
requirements: []
|
|
220
|
-
|
|
221
|
-
rubygems_version: 2.6.13
|
|
222
|
-
signing_key:
|
|
75
|
+
rubygems_version: 3.6.9
|
|
223
76
|
specification_version: 4
|
|
224
77
|
summary: Defra ruby on rails address lookup gem
|
|
225
|
-
test_files:
|
|
226
|
-
- spec/spec_helper.rb
|
|
227
|
-
- spec/defra_ruby/address/configuration_spec.rb
|
|
228
|
-
- spec/defra_ruby/address/response_spec.rb
|
|
229
|
-
- spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb
|
|
230
|
-
- spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb
|
|
231
|
-
- spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb
|
|
232
|
-
- spec/defra_ruby/address_spec.rb
|
|
233
|
-
- spec/examples.txt
|
|
234
|
-
- spec/support/defra_ruby_address.rb
|
|
235
|
-
- spec/support/simplecov.rb
|
|
236
|
-
- spec/support/webmock.rb
|
|
237
|
-
- spec/support/pry.rb
|
|
238
|
-
- spec/support/dotenv.rb
|
|
239
|
-
- spec/support/shared_examples/handle_request_errors.rb
|
|
240
|
-
- spec/fixtures/ea_address_facade_v1_1_not_found.json
|
|
241
|
-
- spec/fixtures/os_places_address_lookup_blank.json
|
|
242
|
-
- spec/fixtures/ea_address_facade_v1_1_valid.json
|
|
243
|
-
- spec/fixtures/ea_address_facade_v1_valid.json
|
|
244
|
-
- spec/fixtures/ea_address_facade_v1_blank.json
|
|
245
|
-
- spec/fixtures/ea_address_facade_v1_1_blank.json
|
|
246
|
-
- spec/fixtures/os_places_address_lookup_valid.json
|
|
247
|
-
- spec/fixtures/ea_address_facade_v1_not_found.json
|
|
248
|
-
- spec/fixtures/os_places_address_lookup_not_found.json
|
|
78
|
+
test_files: []
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Address
|
|
7
|
-
RSpec.describe Configuration do
|
|
8
|
-
it "sets the appropriate default config settings" do
|
|
9
|
-
fresh_config = described_class.new
|
|
10
|
-
|
|
11
|
-
expect(fresh_config.timeout).to eq(3)
|
|
12
|
-
expect(fresh_config.host).to be_nil
|
|
13
|
-
expect(fresh_config.client_id).to eq(0)
|
|
14
|
-
expect(fresh_config.key).to eq("client1")
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Address
|
|
7
|
-
RSpec.describe Response do
|
|
8
|
-
subject(:response) { described_class.new(response_exe) }
|
|
9
|
-
|
|
10
|
-
let(:successful) { -> { [{ "postcode" => "BS1 5AH" }] } }
|
|
11
|
-
let(:errored) { -> { raise "Boom!" } }
|
|
12
|
-
|
|
13
|
-
describe "#successful?" do
|
|
14
|
-
context "when the response throws an error" do
|
|
15
|
-
let(:response_exe) { errored }
|
|
16
|
-
|
|
17
|
-
it "returns false" do
|
|
18
|
-
expect(response).to_not be_successful
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context "when the response doesn't throw an error" do
|
|
23
|
-
let(:response_exe) { successful }
|
|
24
|
-
|
|
25
|
-
it "returns true" do
|
|
26
|
-
expect(response).to be_successful
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#results" do
|
|
32
|
-
context "when the response throws an error" do
|
|
33
|
-
let(:response_exe) { errored }
|
|
34
|
-
|
|
35
|
-
it "returns an empty array" do
|
|
36
|
-
expect(response.results).to eq([])
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "when the response does not throw an error" do
|
|
41
|
-
let(:response_exe) { successful }
|
|
42
|
-
|
|
43
|
-
it "returns a JSON array" do
|
|
44
|
-
expect(response.results).to be_instance_of(Array)
|
|
45
|
-
expect(response.results[0]).to be_instance_of(Hash)
|
|
46
|
-
expect(response.results[0]["postcode"]).to eq("BS1 5AH")
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "#error" do
|
|
52
|
-
context "when the response throws an error" do
|
|
53
|
-
let(:response_exe) { errored }
|
|
54
|
-
|
|
55
|
-
it "returns the error" do
|
|
56
|
-
expect(response.error).to be_a(StandardError)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "when the response don't throw an error" do
|
|
61
|
-
let(:response_exe) { successful }
|
|
62
|
-
|
|
63
|
-
it "returns a nil object" do
|
|
64
|
-
expect(response.error).to be_nil
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Address
|
|
7
|
-
RSpec.describe EaAddressFacadeV11Service do
|
|
8
|
-
describe "#run" do
|
|
9
|
-
before do
|
|
10
|
-
DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
|
|
11
|
-
stub_request(:get, url).to_return(status: code, body: body)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
let(:client_id) { DefraRuby::Address.configuration.client_id }
|
|
15
|
-
let(:key) { DefraRuby::Address.configuration.key }
|
|
16
|
-
let(:postcode) { "BS1 5AH" }
|
|
17
|
-
let(:url) { "http://localhost:8005/address-service/v1/addresses/postcode?client-id=#{client_id}&key=#{key}&query-string=#{postcode}" }
|
|
18
|
-
let(:code) { 200 }
|
|
19
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_valid.json") }
|
|
20
|
-
|
|
21
|
-
include_examples "handle request errors"
|
|
22
|
-
|
|
23
|
-
context "when the postcode is valid" do
|
|
24
|
-
|
|
25
|
-
it "returns a successful response" do
|
|
26
|
-
response = described_class.run(postcode)
|
|
27
|
-
|
|
28
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
29
|
-
|
|
30
|
-
expect(response).to be_a(Response)
|
|
31
|
-
expect(response.successful?).to eq(true)
|
|
32
|
-
expect(response.results).not_to be_empty
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "when the postcode is invalid" do
|
|
37
|
-
context "because it is not found" do
|
|
38
|
-
let(:postcode) { "BS1 9XX" }
|
|
39
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_not_found.json") }
|
|
40
|
-
|
|
41
|
-
it "returns a 'NoMatchError'" do
|
|
42
|
-
response = described_class.run(postcode)
|
|
43
|
-
|
|
44
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
45
|
-
|
|
46
|
-
expect(response).to be_a(Response)
|
|
47
|
-
expect(response).to_not be_successful
|
|
48
|
-
expect(response.results).to be_empty
|
|
49
|
-
expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "because it is blank" do
|
|
54
|
-
let(:postcode) { "" }
|
|
55
|
-
let(:code) { 400 }
|
|
56
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_blank.json") }
|
|
57
|
-
|
|
58
|
-
it "returns a failed response" do
|
|
59
|
-
response = described_class.run(postcode)
|
|
60
|
-
|
|
61
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
62
|
-
|
|
63
|
-
expect(response).to be_a(Response)
|
|
64
|
-
expect(response).to_not be_successful
|
|
65
|
-
expect(response.results).to be_empty
|
|
66
|
-
expect(response.error).to be_an_instance_of(RestClient::BadRequest)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Address
|
|
7
|
-
RSpec.describe EaAddressFacadeV1Service do
|
|
8
|
-
describe "#run" do
|
|
9
|
-
before do
|
|
10
|
-
DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
|
|
11
|
-
stub_request(:get, url).to_return(status: code, body: body)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
let(:client_id) { DefraRuby::Address.configuration.client_id }
|
|
15
|
-
let(:key) { DefraRuby::Address.configuration.key }
|
|
16
|
-
let(:postcode) { "BS1 5AH" }
|
|
17
|
-
let(:url) { "http://localhost:8005/address-service/v1/addresses/postcode?client-id=#{client_id}&key=#{key}&postcode=#{postcode}" }
|
|
18
|
-
let(:code) { 200 }
|
|
19
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_valid.json") }
|
|
20
|
-
|
|
21
|
-
include_examples "handle request errors"
|
|
22
|
-
|
|
23
|
-
context "when the postcode is valid" do
|
|
24
|
-
|
|
25
|
-
it "returns a successful response" do
|
|
26
|
-
response = described_class.run(postcode)
|
|
27
|
-
|
|
28
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
29
|
-
|
|
30
|
-
expect(response).to be_a(Response)
|
|
31
|
-
expect(response.successful?).to eq(true)
|
|
32
|
-
expect(response.results).not_to be_empty
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "when the postcode is invalid" do
|
|
37
|
-
context "because it is not found" do
|
|
38
|
-
let(:postcode) { "BS1 9XX" }
|
|
39
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_not_found.json") }
|
|
40
|
-
|
|
41
|
-
it "returns a 'NoMatchError'" do
|
|
42
|
-
response = described_class.run(postcode)
|
|
43
|
-
|
|
44
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
45
|
-
|
|
46
|
-
expect(response).to be_a(Response)
|
|
47
|
-
expect(response).to_not be_successful
|
|
48
|
-
expect(response.results).to be_empty
|
|
49
|
-
expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "because it is blank" do
|
|
54
|
-
let(:postcode) { "" }
|
|
55
|
-
let(:code) { 400 }
|
|
56
|
-
let(:body) { File.read("spec/fixtures/ea_address_facade_v1_blank.json") }
|
|
57
|
-
|
|
58
|
-
it "returns a failed response" do
|
|
59
|
-
response = described_class.run(postcode)
|
|
60
|
-
|
|
61
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
62
|
-
|
|
63
|
-
expect(response).to be_a(Response)
|
|
64
|
-
expect(response).to_not be_successful
|
|
65
|
-
expect(response.results).to be_empty
|
|
66
|
-
expect(response.error).to be_an_instance_of(RestClient::BadRequest)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Address
|
|
7
|
-
RSpec.describe OsPlacesAddressLookupService do
|
|
8
|
-
describe "#run" do
|
|
9
|
-
before do
|
|
10
|
-
DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
|
|
11
|
-
stub_request(:get, url).to_return(status: code, body: body)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
let(:postcode) { "BS1 5AH" }
|
|
15
|
-
let(:url) { "http://localhost:8005/addresses?postcode=#{postcode}" }
|
|
16
|
-
let(:code) { 200 }
|
|
17
|
-
let(:body) { File.read("spec/fixtures/os_places_address_lookup_valid.json") }
|
|
18
|
-
|
|
19
|
-
include_examples "handle request errors"
|
|
20
|
-
|
|
21
|
-
context "when the postcode is valid" do
|
|
22
|
-
|
|
23
|
-
it "returns a successful response" do
|
|
24
|
-
response = described_class.run(postcode)
|
|
25
|
-
|
|
26
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
27
|
-
|
|
28
|
-
expect(response).to be_a(Response)
|
|
29
|
-
expect(response.successful?).to eq(true)
|
|
30
|
-
expect(response.results).not_to be_empty
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "when the postcode is invalid" do
|
|
35
|
-
let(:code) { 400 }
|
|
36
|
-
|
|
37
|
-
context "because it is not found" do
|
|
38
|
-
let(:postcode) { "BS1 9XX" }
|
|
39
|
-
let(:body) { File.read("spec/fixtures/os_places_address_lookup_not_found.json") }
|
|
40
|
-
|
|
41
|
-
it "returns a 'NoMatchError'" do
|
|
42
|
-
response = described_class.run(postcode)
|
|
43
|
-
|
|
44
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
45
|
-
|
|
46
|
-
expect(response).to be_a(Response)
|
|
47
|
-
expect(response).to_not be_successful
|
|
48
|
-
expect(response.results).to be_empty
|
|
49
|
-
expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "because it is blank" do
|
|
54
|
-
let(:postcode) { "" }
|
|
55
|
-
let(:body) { File.read("spec/fixtures/os_places_address_lookup_blank.json") }
|
|
56
|
-
|
|
57
|
-
it "returns a failed response" do
|
|
58
|
-
response = described_class.run(postcode)
|
|
59
|
-
|
|
60
|
-
expect(a_request(:get, url)).to have_been_made.at_most_once
|
|
61
|
-
|
|
62
|
-
expect(response).to be_a(Response)
|
|
63
|
-
expect(response).to_not be_successful
|
|
64
|
-
expect(response.results).to be_empty
|
|
65
|
-
expect(response.error).to be_an_instance_of(RestClient::BadRequest)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe DefraRuby::Address do
|
|
6
|
-
describe "VERSION" do
|
|
7
|
-
it "is a version string in the correct format" do
|
|
8
|
-
expect(DefraRuby::Address::VERSION).to be_a(String)
|
|
9
|
-
expect(DefraRuby::Address::VERSION).to match(/\d+\.\d+\.\d+/)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "#configuration" do
|
|
14
|
-
context "when the host app has not provided configuration" do
|
|
15
|
-
it "returns a DefraRuby::Address::Configuration instance" do
|
|
16
|
-
expect(described_class.configuration).to be_an_instance_of(DefraRuby::Address::Configuration)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "when the host app has provided configuration" do
|
|
21
|
-
let(:host) { "http://localhost:9012" }
|
|
22
|
-
|
|
23
|
-
it "returns an DefraRuby::Address::Configuration instance with a matching host" do
|
|
24
|
-
described_class.configure { |config| config.host = host }
|
|
25
|
-
|
|
26
|
-
expect(described_class.configuration.host).to eq(host)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/spec/examples.txt
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
example_id | status | run_time |
|
|
2
|
-
-------------------------------------------------------------------------------------- | ------ | --------------- |
|
|
3
|
-
./spec/defra_ruby/address/configuration_spec.rb[1:1] | passed | 0.00888 seconds |
|
|
4
|
-
./spec/defra_ruby/address/response_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
|
|
5
|
-
./spec/defra_ruby/address/response_spec.rb[1:1:2:1] | passed | 0.0003 seconds |
|
|
6
|
-
./spec/defra_ruby/address/response_spec.rb[1:2:1:1] | passed | 0.0001 seconds |
|
|
7
|
-
./spec/defra_ruby/address/response_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
|
|
8
|
-
./spec/defra_ruby/address/response_spec.rb[1:3:1:1] | passed | 0.00011 seconds |
|
|
9
|
-
./spec/defra_ruby/address/response_spec.rb[1:3:2:1] | passed | 0.0001 seconds |
|
|
10
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:1:1:1] | passed | 0.00301 seconds |
|
|
11
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:1:2:1] | passed | 0.00311 seconds |
|
|
12
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:2:1] | passed | 0.01005 seconds |
|
|
13
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:3:1:1] | passed | 0.01183 seconds |
|
|
14
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:3:2:1] | passed | 0.00571 seconds |
|
|
15
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:1:1:1] | passed | 0.00323 seconds |
|
|
16
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:1:2:1] | passed | 0.00337 seconds |
|
|
17
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:2:1] | passed | 0.02025 seconds |
|
|
18
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:3:1:1] | passed | 0.0075 seconds |
|
|
19
|
-
./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:3:2:1] | passed | 0.00576 seconds |
|
|
20
|
-
./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:1:1:1] | passed | 0.0035 seconds |
|
|
21
|
-
./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:1:2:1] | passed | 0.00558 seconds |
|
|
22
|
-
./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:2:1] | passed | 0.0041 seconds |
|
|
23
|
-
./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:3:1:1] | passed | 0.00572 seconds |
|
|
24
|
-
./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:3:2:1] | passed | 0.00559 seconds |
|
|
25
|
-
./spec/defra_ruby/address_spec.rb[1:1:1] | passed | 0.00494 seconds |
|
|
26
|
-
./spec/defra_ruby/address_spec.rb[1:2:1:1] | passed | 0.00262 seconds |
|
|
27
|
-
./spec/defra_ruby/address_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"facade_status_code": 400,
|
|
3
|
-
"facade_error_message": "bad request to facade service, no request made to supplier service. required paramater missing.",
|
|
4
|
-
"facade_error_code": "address_service_error_13",
|
|
5
|
-
"supplier_was_called": false,
|
|
6
|
-
"supplier_status_code": null,
|
|
7
|
-
"supplier_response": null
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"header": {
|
|
3
|
-
"totalMatches": 0,
|
|
4
|
-
"startMatch": null,
|
|
5
|
-
"endMatch": null,
|
|
6
|
-
"query": "postcode=BS1 9XX",
|
|
7
|
-
"language": "EN",
|
|
8
|
-
"dataset": "DPA",
|
|
9
|
-
"epoch": "70",
|
|
10
|
-
"uriToSupplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=BS1%209XX&fq=logical_status_code%3A1&dataset=DPA",
|
|
11
|
-
"uriFromClient": ""
|
|
12
|
-
},
|
|
13
|
-
"results": []
|
|
14
|
-
}
|