govuk_content_item_loader 1.2.2 → 2.0.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: 704a8afd75af58674109ebefcb22e9855c481d7b5280330e6f1d25eac2fcbec2
4
- data.tar.gz: 7415244c1e4abd90dfd25e1499bb083839e1dc0bc37d6ae6c9937c9c256a9c26
3
+ metadata.gz: 7bb947b61c830b418c2941913dc207c17b6f175e3d6ba2a0ed13051ba60a0fc4
4
+ data.tar.gz: '024586893b7ad6492cec7ca9f7c52dbf0f6eab6fd480b0f1910727d9bd4becf9'
5
5
  SHA512:
6
- metadata.gz: 20823b0e5c2a93ede2bb195995393aa692dbb07e4b5d0cafe02b6d241ecac06c072bb8f009419dd66424b44a91237e813d6e226a282c300a46eb12fc7c52a13a
7
- data.tar.gz: b9a349fb86b3232ae009d77c60672c0c8cdea9c5850f2d639e17ca09ea3d6724999314cfdbc540d933353aa4d333abc18716eb17607b1272b2f1a73a29430037
6
+ metadata.gz: 6561e782d74861fc4b641f37924d55b92a5337c2cff0bd90d7331bbaaae6eaa91ea6320d4e3f4b6f0d9f337ca06a2caaa79dc9362692ac43134d579e634db82f
7
+ data.tar.gz: 2afa336300d20386fa0525edd2e97105e8d1291a70467cfb91fe629a81e268c799f1c49e6832ea045342c0b67ca2e5e5ed4f63561e21823a7d00878cefc70917
data/CHANGELOG.md CHANGED
@@ -1,12 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+
5
+ * Add `stub_conditional_content_loader_isnt_available` test helper.
6
+ * Add `stub_conditional_content_loader_has_gone_item` test helper.
7
+
8
+ ## 2.0.0
9
+
10
+ * 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.
11
+ * 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.
12
+
3
13
  ## 1.2.2
4
14
 
5
15
  * Update dependencies
6
16
 
7
17
  ## 1.2.1
8
18
 
9
- * Stub the requests in test helpers and add Plek as dependency
19
+ * Stub the requests in test helpers and add Plek as dependency
10
20
 
11
21
  ## 1.2.0
12
22
 
@@ -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,36 @@
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
-
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)
6
+ include GdsApi::TestHelpers::ContentStore
7
+ include GdsApi::TestHelpers::PublishingApi
8
+
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]
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
47
18
 
48
- error = GdsApi::HTTPErrorResponse.new(status, message, error_details, http_body)
19
+ def stub_conditional_content_loader_isnt_available
20
+ stub_content_store_isnt_available
21
+ stub_publishing_api_isnt_available
22
+ end
23
+
24
+ def stub_conditional_content_loader_has_gone_item(base_path)
25
+ stub_content_store_has_gone_item(base_path)
26
+ stub_publishing_api_graphql_has_gone_item(base_path)
27
+ end
49
28
 
50
- loader = instance_double(GovukConditionalContentItemLoader)
29
+ private
51
30
 
52
- allow(GovukConditionalContentItemLoader).to receive(:new).with(request: anything)
53
- .and_return(loader)
54
- allow(loader).to receive(:load).and_raise(error)
31
+ def content_item_for_base_path(base_path)
32
+ include GdsApi::TestHelpers::ContentItemHelpers
55
33
 
56
- error
34
+ super.merge("base_path" => base_path)
57
35
  end
58
36
  end
@@ -1,3 +1,3 @@
1
1
  module GovukContentItemLoader
2
- VERSION = "1.2.2".freeze
2
+ VERSION = "2.0.1".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.1
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: []