Skip to content

Commit 6dd9bd6

Browse files
authored
Merge pull request #106 from alphagov/doc-refac-tests
Refactor specs for `PublishingApiDocument`
2 parents c623a46 + ade11f5 commit 6dd9bd6

2 files changed

Lines changed: 90 additions & 127 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
RSpec.describe PublishingApi::Action do
2+
subject(:action) { concern_consumer.new(document_hash) }
3+
4+
let(:concern_consumer) { Struct.new(:document_hash).include(described_class) }
5+
let(:document_hash) { { document_type:, base_path:, locale:, details: { url: } } }
6+
let(:base_path) { "/test_base_path" }
7+
let(:url) { nil }
8+
let(:locale) { "en" }
9+
10+
%w[gone redirect substitute vanish].each do |document_type|
11+
context "when the document type is #{document_type}" do
12+
let(:document_type) { document_type }
13+
14+
it { is_expected.to be_unpublish }
15+
end
16+
end
17+
18+
context "when the document type is on the ignore list as a string" do
19+
let(:document_type) { "test_ignored_type" } # see test section in YAML config
20+
21+
it { is_expected.to be_ignore }
22+
23+
it "has the expected ignore_reason" do
24+
expect(action.ignore_reason).to eq("document_type on ignorelist (test_ignored_type)")
25+
end
26+
end
27+
28+
context "when the document type is on the ignore list as a pattern" do
29+
let(:document_type) { "another_test_ignored_type_foo" } # see test section in YAML config
30+
31+
it { is_expected.to be_ignore }
32+
33+
it "has the expected ignore_reason" do
34+
expect(action.ignore_reason).to eq(
35+
"document_type on ignorelist (another_test_ignored_type_foo)",
36+
)
37+
end
38+
end
39+
40+
context "when the document doesn't have a base path or a details.url" do
41+
let(:document_type) { "internal" }
42+
let(:base_path) { nil }
43+
let(:url) { nil }
44+
45+
it { is_expected.to be_ignore }
46+
47+
it "has the expected ignore_reason" do
48+
expect(action.ignore_reason).to eq("unaddressable")
49+
end
50+
end
51+
52+
context "when the document doesn't have an English locale" do
53+
let(:document_type) { "dokument" }
54+
let(:locale) { "de" }
55+
56+
it { is_expected.to be_ignore }
57+
58+
it "has the expected ignore_reason" do
59+
expect(action.ignore_reason).to eq("locale not permitted (de)")
60+
end
61+
end
62+
63+
context "when the document type is on the ignore list but the path is excluded" do
64+
let(:document_type) { "test_ignored_type" } # see test section in YAML config
65+
let(:base_path) { "/test_ignored_path_override" } # see test section in YAML config
66+
67+
it { is_expected.to be_publish }
68+
end
69+
70+
context "when the document doesn't have a base path but does have a url" do
71+
let(:document_type) { "external_content" }
72+
let(:base_path) { nil }
73+
let(:url) { "https://www.example.com" }
74+
75+
it { is_expected.to be_publish }
76+
end
77+
78+
context "when the document has a blank locale but otherwise should be added" do
79+
let(:document_type) { "stuff" }
80+
let(:locale) { nil }
81+
82+
it { is_expected.to be_publish }
83+
end
84+
85+
context "when the document type is anything else" do
86+
let(:document_type) { "anything-else" }
87+
88+
it { is_expected.to be_publish }
89+
end
90+
end

spec/models/publishing_api_document_spec.rb

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)