govuk_content_item_loader 1.2.2 → 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: 704a8afd75af58674109ebefcb22e9855c481d7b5280330e6f1d25eac2fcbec2
4
- data.tar.gz: 7415244c1e4abd90dfd25e1499bb083839e1dc0bc37d6ae6c9937c9c256a9c26
3
+ metadata.gz: a00bbc8f14d56f67f1ef763163819d0ca8aa5cadc19657e99ba4138e30d5613c
4
+ data.tar.gz: 7ad600627ef7be66f62cf980d8e9417b044ee39367792d89dac743382c9724cd
5
5
  SHA512:
6
- metadata.gz: 20823b0e5c2a93ede2bb195995393aa692dbb07e4b5d0cafe02b6d241ecac06c072bb8f009419dd66424b44a91237e813d6e226a282c300a46eb12fc7c52a13a
7
- data.tar.gz: b9a349fb86b3232ae009d77c60672c0c8cdea9c5850f2d639e17ca09ea3d6724999314cfdbc540d933353aa4d333abc18716eb17607b1272b2f1a73a29430037
6
+ metadata.gz: 46c9ebf6a037ca8087c093f2f69f5399dc22e1273468ec0b70a833d58e7762e69332f42ad75e1da12082461eb0c94ced34b311da7166ddbf5dd85502ab971e07
7
+ data.tar.gz: fbbe5c0102e6e13d14a3a5685cee82973afc6c2e5cf31d565b9f96992a03819be1647571259e953c4e88d410dc832df8e05e79da5c32463696d82ea40df79182
data/CHANGELOG.md CHANGED
@@ -1,12 +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
+
3
8
  ## 1.2.2
4
9
 
5
10
  * Update dependencies
6
11
 
7
12
  ## 1.2.1
8
13
 
9
- * Stub the requests in test helpers and add Plek as dependency
14
+ * Stub the requests in test helpers and add Plek as dependency
10
15
 
11
16
  ## 1.2.0
12
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.2".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.2
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: []