defra_ruby_mocks 5.1.3 → 5.2.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: aecd68d9ac0f7dd9256d9d8f39eb645d7fc32c45cf9bc8a6e76315029156d81e
4
- data.tar.gz: 470e1e68a160dcc92895eccfc862ca7b302fb8a185505afe554d56798a7b7f7a
3
+ metadata.gz: 2050966a0416ac33fdb18d7b5e99dddb3548ef4d704792441a7a77a6c664b58e
4
+ data.tar.gz: 555e7313d1587a5f83108a5f3ed42de143cb5b0695ab4e11582e883e0fe0e0a3
5
5
  SHA512:
6
- metadata.gz: f5fe8f9332df764a30bc808156ec2c61c31ab582bd0d8784bcef5da2a7cdbb7b16d14d9459bcd97b9918f9775803f60ecbbd487d46fd7bfd8c11b7a711f91e54
7
- data.tar.gz: bce6423f17b916a7d7447faaee544f9786934e1425e16735b2de95742676cdccfad6746f75caae1c8241d9a1898a0c38e33fd1dd90daf68c7485b6ac3321aceb
6
+ metadata.gz: 6a423e4730a149e0999d21e47b601b0fa83a011b3048c7eb03eebd2534f01752143b3c0f3c273dc6df37191287e6345cb32b1075c7fe745aab415034f6c8b43e
7
+ data.tar.gz: 1cb2bc2402d47184315227ba57d31687c1163c0eeacde31b2addd75cdf0e0d41bdbe3710f5c4853a9abbd2d4489a28ccee48f8aeaf4dcaf2beae464b8b4e1696
data/README.md CHANGED
@@ -171,19 +171,25 @@ This Govpay mock replicates those 2 interactions with the following url
171
171
 
172
172
  #### Configuration
173
173
 
174
- In order to use the govpay mock you'll need to provide additional configuration details:
174
+ In order to use the govpay mock you'll need to provide additional configuration details.
175
+ - The root Govpay mock URLs for both front- and back-office. Both are required because the mocks for front-office point at back-office and vice-versa, and the mock gem needs to know both values for the two hosting applications.
176
+ - The external URL for both applications. These are required because the mock gem needs to map from internal-EC2 only URLs to externally accessible URLs.
177
+
178
+ For example, for a front-office application, where the front-office and back-office mocks are mounted on `/fo/mocks` and `/bo/mocks` respectively:
175
179
 
176
180
  ```ruby
177
181
  config/initializers/defra_ruby_mocks.rb
178
182
  require "defra_ruby_mocks"
179
183
 
180
184
  DefraRubyMocks.configure do |config|
181
- config.govpay_domain = File.join(ENV["WCRS_GOVPAY_MOCK_DOMAIN"] || "http://localhost:3002", "/fo/mocks/govpay/v1")
185
+ configuration.govpay_mocks_external_root_url = ENV.fetch("MOCK_FO_GOVPAY_URL", "https://back-office.domain.cloud/bo/mocks/govpay/v1")
186
+ configuration.govpay_mocks_external_root_url_other = ENV.fetch("MOCK_BO_GOVPAY_URL", "https://front-office.domain.cloud/fo/mocks/govpay/v1")
187
+
188
+ configuration.govpay_mocks_internal_root_url = ENV.fetch("MOCK_FO_GOVPAY_URL_INTERNAL", "https://back-office-internal.domain.cloud:8001/bo/mocks/govpay/v1")
189
+ configuration.govpay_mocks_internal_root_url_other = ENV.fetch("MOCK_BO_GOVPAY_URL_INTERNAL", "https://front-office-internal.domain.cloud:8002/fo/mocks/govpay/v1")
182
190
  end
183
191
  ```
184
192
 
185
- The domain is used when generating the URL we tell the app to redirect users to. As this is just an engine and not a standalone service, we need to tell it what domain it is running from.
186
-
187
193
  You'll also need to provide AWS configuration details for the mocks, for example:
