govuk_content_item_loader 1.1.2 → 1.2.1

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: 208a339dd9691090128a655acbe22bc1c403ce172fd1555318bf15fb67cd533e
4
- data.tar.gz: d32050cfdbaf157b5da48878fdb3e5c52c1a0510653d9deae36899da7adbbf0f
3
+ metadata.gz: 2706641da9c4079e8da612e4bf3cb35a18a1d3957995022e54a8051ecce635ec
4
+ data.tar.gz: b9fb4b83c2cd9a0927f9b998156f3cca9bc390b4a486d7af5d5b96395e567c78
5
5
  SHA512:
6
- metadata.gz: 5ed40d8b8dbf4e265ead813865c8b462e22134f4a2e74b55e9df2b4ae506c23622c9d9d085dffd03f4c7c083d74869756356d30ed96f5cff9d56e6dfe9bfaa72
7
- data.tar.gz: 65cc4a6631a46bc07d2ab8dc80daf212d1c953e8e4c300329c3b54fa4c75de5aae2da06af57a2accbca7d074988fb1a0c78bacfe56ccc2cab6599666e37ce199
6
+ metadata.gz: 6ac3b1f7f1d5bad18afe1b0716bc238d2bc7abe3e2c976208cbb0dc9178ecb2dab8549780d4565d1d9e94940ecde2d0af3098f0a04dee32d6de30f1e3985be4a
7
+ data.tar.gz: da3e422b44b8c86f5bfda89d3f43a2b43992bc2cdf50786477923e338cf29d9daf5a54d7f84cfdb18a354ce572a3fc929af68c8b7e59aece6b94d5d82a6abf9d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ * Stub the requests in test helpers and add Plek as dependency
6
+
7
+ ## 1.2.0
8
+
9
+ * Add test helpers which provide stubs
10
+
3
11
  ## 1.1.2
4
12
 
5
13
  * Update dependencies
data/README.md CHANGED
@@ -86,6 +86,10 @@ loader = GovukGraphql::ConditionalContentItemLoader.new(
86
86
 
87
87
  The decision logic is also exposed via `can_load_from_graphql?`, allowing applications to make the routing decision themselves and implement custom fallback or error-handling behaviour if needed.
88
88
 
89
+ ## Test helpers
90
+
91
+ There are also test helpers for stubbing responses in other apps. See [lib/test_helpers.rb](/lib/test_helpers.rb).
92
+
89
93
  ## Licence
90
94
 
91
95
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = %w[lib]
21
21
 
22
22
  spec.add_dependency "gds-api-adapters", ">= 99.3"
23
+ spec.add_dependency "plek", ">= 1.9.0"
23
24
  spec.add_dependency "railties", ">= 7.2"
24
25
 
25
26
  spec.add_development_dependency "climate_control"
@@ -0,0 +1,58 @@
1
+ require "json"
2
+
3
+ module GovukConditionalContentItemLoaderTestHelpers
4
+ CONTENT_STORE_ENDPOINT = Plek.find("content-store")
5
+ PUBLISHING_API_ENDPOINT = Plek.find("publishing-api")
6
+
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)
33
+ end
34
+
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)
49
+
50
+ loader = instance_double(GovukConditionalContentItemLoader)
51
+
52
+ allow(GovukConditionalContentItemLoader).to receive(:new).with(request: anything)
53
+ .and_return(loader)
54
+ allow(loader).to receive(:load).and_raise(error)
55
+
56
+ error
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukContentItemLoader
2
- VERSION = "1.1.2".freeze
2
+ VERSION = "1.2.1".freeze
3
3
  end
@@ -1,3 +1,4 @@
1
1
  require "govuk_content_item_loader/govuk_graphql_traffic_rates"
2
2
  require "govuk_content_item_loader/govuk_conditional_content_item_loader"
3
3
  require "govuk_content_item_loader/version"
4
+ require "govuk_content_item_loader/test_helpers"
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.1.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '99.3'
26
+ - !ruby/object:Gem::Dependency
27
+ name: plek
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.9.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.9.0
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: railties
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +176,7 @@ files:
162
176
  - lib/govuk_content_item_loader.rb
163
177
  - lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb
164
178
  - lib/govuk_content_item_loader/govuk_graphql_traffic_rates.rb
179
+ - lib/govuk_content_item_loader/test_helpers.rb
165
180
  - lib/govuk_content_item_loader/version.rb
166
181
  homepage: https://github.com/alphagov/govuk_content_item_loader
167
182
  licenses: