govuk_content_item_loader 1.2.1 → 2.0.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: 2706641da9c4079e8da612e4bf3cb35a18a1d3957995022e54a8051ecce635ec
4
- data.tar.gz: b9fb4b83c2cd9a0927f9b998156f3cca9bc390b4a486d7af5d5b96395e567c78
3
+ metadata.gz: a00bbc8f14d56f67f1ef763163819d0ca8aa5cadc19657e99ba4138e30d5613c
4
+ data.tar.gz: 7ad600627ef7be66f62cf980d8e9417b044ee39367792d89dac743382c9724cd
5
5
  SHA512:
6
- metadata.gz: 6ac3b1f7f1d5bad18afe1b0716bc238d2bc7abe3e2c976208cbb0dc9178ecb2dab8549780d4565d1d9e94940ecde2d0af3098f0a04dee32d6de30f1e3985be4a
7
- data.tar.gz: da3e422b44b8c86f5bfda89d3f43a2b43992bc2cdf50786477923e338cf29d9daf5a54d7f84cfdb18a354ce572a3fc929af68c8b7e59aece6b94d5d82a6abf9d
6
+ metadata.gz: 46c9ebf6a037ca8087c093f2f69f5399dc22e1273468ec0b70a833d58e7762e69332f42ad75e1da12082461eb0c94ced34b311da7166ddbf5dd85502ab971e07
7
+ data.tar.gz: fbbe5c0102e6e13d14a3a5685cee82973afc6c2e5cf31d565b9f96992a03819be1647571259e953c4e88d410dc832df8e05e79da5c32463696d82ea40df79182
@@ -38,7 +38,7 @@ jobs:
38
38
  - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
39
39
  with:
40
40
  ref: ${{ inputs.ref || github.ref }}
41
- - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
41
+ - uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1.299.0
42
42
  with:
43
43
  ruby-version: ${{ matrix.ruby }}
44
44
  bundler-cache: true
data/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ * BREAKING: replaces `stub_conditional_loader_returns_content_item` test helper with `stub_conditional_loader_returns_content_item_for_path` to match requests to a specific request path, for testing in frontend applications.
6
+ * BREAKING: replaces `stub_conditional_loader_does_not_return_content_item` test helper with `stub_conditional_loader_does_not_return_content_item_for_path` to match requests to a specific request path, for testing in frontend applications.
7
+
8
+ ## 1.2.2
9
+
10
+ * Update dependencies
11
+
3
12
  ## 1.2.1
4
13
 
5
- * Stub the requests in test helpers and add Plek as dependency
14
+ * Stub the requests in test helpers and add Plek as dependency
6
15
 
7
16
  ## 1.2.0
8
17
 
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_development_dependency "rubocop-govuk", "~> 5.2"
32
32
  spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "webmock"
33
34
  end
@@ -1,58 +1,26 @@
1
- require "json"
1
+ require "gds_api/test_helpers/content_item_helpers"
2
+ require "gds_api/test_helpers/content_store"
3
+ require "gds_api/test_helpers/publishing_api"
2
4
 
3
5
  module GovukConditionalContentItemLoaderTestHelpers
4
- CONTENT_STORE_ENDPOINT = Plek.find("content-store")
5
- PUBLISHING_API_ENDPOINT = Plek.find("publishing-api")
6
+ include GdsApi::TestHelpers::ContentStore
7
+ include GdsApi::TestHelpers::PublishingApi
6
8
 
7
- # Stubs the loader returns a content item
8
- # The following options can be passed in:
9
- #
10
- # :max_age will set the max-age of the Cache-Control header in the response. Defaults to 900
11
- # :private if true, the Cache-Control header will include the "private" directive. By default it
12
- # will include "public"
13
- def stub_conditional_loader_returns_content_item(body, options = {})
14
- body = body.is_a?(String) ? body : body.to_json
15
- max_age = options.fetch(:max_age, 900)
16
- visibility = options[:private] ? "private" : "public"
17
-
18
- [CONTENT_STORE_ENDPOINT, PUBLISHING_API_ENDPOINT].each do |endpoint|
19
- stub_request(:get, %r{#{Regexp.escape(endpoint)}}).to_return(
20
- status: 200,
21
- body: body,
22
- headers: {
23
- "Cache-Control" => "#{visibility}, max-age=#{max_age}",
24
- "Date" => Time.now.httpdate,
25
- },
26
- )
27
- end
28
-
29
- loader = instance_double(GovukConditionalContentItemLoader, load: JSON.parse(body))
30
-
31
- allow(GovukConditionalContentItemLoader).to receive(:new).with(request: anything)
32
- .and_return(loader)
9
+ def stub_conditional_loader_returns_content_item_for_path(base_path, body = content_item_for_base_path(base_path), options = {})
10
+ stub_content_store_has_item(base_path, body, options)
11
+ stub_publishing_api_graphql_has_item(base_path, body, options)
33
12
  end
34
13
 
35
- # Stubs the loader returns a error response
36
- # The following options can be passed in:
37
- #
38
- # :status the HTTP status code for the error. Defaults to 404
39
- # :message the error message. Defaults to "Not Found"
40
- # :error_details optional additional error details to attach to the exception
41
- # :http_body optional raw response body to attach to the exception
42
- def stub_conditional_loader_does_not_return_content_item(options = {})
43
- status = options.fetch(:status, 404)
44
- message = options.fetch(:message, "Not Found")
45
- error_details = options[:error_details]
46
- http_body = options[:http_body]
47
-
48
- error = GdsApi::HTTPErrorResponse.new(status, message, error_details, http_body)
14
+ def stub_conditional_loader_does_not_return_content_item_for_path(base_path, options = {})
15
+ stub_content_store_does_not_have_item(base_path, options)
16
+ stub_publishing_api_graphql_does_not_have_item(base_path)
17
+ end
49
18
 
50
- loader = instance_double(GovukConditionalContentItemLoader)
19
+ private
51
20
 
52
- allow(GovukConditionalContentItemLoader).to receive(:new).with(request: anything)
53
- .and_return(loader)
54
- allow(loader).to receive(:load).and_raise(error)
21
+ def content_item_for_base_path(base_path)
22
+ include GdsApi::TestHelpers::ContentItemHelpers
55
23
 
56
- error
24
+ super.merge("base_path" => base_path)
57
25
  end
58
26
  end
@@ -1,3 +1,3 @@
1
1
  module GovukContentItemLoader
2
- VERSION = "1.2.1".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_content_item_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -149,6 +149,20 @@ dependencies:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: webmock
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
152
166
  email:
153
167
  - govuk-dev@digital.cabinet-office.gov.uk
154
168
  executables: []
@@ -196,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
210
  - !ruby/object:Gem::Version
197
211
  version: '0'
198
212
  requirements: []
199
- rubygems_version: 4.0.8
213
+ rubygems_version: 4.0.9
200
214
  specification_version: 4
201
215
  summary: Provides a standardised content item loader for GOV.UK frontend apps with
202
216
  configurable GraphQL traffic routing and automatic fallback to the Content Store