Replace usages of `QuestionWorker`

This commit is contained in:
Karina Kwiatek 2023-12-11 19:56:50 +01:00
parent aaee04b5ed
commit 64ac18843e
3 changed files with 31 additions and 30 deletions

View File

@ -1,19 +1,6 @@
# frozen_string_literal: true
class Ajax::QuestionController < AjaxController
def destroy
params.require :question
UseCase::Question::Destroy.call(
question_id: params[:question],
current_user: current_user
)
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
def create
params.require :question
params.require :anonymousQuestion
@ -24,14 +11,14 @@ class Ajax::QuestionController < AjaxController
@response = {
success: true,
message: t(".success"),
status: :okay
status: :okay,
}
if user_signed_in? && params[:rcpt] == "followers"
UseCase::Question::CreateFollowers.call(
source_user_id: current_user.id,
content: params[:question],
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
)
return
end
@ -41,7 +28,21 @@ class Ajax::QuestionController < AjaxController
target_user_id: params[:rcpt],
content: params[:question],
anonymous: params[:anonymousQuestion],
author_identifier: AnonymousBlock.get_identifier(request.remote_ip)
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
)
end
def destroy
params.require :question
UseCase::Question::Destroy.call(
question_id: params[:question],
current_user: current_user,
)
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
end

View File

@ -48,25 +48,25 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
include_examples "returns the expected response"
end
shared_examples "enqueues QuestionWorker jobs" do
it "enqueues a QuestionWorker job" do
allow(QuestionWorker).to receive(:perform_bulk)
shared_examples "enqueues SendToInboxJob jobs" do
it "enqueues a SendToInboxJob job" do
allow(SendToInboxJob).to receive(:perform_bulk)
subject
question_id = Question.last.id
bulk_args = followers.map { |f| [f.id, question_id] }
expect(QuestionWorker).to have_received(:perform_bulk).with(bulk_args)
expect(SendToInboxJob).to have_received(:perform_bulk).with(bulk_args)
end
include_examples "returns the expected response"
end
shared_examples "does not enqueue a QuestionWorker job" do
it "does not enqueue a QuestionWorker job" do
allow(QuestionWorker).to receive(:perform_async)
allow(QuestionWorker).to receive(:perform_bulk)
shared_examples "does not enqueue a SendToInboxJob job" do
it "does not enqueue a SendToInboxJob job" do
allow(SendToInboxJob).to receive(:perform_async)
allow(SendToInboxJob).to receive(:perform_bulk)
subject
expect(QuestionWorker).not_to have_received(:perform_async)
expect(QuestionWorker).not_to have_received(:perform_bulk)
expect(SendToInboxJob).not_to have_received(:perform_async)
expect(SendToInboxJob).not_to have_received(:perform_bulk)
end
include_examples "returns the expected response"
@ -209,7 +209,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
let(:expected_question_anonymous) { false }
include_examples "creates the question", false
include_examples "enqueues QuestionWorker jobs"
include_examples "enqueues SendToInboxJob jobs"
end
context "when anonymousQuestion is false" do
@ -217,7 +217,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
let(:expected_question_anonymous) { false }
include_examples "creates the question", false
include_examples "enqueues QuestionWorker jobs"
include_examples "enqueues SendToInboxJob jobs"
end
end
@ -384,7 +384,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
}
end
include_examples "does not enqueue a QuestionWorker job"
include_examples "does not enqueue a SendToInboxJob job"
end
context "when rcpt is an invalid value" do

View File

@ -29,7 +29,7 @@ describe UseCase::Question::CreateFollowers do
it "enqueues a QuestionWorker job" do
followers.each do |target_user|
expect(QuestionWorker).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id)
expect(SendToInboxJob).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id)
end
end