Add tests for mute rule use cases

This commit is contained in:
Karina Kwiatek 2023-01-02 12:26:52 +01:00 committed by Andreas Nedbal
parent 04bc1da8cf
commit b3a7cf388a
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
require "rails_helper"
describe UseCase::MuteRule::Create do
subject { UseCase::MuteRule::Create.call(user:, phrase:) }
context "user passed" do
let(:user) { FactoryBot.create(:user) }
context "phrase is empty" do
let(:phrase) { "" }
it "does not create the rule" do
expect { subject }.not_to(change { MuteRule.count })
end
end
context "phrase is non-empty" do
let(:phrase) { "test" }
it "creates the rule" do
expect { subject }.to change { MuteRule.count }.by(1)
end
end
end
end

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
require "rails_helper"
describe UseCase::MuteRule::Destroy do
subject { UseCase::MuteRule::Destroy.call(rule:) }
context "rule exists" do
let(:user) { FactoryBot.create(:user) }
let(:rule) { MuteRule.create(user:, muted_phrase: "test") }
it "deletes the mute rule" do
expect { subject }.to change { MuteRule.exists?(rule.id) }.from(true).to(false)
end
end
end