mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-13 21:33:20 +01:00
Add test for unpin use case
This commit is contained in:
parent
438884e13a
commit
664bf5eab2
1 changed files with 31 additions and 0 deletions
31
spec/lib/use_case/answer/unpin_spec.rb
Normal file
31
spec/lib/use_case/answer/unpin_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe UseCase::Answer::Unpin do
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
subject { UseCase::Answer::Unpin.call(user:, answer:) }
|
||||
|
||||
context "answer exists" do
|
||||
let(:pinned_at) { Time.at(1603290950).utc }
|
||||
let(:answer) { FactoryBot.create(:answer, user: FactoryBot.create(:user), pinned_at:) }
|
||||
|
||||
context "as answer owner" do
|
||||
let(:user) { answer.user }
|
||||
|
||||
it "unpins the answer" do
|
||||
expect { subject }.to change { answer.pinned_at }.from(pinned_at).to(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "as other user" do
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
it "does not unpin the answer" do
|
||||
expect { subject }.to raise_error(Errors::NotAuthorized)
|
||||
expect(answer.reload.pinned_at).to eq(pinned_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue