@@ -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