-
Notifications
You must be signed in to change notification settings - Fork 11
/
destroy_interactor_spec.rb
55 lines (45 loc) · 1.66 KB
/
destroy_interactor_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true
RSpec.describe Editions::DestroyInteractor do
describe ".call" do
let(:edition) { create(:edition) }
let(:user) { create :user }
let(:params) do
ActionController::Parameters.new(document: edition.document.to_param)
end
before do
stub_publishing_api_unreserve_path(edition.base_path)
stub_publishing_api_discard_draft(edition.content_id)
end
it "discards an edition" do
result = Editions::DestroyInteractor.call(params: params, user: user)
expect(result).to be_success
expect(result.edition).to be_discarded
end
it "delegates to the DeleteDraftEditionService" do
expect(DeleteDraftEditionService)
.to receive(:call)
.with(edition.document, user)
Editions::DestroyInteractor.call(params: params, user: user)
end
it "creates a timeline entry" do
expect { Editions::DestroyInteractor.call(params: params, user: user) }
.to change { TimelineEntry.where(entry_type: :draft_discarded).count }
.by(1)
end
context "when the Publishing API is down" do
before { stub_publishing_api_isnt_available }
it "fails with an api_error flag" do
result = Editions::DestroyInteractor.call(params: params, user: user)
expect(result).to be_failure
expect(result.api_error).to be(true)
end
end
context "when the edition isn't editable" do
let(:edition) { create(:edition, :published) }
it "raises a state error" do
expect { Editions::DestroyInteractor.call(params: params, user: user) }
.to raise_error(EditionAssertions::StateError)
end
end
end
end