From 37c63f0f52bc46313b848df28f24b037fe88e9b1 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 14 Jun 2022 23:56:03 +0200 Subject: [PATCH] Add tests for direct questions with muted terms or anon blocks --- .../ajax/question_controller_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/controllers/ajax/question_controller_spec.rb b/spec/controllers/ajax/question_controller_spec.rb index 9d0224c3..af936378 100644 --- a/spec/controllers/ajax/question_controller_spec.rb +++ b/spec/controllers/ajax/question_controller_spec.rb @@ -37,6 +37,18 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do include_examples "returns the expected response" end + shared_examples "creates the question but doesn't send it to the user's inbox" do + it "creates the question" do + expect { subject }.to(change { Question.count }.by(1)) + end + + it "does not add the question to the target users' inbox" do + expect { subject }.not_to(change { target_user.inboxes.count }) + end + + include_examples "returns the expected response" + end + shared_examples "enqueues a QuestionWorker job" do |expected_rcpt| it "enqueues a QuestionWorker job" do allow(QuestionWorker).to receive(:perform_async) @@ -238,6 +250,28 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do include_examples "does not create the question" end + + context "when question contains a muted term" do + before do + MuteRule.create(user: target_user, muted_phrase: "Preis") + end + + include_examples "creates the question but doesn't send it to the user's inbox" + end + + context "when sender is blocked by the user" do + before do + identifier = AnonymousBlock.get_identifier("0.0.0.0") + dummy_question = FactoryBot.create(:question, author_is_anonymous: true, author_identifier: identifier) + AnonymousBlock.create( + user: target_user, + identifier: identifier, + question: dummy_question, + ) + end + + include_examples "creates the question but doesn't send it to the user's inbox" + end end context "when user does not allow anonymous questions" do