Retrospring/spec/lib/use_case/question/create_followers_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
Ruby
Raw Normal View History

# 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,
content:,
author_identifier:,
)
end
context "user is logged in" do
before do
followers.each do |target_user|
target_user.follow source_user
end
end
let(:source_user) { create(:user) }
let(:followers) { create_list(:user, 5) }
let(:content) { "content" }
let(:author_identifier) { nil }
it "creates question" do
expect(subject[:resource]).to be_persisted
end
it "enqueues a QuestionWorker job" do
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)
end
end
it "increments the asked count" do
expect { subject }.to change { source_user.reload.asked_count }.by(1)
end
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
end
end