Skip to content

Commit b72739f

Browse files
committed
wip
1 parent 1cabc1c commit b72739f

3 files changed

Lines changed: 37 additions & 22 deletions

File tree

app/models/document_collection_non_whitehall_link/govuk_url.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ def parsed_url
3232

3333
def content_item
3434
content_id
35-
@content_item ||= begin
36-
Services.publishing_api.get_content(@content_id).to_h
37-
rescue GdsApi::HTTPNotFound
38-
content_item_from_content_store
39-
end
35+
@content_item ||= content_item_from_content_store
4036
end
4137

4238
def content_id

features/step_definitions/document_collection_steps.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@
157157
content_id = SecureRandom.uuid
158158

159159
stub_publishing_api_has_lookups(base_path => content_id)
160-
stub_publishing_api_has_item(
160+
stub_content_store_has_item(
161+
base_path,
161162
content_id:,
162163
base_path:,
163164
publishing_app: "content-publisher",

test/unit/app/models/document_collection_non_whitehall_link/govuk_url_test.rb

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class DocumentCollectionNonWhitehallLink::GovukUrlTest < ActiveSupport::TestCase
1010
base_path: "/test",
1111
publishing_app: "content-publisher",
1212
)
13+
Services.content_store.stubs(:content_item).with("/test").returns(
14+
"content_id" => @content_id,
15+
"title" => "Test",
16+
"base_path" => "/test",
17+
"publishing_app" => "content-publisher",
18+
)
1319
end
1420

1521
test "should be valid without a GOV.UK url that Publishing API knows" do
@@ -33,11 +39,13 @@ class DocumentCollectionNonWhitehallLink::GovukUrlTest < ActiveSupport::TestCase
3339
test "should be valid when a mainstream guide sub-page url is used" do
3440
content_id = SecureRandom.uuid
3541
stub_publishing_api_has_lookups("/foo" => content_id)
36-
stub_publishing_api_has_item(content_id:,
37-
title: "Foo Bar",
38-
base_path: "/foo",
39-
document_type: "guide",
40-
publishing_app: "content-publisher")
42+
Services.content_store.stubs(:content_item).with("/foo/subpage").returns(
43+
"content_id" => content_id,
44+
"title" => "Foo Bar",
45+
"base_path" => "/foo",
46+
"publishing_app" => "content-publisher",
47+
"document_type" => "guide",
48+
)
4149

4250
url = DocumentCollectionNonWhitehallLink::GovukUrl.new(
4351
url: "https://www.gov.uk/foo/subpage",
@@ -99,12 +107,6 @@ class DocumentCollectionNonWhitehallLink::GovukUrlTest < ActiveSupport::TestCase
99107

100108
test "should be valid when a Welsh-language GOV.UK URL is used that is not in the Publishing API path reservations" do
101109
welsh_content_id = SecureRandom.uuid
102-
stub_publishing_api_has_item(
103-
content_id: welsh_content_id,
104-
title: "Talu cosb hunanasesiad",
105-
base_path: "/talu-cosb-hunanasesiad",
106-
publishing_app: "publisher",
107-
)
108110
content_store_response = { "content_id" => welsh_content_id, "title" => "Talu cosb hunanasesiad", "base_path" => "/talu-cosb-hunanasesiad", "publishing_app" => "publisher" }
109111
Services.content_store.stubs(:content_item).with("/talu-cosb-hunanasesiad").returns(content_store_response)
110112

@@ -116,6 +118,20 @@ class DocumentCollectionNonWhitehallLink::GovukUrlTest < ActiveSupport::TestCase
116118
assert url.valid?
117119
end
118120

121+
test "should be valid when a Welsh-language GOV.UK URL is in the Publishing API but only has a Welsh locale" do
122+
welsh_content_id = SecureRandom.uuid
123+
stub_publishing_api_has_lookups("/talu-treth-twe" => welsh_content_id)
124+
content_store_response = { "content_id" => welsh_content_id, "title" => "Talu TWE y cyflogwr", "base_path" => "/talu-treth-twe", "publishing_app" => "publisher", "locale" => "cy" }
125+
Services.content_store.stubs(:content_item).with("/talu-treth-twe").returns(content_store_response)
126+
127+
url = DocumentCollectionNonWhitehallLink::GovukUrl.new(
128+
url: "https://www.gov.uk/talu-treth-twe",
129+
document_collection_group: build(:document_collection_group),
130+
)
131+
132+
assert url.valid?
133+
end
134+
119135
test "should be invalid when Publishing API returns a 404" do
120136
stub_any_publishing_api_call_to_return_not_found
121137

@@ -131,11 +147,13 @@ class DocumentCollectionNonWhitehallLink::GovukUrlTest < ActiveSupport::TestCase
131147
test "should be invalid when a non-mainstream guide sub-page url is used" do
132148
content_id = SecureRandom.uuid
133149
stub_publishing_api_has_lookups("/foo" => content_id)
134-
stub_publishing_api_has_item(content_id:,
135-
title: "Foo Bar",
136-
base_path: "/foo",
137-
document_type: "other",
138-
publishing_app: "content-publisher")
150+
Services.content_store.stubs(:content_item).with("/foo/subpage").returns(
151+
"content_id" => content_id,
152+
"title" => "Foo Bar",
153+
"base_path" => "/foo",
154+
"publishing_app" => "content-publisher",
155+
"document_type" => "other",
156+
)
139157

140158
url = DocumentCollectionNonWhitehallLink::GovukUrl.new(
141159
url: "https://www.gov.uk/foo/subpage",

0 commit comments

Comments
 (0)