Add tests for mute relationship and notification behaviour

This commit is contained in:
Andreas Nedbal 2022-12-29 04:52:52 +01:00 committed by Andreas Nedbal
parent 744724bc3a
commit 7afff7884e
4 changed files with 85 additions and 0 deletions

View File

@ -105,6 +105,29 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
it_behaves_like "fails when answer content is empty"
end
context "when the question author mutes the user" do
let(:inbox_user) { user }
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"message" => anything
}
end
before do
question.user.mute(inbox_user)
end
include_examples "creates the answer"
it_behaves_like "fails when answer content is empty"
it "does not create a notification for the question author" do
expect{ subject }.to change { question.user.notifications.count }.by(0)
end
end
end
context "when inbox is false" do

View File

@ -100,6 +100,28 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
include_examples "does not create the comment"
end
context "when the answer author is muting the user" do
before do
answer.user.mute(user)
end
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"message" => anything,
"render" => anything,
"count" => 1
}
end
include_examples "creates the comment"
it "does not create a notification for the author" do
expect{ subject }.to change { answer.user.notifications.count }.by(0)
end
end
end
context "when answer does not exist" do

View File

@ -155,6 +155,24 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
include_examples "does not create the question", check_for_inbox: false
end
context "when the sender is muted by the user" do
before(:each) do
target_user.mute(user)
end
let(:anonymous_question) { "false" }
let(:user_allows_anonymous_questions) { true }
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"message" => anything
}
end
include_examples "creates the question but doesn't send it to the user's inbox"
end
context "when the sender is blocking the user" do
before(:each) do
user.block(target_user)

View File

@ -54,6 +54,16 @@ describe Ajax::RelationshipController, type: :controller do
let(:type) { "follow" }
include_examples "valid relationship type"
context "target user mutes source user" do
before do
user2.mute(user)
end
it "creates the relationship but no notification" do
expect { subject }.to change { Notification.count }.by(0)
end
end
end
context "type = 'block'" do
@ -62,6 +72,12 @@ describe Ajax::RelationshipController, type: :controller do
include_examples "valid relationship type"
end
context "type = 'mute'" do
let(:type) { "mute" }
include_examples "valid relationship type"
end
context "type = 'dick'" do
let(:type) { "dick" }
@ -121,6 +137,12 @@ describe Ajax::RelationshipController, type: :controller do
include_examples "valid relationship type"
end
context "type = 'mute'" do
let(:type) { "mute" }
include_examples "valid relationship type"
end
context "type = 'dick'" do
let(:type) { "dick" }