mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-15 20:19:59 +01:00
Add tests for reaction use cases
This commit is contained in:
parent
3811f15bd7
commit
4458aba37f
2 changed files with 64 additions and 0 deletions
33
spec/lib/use_case/reaction/create_spec.rb
Normal file
33
spec/lib/use_case/reaction/create_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe UseCase::Reaction::Create do
|
||||
shared_examples_for "valid target type" do
|
||||
it "creates a reaction" do
|
||||
expect { subject }.to change { target.smile_count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
subject { UseCase::Reaction::Create.call(source_user: user, target:) }
|
||||
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
context "target is an Answer" do
|
||||
let(:target) { FactoryBot.create(:answer, user:) }
|
||||
|
||||
include_examples "valid target type"
|
||||
end
|
||||
|
||||
context "target is a Comment" do
|
||||
let(:target) { FactoryBot.create(:comment, user:, answer: FactoryBot.create(:answer, user:)) }
|
||||
|
||||
include_examples "valid target type"
|
||||
end
|
||||
|
||||
context "target is a Question" do
|
||||
let(:target) { FactoryBot.create(:question) }
|
||||
|
||||
include_examples "raises an error", Dry::Types::ConstraintError
|
||||
end
|
||||
end
|
31
spec/lib/use_case/reaction/destroy_spec.rb
Normal file
31
spec/lib/use_case/reaction/destroy_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe UseCase::Reaction::Destroy do
|
||||
shared_examples_for "valid target type" do
|
||||
before do
|
||||
user.smile target
|
||||
end
|
||||
|
||||
it "destroys a reaction" do
|
||||
expect { subject }.to change { target.smile_count }.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
subject { UseCase::Reaction::Destroy.call(source_user: user, target:) }
|
||||
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
context "target is an Answer" do
|
||||
let(:target) { FactoryBot.create(:answer, user:) }
|
||||
|
||||
include_examples "valid target type"
|
||||
end
|
||||
|
||||
context "target is a Comment" do
|
||||
let(:target) { FactoryBot.create(:comment, user:, answer: FactoryBot.create(:answer, user:)) }
|
||||
|
||||
include_examples "valid target type"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue