Skip to content

Commit

Permalink
Merge pull request #58 from alphagov/new-parts
Browse files Browse the repository at this point in the history
Extract (partial) parts from documents
  • Loading branch information
csutter authored Oct 25, 2023
2 parents ccc4100 + c331e98 commit 692c61e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/document_sync_worker/document/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def metadata
# Vertex can only currently boost on numeric fields, not booleans
is_historic: historic? ? 1 : 0,
locale: document_hash["locale"],
parts:,
}
end

Expand Down Expand Up @@ -91,6 +92,12 @@ def historic?

political && government&.dig("details", "current") == false
end

def parts
document_hash
.dig("details", "parts")
&.map { { slug: _1["slug"], title: _1["title"] } } || []
end
end
end
end
31 changes: 31 additions & 0 deletions spec/lib/document_sync_worker/document/publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,37 @@

it { is_expected.to eq("en") }
end

describe "parts" do
subject(:extracted_parts) { document.metadata[:parts] }

let(:document_hash) { { "details" => { "parts" => parts } } }

context "when the document has no parts" do
let(:parts) { nil }

it { is_expected.to be_empty }
end

context "when the document has parts" do
let(:parts) do
[
{
"title" => "Part 1",
"slug" => "/part-1",
"body" => "Part 1 body",
},
{
"title" => "Part 2",
"slug" => "/part-2",
"body" => "Part 2 body",
},
]
end

it { is_expected.to eq([{ title: "Part 1", slug: "/part-1" }, { title: "Part 2", slug: "/part-2" }]) }
end
end
end

describe "#synchronize_to" do
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/document_sync_worker_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
668cd623-c7a8-4159-9575-90caac36d4b4 c31256e8-f328-462b-993f-dce50b7892e9
],
locale: "en",
parts: [],
)

expect(result[:content]).to start_with("<div class=\"govspeak\"><p>The government has")
Expand Down Expand Up @@ -62,6 +63,13 @@
8f78544f-a4ed-46b4-8163-889679d119b9 71cd9f51-f492-4c3f-91ca-5ad694c26592
],
locale: "en",
parts: [
{ slug: "warnings-and-insurance", title: "Warnings and insurance" },
{ slug: "entry-requirements", title: "Entry requirements" },
{ slug: "safety-and-security", title: "Safety and security" },
{ slug: "health", title: "Health" },
{ slug: "getting-help", title: "Getting help" },
],
)

expect(result[:content]).to be_empty
Expand Down Expand Up @@ -93,6 +101,7 @@
3dbeb4a3-33c0-4bda-bd21-b721b0f8736f
],
locale: "en",
parts: [],
)

expect(result[:content]).to start_with("<div class=\"govspeak\"><p>In the UEFA Champions")
Expand Down Expand Up @@ -122,6 +131,7 @@
content_purpose_supergroup: "other",
part_of_taxonomy_tree: [],
locale: "en",
parts: [],
)

expect(result[:content]).to be_blank
Expand Down

0 comments on commit 692c61e

Please sign in to comment.