2022-07-08 12:26:21 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe UseCase::Question::CreateFollowers do
|
|
|
|
subject do
|
|
|
|
UseCase::Question::CreateFollowers.call(
|
2022-07-08 12:28:44 -07:00
|
|
|
source_user_id: source_user.id,
|
2023-11-01 14:40:41 -07:00
|
|
|
content:,
|
|
|
|
author_identifier:,
|
2022-07-08 12:26:21 -07:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "user is logged in" do
|
2023-11-01 14:40:41 -07:00
|
|
|
before do
|
|
|
|
followers.each do |target_user|
|
|
|
|
target_user.follow source_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-08 12:26:21 -07:00
|
|
|
let(:source_user) { create(:user) }
|
2023-11-01 14:40:41 -07:00
|
|
|
let(:followers) { create_list(:user, 5) }
|
2022-07-08 12:26:21 -07:00
|
|
|
let(:content) { "content" }
|
|
|
|
let(:author_identifier) { nil }
|
|
|
|
|
|
|
|
it "creates question" do
|
2022-07-30 06:51:28 -07:00
|
|
|
expect(subject[:resource]).to be_persisted
|
2022-07-08 12:26:21 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "enqueues a QuestionWorker job" do
|
2023-11-01 14:40:41 -07:00
|
|
|
followers.each do |target_user|
|
|
|
|
expect(QuestionWorker).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id)
|
|
|
|
end
|
2022-07-08 12:26:21 -07:00
|
|
|
end
|
2023-01-02 00:20:59 -08:00
|
|
|
|
|
|
|
it "increments the asked count" do
|
|
|
|
expect { subject }.to change { source_user.reload.asked_count }.by(1)
|
|
|
|
end
|
2022-07-08 12:26:21 -07:00
|
|
|
end
|
|
|
|
end
|