-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor invocation of delete and ignore into document
This removes two unnecessary abstractions, with the final one still to come.
- Loading branch information
Showing
8 changed files
with
93 additions
and
138 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,93 +1,119 @@ | ||
RSpec.describe PublishingApiDocument do | ||
describe "#action" do | ||
subject(:document) { described_class.new(document_hash).action } | ||
|
||
let(:document_hash) do | ||
{ | ||
document_type:, | ||
base_path:, | ||
details: { url: }, | ||
locale:, | ||
} | ||
subject(:document) do | ||
described_class.new( | ||
document_hash, | ||
put_service:, | ||
delete_service:, | ||
) | ||
end | ||
|
||
let(:put_service) { double(:put_service, call: nil) } | ||
let(:delete_service) { double(:delete_service, call: nil) } | ||
|
||
let(:document_hash) do | ||
{ | ||
content_id: "content-id", | ||
document_type:, | ||
base_path:, | ||
details: { url: }, | ||
locale:, | ||
payload_version: 42, | ||
} | ||
end | ||
let(:base_path) { "/base-path" } | ||
let(:url) { nil } | ||
let(:locale) { "en" } | ||
|
||
describe "#synchronize" do | ||
before do | ||
allow(Rails.logger).to receive(:info) | ||
|
||
document.synchronize | ||
end | ||
let(:base_path) { "/base-path" } | ||
let(:url) { nil } | ||
let(:locale) { "en" } | ||
|
||
%w[gone redirect substitute vanish].each do |document_type| | ||
context "when the document type is #{document_type}" do | ||
let(:document_type) { document_type } | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Unpublish) } | ||
it "calls the delete service" do | ||
expect(delete_service).to have_received(:call).with("content-id", payload_version: 42) | ||
end | ||
end | ||
end | ||
|
||
context "when the document type is on the ignore list as a string" do | ||
let(:document_type) { "ignored" } | ||
let(:document_type) { "test_ignored_type" } # see test section in YAML config | ||
|
||
before do | ||
allow(Rails.configuration).to receive(:document_type_ignorelist).and_return(%w[ignored]) | ||
it "does not publish the document and logs a message" do | ||
expect(put_service).not_to have_received(:call) | ||
expect(Rails.logger).to have_received(:info).with("Ignoring document 'content-id'") | ||
end | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Ignore) } | ||
end | ||
|
||
context "when the document type is on the ignore list as a pattern" do | ||
let(:document_type) { "ignored_thing" } | ||
let(:document_type) { "another_test_ignored_type_foo" } # see test section in YAML config | ||
|
||
before do | ||
allow(Rails.configuration).to receive(:document_type_ignorelist).and_return([/^ignored_/]) | ||
it "does not publish the document and logs a message" do | ||
expect(put_service).not_to have_received(:call) | ||
expect(Rails.logger).to have_received(:info).with("Ignoring document 'content-id'") | ||
end | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Ignore) } | ||
end | ||
|
||
context "when the document type is on the ignore list but the path is excluded" do | ||
let(:document_type) { "ignored" } | ||
context "when the document doesn't have a base path or a details.url" do | ||
let(:document_type) { "internal" } | ||
let(:base_path) { nil } | ||
let(:url) { nil } | ||
|
||
before do | ||
allow(Rails.configuration).to receive(:document_type_ignorelist).and_return(%w[ignored]) | ||
allow(Rails.configuration).to receive(:document_type_ignorelist_path_overrides) | ||
.and_return(%w[/base-path]) | ||
it "does not publish the document and logs a message" do | ||
expect(put_service).not_to have_received(:call) | ||
expect(Rails.logger).to have_received(:info).with("Ignoring document 'content-id'") | ||
end | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Publish) } | ||
end | ||
|
||
context "when the document doesn't have an English locale" do | ||
let(:document_type) { "dokument" } | ||
let(:locale) { "de" } | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Ignore) } | ||
it "does not publish the document and logs a message" do | ||
expect(put_service).not_to have_received(:call) | ||
expect(Rails.logger).to have_received(:info).with("Ignoring document 'content-id'") | ||
end | ||
end | ||
|
||
context "when the document doesn't have a base path or a details.url" do | ||
let(:document_type) { "internal" } | ||
let(:base_path) { nil } | ||
let(:url) { nil } | ||
context "when the document type is on the ignore list but the path is excluded" do | ||
let(:document_type) { "test_ignored_type" } # see test section in YAML config | ||
let(:base_path) { "/test_ignored_path_override" } # see test section in YAML config | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Ignore) } | ||
it "calls the put service" do | ||
expect(put_service).to have_received(:call) | ||
end | ||
end | ||
|
||
context "when the document doesn't have a base path but does have a url" do | ||
let(:document_type) { "external_content" } | ||
let(:base_path) { nil } | ||
let(:url) { "https://www.example.com" } | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Publish) } | ||
it "calls the put service" do | ||
expect(put_service).to have_received(:call) | ||
end | ||
end | ||
|
||
context "when the document has a blank locale but otherwise should be added" do | ||
let(:document_type) { "stuff" } | ||
let(:locale) { nil } | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Publish) } | ||
it "calls the put service" do | ||
expect(put_service).to have_received(:call) | ||
end | ||
end | ||
|
||
context "when the document type is anything else" do | ||
let(:document_type) { "anything-else" } | ||
|
||
it { is_expected.to be_a(PublishingApiAction::Publish) } | ||
it "calls the put service" do | ||
expect(put_service).to have_received(:call) | ||
end | ||
end | ||
end | ||
end |