Skip to content

Commit 404b442

Browse files
authored
Merge pull request #3252 from alphagov/MAIN-7370-fact-check-manager-preview-links
[MAIN-7370] Add draft preview fields to fact-check-manager API payloads
2 parents 8b543ca + 7b5149c commit 404b442

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

app/lib/gds_api/fact_check_manager.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ class GdsApi::FactCheckManager < GdsApi::Base
1414
# @option [hash] previous_content Hash containing HTML content of previous content version to check against
1515
# @option [string] deadline Date a response is requested by. Use iso8601 date format: "2026-02-09"
1616
# @param [array] recipients Array of emails to be notified of the request
17+
# @option [uuid] draft_auth_bypass_id The edition's auth_bypass_id for draft origin preview access
18+
# @option [uuid] draft_content_id The edition's content_id for draft origin preview access
19+
# @option [string] draft_slug The edition's slug for the draft origin preview URL path
1720
#
1821
# @return [GdsApi::Response] Basic response with code
1922

2023
def post_fact_check(source_app:, source_id:, requester_name:, requester_email:, current_content:,
21-
recipients:, source_title: nil, source_url: nil, previous_content: nil, deadline: nil)
24+
recipients:, source_title: nil, source_url: nil, previous_content: {}, deadline: nil,
25+
draft_auth_bypass_id: nil, draft_content_id: nil, draft_slug: nil)
2226
post_json(
2327
"#{endpoint}/api/requests",
2428
source_app:,
@@ -31,6 +35,9 @@ def post_fact_check(source_app:, source_id:, requester_name:, requester_email:,
3135
previous_content:,
3236
deadline:,
3337
recipients:,
38+
draft_auth_bypass_id:,
39+
draft_content_id:,
40+
draft_slug:,
3441
)
3542
end
3643

@@ -53,10 +60,14 @@ def post_resend_emails(source_app:, source_id:)
5360
# @param [uuid] source_id The unique ID for the content
5461
# @param [hash] current_content
5562
# @option [string] source_title The title of the content (optional)
56-
def patch_update_content(source_app:, source_id:, current_content:, source_title: nil)
63+
# @option [uuid] draft_auth_bypass_id The edition's auth_bypass_id for draft origin preview access (optional)
64+
# @option [string] draft_slug The edition's slug for the draft origin preview URL path (optional)
65+
def patch_update_content(source_app:, source_id:, current_content:, source_title: nil, draft_auth_bypass_id: nil, draft_slug: nil)
5766
payload = {
5867
source_title:,
5968
current_content:,
69+
draft_auth_bypass_id:,
70+
draft_slug:,
6071
}.compact
6172

6273
patch_json("#{endpoint}/api/requests/#{source_app}/#{source_id}", payload)

app/services/fact_check_manager_api_service.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.resend_fact_check_emails(edition)
1414

1515
def self.build_post_payload(edition, requester, email_addresses)
1616
current_content_presenter = Formats::GenericEditionPresenter.new(edition)
17-
previous_content = nil
17+
previous_content = {}
1818
if edition.published_edition
1919
previous_content_presenter = Formats::GenericEditionPresenter.new(edition.published_edition)
2020
previous_content = previous_content_presenter.render_for_fact_check_manager_api
@@ -29,7 +29,10 @@ def self.build_post_payload(edition, requester, email_addresses)
2929
current_content: current_content_presenter.render_for_fact_check_manager_api,
3030
previous_content: previous_content,
3131
deadline: working_days_after(Date.current, how_many: 5).to_fs(:iso8601),
32-
recipients: email_addresses.split(",").map(&:strip) }
32+
recipients: email_addresses.split(",").map(&:strip),
33+
draft_auth_bypass_id: edition.auth_bypass_id,
34+
draft_content_id: edition.content_id,
35+
draft_slug: edition.slug }
3336
end
3437

3538
def self.update_fact_check_content(edition)
@@ -40,6 +43,8 @@ def self.update_fact_check_content(edition)
4043
source_id: edition.id,
4144
source_title: edition.title,
4245
current_content: current_content_presenter.render_for_fact_check_manager_api,
46+
draft_auth_bypass_id: edition.auth_bypass_id,
47+
draft_slug: edition.slug,
4348
)
4449
end
4550
end

test/unit/services/fact_check_manager_api_service_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FactCheckManagerApiServiceTest < ActiveSupport::TestCase
2929
context ".update_fact_check_content" do
3030
should "call the fact check manager api adapter" do
3131
Services.fact_check_manager_api.expects(:patch_update_content)
32-
.with(source_app: "publisher", source_id: @edition.id, source_title: "New Title", current_content: { body: "some body" })
32+
.with(source_app: "publisher", source_id: @edition.id, source_title: "New Title", current_content: { body: "some body" }, draft_auth_bypass_id: @edition.auth_bypass_id, draft_slug: @edition.slug)
3333
.returns("stub response")
3434

3535
FactCheckManagerApiService.update_fact_check_content(@edition)
@@ -48,9 +48,12 @@ class FactCheckManagerApiServiceTest < ActiveSupport::TestCase
4848
requester_name: "Ben",
4949
requester_email: "joe1@bloggs.com",
5050
current_content: { body: "some body" },
51-
previous_content: nil,
51+
previous_content: {},
5252
deadline: "2026-02-09",
53-
recipients: ["stub@email.com"] }
53+
recipients: ["stub@email.com"],
54+
draft_content_id: @edition.content_id,
55+
draft_auth_bypass_id: @edition.auth_bypass_id,
56+
draft_slug: @edition.slug }
5457

5558
assert_equal expected_payload, payload
5659
end

0 commit comments

Comments
 (0)