Skip to content

Commit

Permalink
Merge pull request #2458 from alphagov/fix-redirect
Browse files Browse the repository at this point in the history
Section Redirects should be publishing the redirect afterwards
  • Loading branch information
minhngocd authored Aug 15, 2024
2 parents b234624 + e31b4db commit daa4835
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/adapters/publishing/redirect_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class Publishing::RedirectAdapter
def self.redirect_section(section, to:)
redirect_content_id = SecureRandom.uuid
Services.publishing_api.put_content(
SecureRandom.uuid,
redirect_content_id,
document_type: "redirect",
schema_name: "redirect",
publishing_app: GdsApiConstants::PublishingApi::PUBLISHING_APP,
Expand All @@ -15,6 +16,8 @@ def self.redirect_section(section, to:)
destination: to,
},
],
update_type: "major",
)
Services.publishing_api.publish(redirect_content_id)
end
end
5 changes: 5 additions & 0 deletions spec/adapters/publishing/redirect_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
destination: "/new-location",
},
],
update_type: "major",
)
expect(Services.publishing_api).to receive(:publish).with(redirect_content_id)
Publishing::RedirectAdapter.redirect_section(section, to: "/new-location")
end

Expand All @@ -31,6 +33,7 @@
redirect_content_id,
be_valid_against_publisher_schema("redirect"),
)
expect(Services.publishing_api).to receive(:publish).with(redirect_content_id)
Publishing::RedirectAdapter.redirect_section(section, to: "/new-location")
end

Expand All @@ -49,7 +52,9 @@
destination: "/new-location",
},
],
update_type: "major",
)
expect(Services.publishing_api).to receive(:publish).with(redirect_content_id)
Publishing::RedirectAdapter.redirect_section(manual, to: "/new-location")
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/tasks/withdraw_and_redirect_section_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
destination: "/guidance/parent_path",
},
],
update_type: "major",
)
assert_publishing_api_publish("some-random-uuid")
end
end
end

0 comments on commit daa4835

Please sign in to comment.