Skip to content

Commit

Permalink
Merge pull request #179 from alphagov/debug-info-doc
Browse files Browse the repository at this point in the history
Add debug information to synced documents
  • Loading branch information
csutter authored Jan 16, 2024
2 parents 5d6b147 + b81dc00 commit 480e5b4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/models/concerns/publishing_api/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def metadata
topical_events:,
manual:,
parts:,
debug:,
}.compact_blank
end

Expand Down Expand Up @@ -152,5 +153,13 @@ def parts_from_attachments
}
}&.compact_blank
end

# Useful information about the document that is not intended to be exposed to the end user.
def debug
{
last_synced_at: Time.zone.now.iso8601,
payload_version: document_hash[:payload_version]&.to_i,
}
end
end
end
52 changes: 51 additions & 1 deletion spec/integration/document_synchronization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
allow(DiscoveryEngine::Sync::Put).to receive(:new).and_return(put_service)
allow(DiscoveryEngine::Sync::Delete).to receive(:new).and_return(delete_service)

PublishingApiMessageProcessor.new.process(message)
Timecop.freeze(Time.zone.local(1989, 12, 13, 1, 2, 3)) do
PublishingApiMessageProcessor.new.process(message)
end
end

describe "for a 'press_release' message" do
Expand All @@ -33,6 +35,10 @@
part_of_taxonomy_tree: %w[37d0fa26-abed-4c74-8835-b3b51ae1c8b2],
organisations: %w[government-digital-service],
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("<div class=\"govspeak\"><p>The UK was represented remotely"),
payload_version: 12_345,
Expand Down Expand Up @@ -88,6 +94,10 @@
body: "The Foreign, Commonwealth & Development Office (FCDO) cannot provide…",
},
],
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("<h1>Warnings and insurance</h1>\n<p>The Foreign"),
payload_version: 12_345,
Expand Down Expand Up @@ -119,6 +129,10 @@
],
organisations: %w[foreign-commonwealth-office],
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("<div class=\"govspeak\"><p>In the UEFA Champions"),
payload_version: 12_345,
Expand All @@ -145,6 +159,10 @@
organisations: %w[driver-and-vehicle-standards-agency],
manual: "/guidance/mot-inspection-manual-for-private-passenger-and-light-commercial-vehicles",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_matching(/<h2 id="section-6-1">6\.1\. Structure.+<\/table>\n\n/m),
payload_version: 12_345,
Expand All @@ -171,6 +189,10 @@
organisations: %w[government-digital-service],
manual: "/service-manual",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 1989,
},
},
content: a_string_matching(/Make sure everyone can use the service/),
payload_version: 1989,
Expand All @@ -197,6 +219,10 @@
content_purpose_supergroup: "other",
organisations: %w[legal-aid-agency],
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("LAA\n<div class=\"govspeak\"><p>We provide civil"),
payload_version: 12_345,
Expand Down Expand Up @@ -226,6 +252,10 @@
world_locations: %w[austria],
content_purpose_supergroup: "other",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("maintains and develops relations between the UK and Austria"),
payload_version: 12_345,
Expand Down Expand Up @@ -253,6 +283,10 @@
part_of_taxonomy_tree: %w[f3caf326-fe33-410f-b7f4-553f4011c81e],
organisations: %w[cabinet-office efficiency-and-reform-group government-digital-service],
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 54_321,
},
},
content: a_string_including(<<~TEXT.chomp),
Directgov 2010 and beyond: revolution not evolution, a report by Martha Lane Fox
Expand Down Expand Up @@ -307,6 +341,10 @@
slug: "disability-quick-start-guide-for-service-providers-html",
},
],
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_starting_with("Equality Act 2010: how it might affect you"),
payload_version: 12_345,
Expand All @@ -331,6 +369,10 @@
is_historic: 0,
content_purpose_supergroup: "other",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: <<~TEXT.chomp,
UK help and services in Switzerland
Expand Down Expand Up @@ -363,6 +405,10 @@
topical_events: %w[her-majesty-queen-elizabeth-ii],
content_purpose_supergroup: "news_and_communications",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 12_345,
},
},
content: a_string_including("Service of thanksgiving for the life of Her Majesty Queen Elizabeth II"),
payload_version: 12_345,
Expand All @@ -387,6 +433,10 @@
is_historic: 0,
content_purpose_supergroup: "other",
locale: "en",
debug: {
last_synced_at: "1989-12-13T01:02:03+00:00",
payload_version: 17,
},
},
content: a_string_including("Brighton & Hove City Council"),
payload_version: 17,
Expand Down
16 changes: 16 additions & 0 deletions spec/models/concerns/publishing_api/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,21 @@
end
end
end

describe "debug" do
subject(:extracted_debug) { extracted_metadata[:debug] }

let(:document_hash) { { payload_version: "42" } }

it "includes the last sync timestamp" do
Timecop.freeze(Time.zone.local(1989, 12, 13, 11, 22, 33)) do
expect(extracted_debug[:last_synced_at]).to eq("1989-12-13T11:22:33+00:00")
end
end

it "includes the payload version as an integer" do
expect(extracted_debug[:payload_version]).to eq(42)
end
end
end
end

0 comments on commit 480e5b4

Please sign in to comment.