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|
|
2023-12-11 10:56:50 -08:00
|
|
|
expect(SendToInboxJob).to have_enqueued_sidekiq_job(target_user.id, subject[:resource].id)
|
2023-11-01 14:40:41 -07:00
|
|
|
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
|
2024-03-10 12:30:47 -07:00
|
|
|
|
|
|
|
context "content is over 32768 characters long" do
|
|
|
|
let(:content) { "a" * 32769 }
|
|
|
|
|
|
|
|
it "raises an error" do
|
|
|
|
expect { subject }.to raise_error(Errors::QuestionTooLong)
|
|
|
|
end
|
|
|
|
end
|
2022-07-08 12:26:21 -07:00
|
|
|
end
|
|
|
|
end
|