-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a
ContentIdAlias
on PUT Content
A `ContentIdAlias` will be created when making a request to this endpoint when the API consumer submits the `[:details][:content_id_alias]` parameter, as long as they're updating the correct document type (currently only possible for email addresses and postal addresses).
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,79 @@ | |
) | ||
end | ||
|
||
describe "linking a content_id to a human readable alias" do | ||
context "when updating a content block type" do | ||
let(:content_block_payload) do | ||
{ | ||
content_id:, | ||
locale: "en", | ||
schema_name: "content_block_email_address", | ||
document_type: "content_block_email_address", | ||
title: "Government Digital Service - General contact", | ||
description: "General contact email address for Government Digital Service", | ||
details: { | ||
content_id_alias: "gds-general", | ||
email_address: "[email protected]", | ||
}, | ||
publishing_app: "whitehall", | ||
} | ||
end | ||
|
||
context "and including a content_id_alias" do | ||
it "creates a ContentIdAlias" do | ||
expect(ContentIdAlias).to receive(:create!).with(name: content_block_payload[:details][:content_id_alias], content_id:) | ||
described_class.call(content_block_payload) | ||
end | ||
|
||
context "but a matching ContentIdAlias already exists" do | ||
before do | ||
create(:content_id_alias, content_id:, name: content_block_payload[:details][:content_id_alias]) | ||
end | ||
|
||
it "raises an error" do | ||
expect { | ||
described_class.call(content_block_payload) | ||
}.to raise_error(CommandError) { |error| | ||
expect(error.code).to eq(422) | ||
} | ||
end | ||
end | ||
end | ||
|
||
context "and not including a content_id_alias" do | ||
before do | ||
validator = double(:validator, validate: true) | ||
allow(Commands::V2::PutContentValidator).to receive(:new) | ||
.and_return(validator) | ||
end | ||
|
||
it "does not create a ContentIdAlias" do | ||
content_block_payload = { | ||
content_id:, | ||
locale: "en", | ||
schema_name: "content_block_email_address", | ||
document_type: "content_block_email_address", | ||
title: "Government Digital Service - General contact", | ||
description: "General contact email address for Government Digital Service", | ||
details: { | ||
email_address: "[email protected]", | ||
}, | ||
publishing_app: "whitehall", | ||
} | ||
expect(ContentIdAlias).not_to receive(:create!) | ||
described_class.call(content_block_payload) | ||
end | ||
end | ||
end | ||
|
||
context "when updating any other type" do | ||
it "does not create a ContentIdAlias" do | ||
expect(ContentIdAlias).not_to receive(:create!) | ||
described_class.call(payload) | ||
end | ||
end | ||
end | ||
|
||
context "when the 'downstream' parameter is false" do | ||
it "does not send to the downstream draft worker" do | ||
expect(DownstreamDraftJob).not_to receive(:perform_async_in_queue) | ||
|