defra_ruby_mocks 5.3.0 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5df956ffaf0644fb9dae96ae157ec7f45b8121d6bc42e5cd96164de8470342a
4
- data.tar.gz: 6da12c96f050164e579932bf9ad188866198db203893ab436fc84c0a1e4ceeb8
3
+ metadata.gz: e24d648c7432078c7cc69a30923d8200fa3583702c60f573b28a02aeb46e3a73
4
+ data.tar.gz: 4748ab1db603a4a773ca7bd397895050606175b10c5f04ddf6f6b8aea4390cc4
5
5
  SHA512:
6
- metadata.gz: df8d21f730573cdf3d97f10a6e41a4c2d7464e62ac3c5d032190fb6b5b9a21c9bc7a76cce56fadcfb757affd1cb21b1c2b5a6bc8a24c33c1a8db882543ffab14
7
- data.tar.gz: bed07b31c14573ba390b13294a69f3209538616bd360379d0efb7b6dcc7b57c42406b6b4cc6e1cdc307933851e07c4537f876c0f9f8e80afdc953bdeec10a47d
6
+ metadata.gz: 5d5e22baf1ebcb28785f32a5578511ec0b5b7fd8888d7ec54a95970d7fef440f691f5ce2699b5590b601ea21b7f66d5c04556703ef5774c56f6ae96916ef637a
7
+ data.tar.gz: 9a4c263655f8903e6e452e1eeb996ae27c754d06dc852ae409b1cc962e3e88d25d41445f17dbe74c8200749cd1db2363c81c9fb66a2a3a29cf231d52b709e77a
data/README.md CHANGED
@@ -132,6 +132,41 @@ The list of possible statuses was taken from
132
132
  - [Companies House API](https://developer.companieshouse.gov.uk/api/docs/company/company_number/companyProfile-resource.html)
133
133
  - [Companies House API enumerations](https://github.com/companieshouse/api-enumerations/blob/master/constants.yml)
134
134
 
135
+ ### OS Places
136
+
137
+ When mounted into an app you can make requests to `/mocks/places/v1/postcode?postcode=[postcode]` to get a mock address lookup response in the OS Places API DPA format.
138
+
139
+ ```bash
140
+ curl "http://localhost:3000/mocks/places/v1/postcode?postcode=BS1%205AH"
141
+ {
142
+ "results": [
143
+ {
144
+ "DPA": {
145
+ "UPRN": "340116",
146
+ "ADDRESS": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
147
+ "ORGANISATION_NAME": "ENVIRONMENT AGENCY",
148
+ "BUILDING_NAME": "HORIZON HOUSE",
149
+ "THOROUGHFARE_NAME": "DEANERY ROAD",
150
+ "POST_TOWN": "BRISTOL",
151
+ "POSTCODE": "BS1 5AH",
152
+ "X_COORDINATE": 358205.0,
153
+ "Y_COORDINATE": 172708.0,
154
+ ...
155
+ }
156
+ },
157
+ ...
158
+ ]
159
+ }
160
+ ```
161
+
162
+ #### Postcodes
163
+
164
+ The mock normalizes postcodes by converting to uppercase and removing spaces. Currently the following postcodes return mock data:
165
+
166
+ - `BS1 5AH` - Returns two addresses (Environment Agency Horizon House, Bristol)
167
+
168
+ Any other postcode will return `{"results": []}`.
169
+
135
170
  ### Govpay
136
171
 
137
172
  When mounted into an app you can simulate interacting with the Govpay hosted pages service. The following endpoints are supported:
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyMocks
4
+ class OsPlacesController < ::DefraRubyMocks::ApplicationController
5
+ def postcode
6
+ results = OsPlacesService.run(params[:postcode]).results
7
+ render json: { "results" => results }
8
+ end
9
+ end
10
+ end
@@ -21,6 +21,7 @@ module DefraRubyMocks
21
21
  new.remove(bucket_name, file_name)
22
22
  end
23
23
 
24
+ # rubocop:disable Naming/PredicateMethod
24
25
  def write(bucket_name, file_name, content)
25
26
  @bucket_name = bucket_name
26
27
  @file_name = file_name
@@ -32,6 +33,7 @@ module DefraRubyMocks
32
33
 
33
34
  true
34
35
  end
36
+ # rubocop:enable Naming/PredicateMethod
35
37
 
36
38
  def read(bucket_name, file_name)
37
39
  @bucket_name = bucket_name
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyMocks
4
+ class OsPlacesService < BaseService
5
+ # Mock addresses in OS Places API DPA format, keyed by normalized postcode
6
+ MOCK_ADDRESSES = {
7
+ "BS15AH" => [
8
+ {
9
+ "DPA" => {
10
+ "UPRN" => "340116",
11
+ "ADDRESS" => "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
12
+ "ORGANISATION_NAME" => "ENVIRONMENT AGENCY",
13
+ "BUILDING_NAME" => "HORIZON HOUSE",
14
+ "THOROUGHFARE_NAME" => "DEANERY ROAD",
15
+ "POST_TOWN" => "BRISTOL",
16
+ "POSTCODE" => "BS1 5AH",
17
+ "X_COORDINATE" => 358_205.0,
18
+ "Y_COORDINATE" => 172_708.0,
19
+ "DEPENDENT_LOCALITY" => "",
20
+ "MATCH" => 1.0,
21
+ "MATCH_DESCRIPTION" => "EXACT",
22
+ "LANGUAGE" => "EN",
23
+ "LAST_UPDATE_DATE" => "2024-01-01",
24
+ "ENTRY_DATE" => "2020-01-01",
25
+ "BLPU_STATE_CODE" => "2",
26
+ "BLPU_STATE_CODE_DESCRIPTION" => "In use",
27
+ "CLASSIFICATION_CODE" => "CO01",
28
+ "CLASSIFICATION_CODE_DESCRIPTION" => "Office / Work Studio",
29
+ "POSTAL_ADDRESS_CODE" => "D",
30
+ "POSTAL_ADDRESS_CODE_DESCRIPTION" => "A record which is linked to PAF",
31
+ "LOGICAL_STATUS_CODE" => "1",
32
+ "STATUS" => "APPROVED",
33
+ "TOPOGRAPHY_LAYER_TOID" => "",
34
+ "PARENT_UPRN" => "",
35
+ "USRN" => ""
36
+ }
37
+ },
38
+ {
39
+ "DPA" => {
40
+ "UPRN" => "340117",
41
+ "ADDRESS" => "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
42
+ "ORGANISATION_NAME" => "THRIVE RENEWABLES PLC",
43
+ "BUILDING_NAME" => "",
44
+ "THOROUGHFARE_NAME" => "DEANERY ROAD",
45
+ "POST_TOWN" => "BRISTOL",
46
+ "POSTCODE" => "BS1 5AH",
47
+ "X_COORDINATE" => 358_130.0,
48
+ "Y_COORDINATE" => 172_687.0,
49
+ "DEPENDENT_LOCALITY" => "",
50
+ "MATCH" => 1.0,
51
+ "MATCH_DESCRIPTION" => "EXACT",
52
+ "LANGUAGE" => "EN",
53
+ "LAST_UPDATE_DATE" => "2024-01-01",
54
+ "ENTRY_DATE" => "2020-01-01",
55
+ "BLPU_STATE_CODE" => "2",
56
+ "BLPU_STATE_CODE_DESCRIPTION" => "In use",
57
+ "CLASSIFICATION_CODE" => "CO01",
58
+ "CLASSIFICATION_CODE_DESCRIPTION" => "Office / Work Studio",
59
+ "POSTAL_ADDRESS_CODE" => "D",
60
+ "POSTAL_ADDRESS_CODE_DESCRIPTION" => "A record which is linked to PAF",
61
+ "LOGICAL_STATUS_CODE" => "1",
62
+ "STATUS" => "APPROVED",
63
+ "TOPOGRAPHY_LAYER_TOID" => "",
64
+ "PARENT_UPRN" => "",
65
+ "USRN" => ""
66
+ }
67
+ }
68
+ ]
69
+ }.freeze
70
+
71
+ def run(postcode)
72
+ @postcode = normalize_postcode(postcode)
73
+ self
74
+ end
75
+
76
+ def results
77
+ MOCK_ADDRESSES.fetch(@postcode, [])
78
+ end
79
+
80
+ private
81
+
82
+ def normalize_postcode(postcode)
83
+ postcode.to_s.upcase.gsub(/\s+/, "")
84
+ end
85
+ end
86
+ end
data/config/routes.rb CHANGED
@@ -11,6 +11,11 @@ DefraRubyMocks::Engine.routes.draw do # rubocop:disable Metrics/BlockLength
11
11
  as: "company_officers",
12
12
  constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
13
13
 
14
+ get "/places/v1/postcode",
15
+ to: "os_places#postcode",
16
+ as: "os_places_addresses",
17
+ constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
18
+
14
19
  post "/govpay/v1/payments",
15
20
  to: "govpay#create_payment",
16
21
  as: "govpay_create_payment",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "5.3.0"
4
+ VERSION = "5.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_mocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-09 00:00:00.000000000 Z
11
+ date: 2026-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.5'
61
+ version: '0.6'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.5'
68
+ version: '0.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +96,7 @@ files:
96
96
  - app/controllers/defra_ruby_mocks/company_controller.rb
97
97
  - app/controllers/defra_ruby_mocks/govpay_controller.rb
98
98
  - app/controllers/defra_ruby_mocks/govpay_test_helpers_controller.rb
99
+ - app/controllers/defra_ruby_mocks/os_places_controller.rb
99
100
  - app/jobs/application_job.rb
100
101
  - app/jobs/base_send_webhook_job.rb
101
102
  - app/jobs/send_payment_webhook_job.rb
@@ -107,6 +108,7 @@ files:
107
108
  - app/services/defra_ruby_mocks/govpay_get_payment_service.rb
108
109
  - app/services/defra_ruby_mocks/govpay_refund_details_service.rb
109
110
  - app/services/defra_ruby_mocks/govpay_request_refund_service.rb
111
+ - app/services/defra_ruby_mocks/os_places_service.rb
110
112
  - app/views/defra_ruby_mocks/company/not_found.json.erb
111
113
  - app/views/defra_ruby_mocks/company/officers.json.erb
112
114
  - app/views/defra_ruby_mocks/company/show.json.erb