2024-09-17 14:43:34 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe(AdminNotices::Dismiss) do
|
2024-10-29 00:21:59 +08:00
|
|
|
describe described_class::Contract, type: :model do
|
|
|
|
it { is_expected.to validate_presence_of(:id) }
|
|
|
|
end
|
2024-09-17 14:43:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
describe ".call" do
|
|
|
|
subject(:result) { described_class.call(params:, **dependencies) }
|
2024-10-18 17:13:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
fab!(:admin_notice) { Fabricate(:admin_notice, identifier: "problem.test") }
|
|
|
|
fab!(:problem_check) { Fabricate(:problem_check_tracker, identifier: "problem.test", blips: 3) }
|
2024-09-17 14:43:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
let(:params) { { id: notice_id } }
|
|
|
|
let(:notice_id) { admin_notice.id }
|
|
|
|
let(:dependencies) { { guardian: current_user.guardian } }
|
2024-09-17 14:43:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
context "when user is not allowed to perform the action" do
|
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
2024-09-17 14:43:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
it { is_expected.to fail_a_policy(:invalid_access) }
|
|
|
|
end
|
2024-10-07 12:29:33 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
context "when data is invalid" do
|
|
|
|
let(:notice_id) { nil }
|
2024-10-07 12:29:33 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
it { is_expected.to fail_a_contract }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the admin notice has already been dismissed" do
|
|
|
|
before { admin_notice.destroy! }
|
2024-09-17 14:43:34 +08:00
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
it { is_expected.to run_successfully }
|
2024-09-17 14:43:34 +08:00
|
|
|
end
|
|
|
|
|
2024-10-29 00:21:59 +08:00
|
|
|
context "when everything's ok" do
|
|
|
|
it { is_expected.to run_successfully }
|
|
|
|
|
|
|
|
it "destroys the admin notice" do
|
|
|
|
expect { result }.to change { AdminNotice.count }.from(1).to(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resets any associated problem check" do
|
|
|
|
expect { result }.to change { problem_check.reload.blips }.from(3).to(0)
|
|
|
|
end
|
2024-09-17 14:43:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|