188
194
 
189
195
  ```ruby
@@ -8,17 +8,7 @@ module DefraRubyMocks
8
8
  include CanUseAwsS3
9
9
 
10
10
  def run(amount:, description:)
11
- success_response.merge(
12
- {
13
- _links: {
14
- self: { href: "#{base_url}/#{payment_id}", method: "GET" },
15
- next_url: { href: "#{base_url}/secure/next-url-uuid-abc123", method: "GET" }
16
- },
17
- amount: amount.to_i,
18
- description: description,
19
- payment_id: payment_id
20
- }
21
- )
11
+ success_response(amount, description)
22
12
  end
23
13
 
24
14
  private
@@ -28,15 +18,31 @@ module DefraRubyMocks
28
18
  end
29
19
 
30
20
  def base_url
31
- File.join(DefraRubyMocks.configuration.govpay_domain, "/payments")
21
+ File.join(DefraRubyMocks.configuration.govpay_mocks_internal_root_url, "/payments")
32
22
  end
33
23
 
34
24
  def payment_id
35
25
  @payment_id ||= SecureRandom.alphanumeric(26)
36
26
  end
37
27
 
28
+ def return_url
29
+ "#{DefraRubyMocks.configuration.govpay_mocks_internal_root_url}/payments/secure/next-url-uuid-abc123"
30
+ end
31
+
32
+ def next_url
33
+ "#{DefraRubyMocks.configuration.govpay_mocks_external_root_url_other}/payments/secure/next-url-uuid-abc123"
34
+ end
35
+
36
+ def url_root(url)
37
+ uri = URI.parse(url)
38
+ url_root = "#{uri.scheme}://#{uri.host}"
39
+ url_root += ":#{uri.port}" if uri.port.present? && uri.port != 80
40
+
41
+ url_root
42
+ end
43
+
38
44
  # rubocop:disable Metrics/MethodLength
39
- def success_response
45
+ def success_response(amount, description)
40
46
  {
41
47
  created_date: "2020-03-03T16:17:19.554Z",
42
48
  state: {
@@ -45,19 +51,19 @@ module DefraRubyMocks
45
51
  },
46
52
  _links: {
47
53
  self: {
48
- href: "https://publicapi.payments.service.gov.uk/v1/payments/hu20sqlact5260q2nanm0q8u93",
54
+ href: "#{base_url}/#{payment_id}",
49
55
  method: "GET"
50
56
  },
51
57
  next_url: {
52
- href: "https://www.payments.service.gov.uk/secure/bb0a272c-8eaf-468d-b3xf-ae5e000d2231",
58
+ href: next_url,
53
59
  method: "GET"
54
60
  }
55
61
  },
56
- amount: 14_500,
62
+ amount: amount.to_i,
57
63
  reference: "12345",
58
- description: "Pay your council tax",
59
- return_url: "https://your.service.gov.uk/completed",
60
- payment_id: "hu20sqlact5260q2nanm0q8u93",
64
+ description:,
65
+ return_url:,
66
+ payment_id:,
61
67
  payment_provider: "worldpay",
62
68
  provider_id: "10987654321"
63
69
  }
@@ -5,7 +5,10 @@ module DefraRubyMocks
5
5
 
6
6
  DEFAULT_DELAY = 1000
7
7
 
8
- attr_accessor :govpay_domain
8
+ attr_accessor :govpay_mocks_external_root_url,
9
+ :govpay_mocks_external_root_url_other,
10
+ :govpay_mocks_internal_root_url,
11
+ :govpay_mocks_internal_root_url_other
9
12
  attr_reader :delay
10
13
 
11
14
  def initialize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "5.1.3"
4
+ VERSION = "5.2.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.1.3
4
+ version: 5.2.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-05-19 00:00:00.000000000 Z
11
+ date: 2025-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails