2022-01-16 09:38:06 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe UseCase::Relationship::Destroy do
|
|
|
|
shared_examples_for "valid relationship type" do
|
|
|
|
its([:status]) { is_expected.to eq(204) }
|
|
|
|
its([:extra]) { is_expected.to eq(target_user: user2) }
|
|
|
|
|
|
|
|
context "relationship exists" do
|
|
|
|
before do
|
|
|
|
user1.public_send(type, user2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "destroys a relationship" do
|
|
|
|
expect { subject }.to change { Relationship.count }.by(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "relationship does not exist" do
|
|
|
|
it "does not change anything at all" do
|
|
|
|
expect { subject }.to change { Relationship.count }.by(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:base_params) do
|
|
|
|
{
|
2022-01-22 13:48:55 -08:00
|
|
|
source_user: source_user,
|
2022-01-22 14:12:54 -08:00
|
|
|
target_user: target_user,
|
|
|
|
type: type
|
2022-01-16 09:38:06 -08:00
|
|
|
}
|
|
|
|
end
|
2022-01-22 14:12:54 -08:00
|
|
|
let(:params) { base_params }
|
2022-01-23 03:28:54 -08:00
|
|
|
let(:source_user) { user1 }
|
|
|
|
let(:target_user) { user2 }
|
2022-01-22 14:12:54 -08:00
|
|
|
let(:type) { nil }
|
2022-01-16 09:38:06 -08:00
|
|
|
|
|
|
|
# test data:
|
|
|
|
let!(:user1) { FactoryBot.create(:user, screen_name: "timallen") }
|
|
|
|
let!(:user2) { FactoryBot.create(:user, screen_name: "joehilyar") }
|
|
|
|
|
2022-07-23 01:02:06 -07:00
|
|
|
subject { described_class.call(**params) }
|
2022-01-16 09:38:06 -08:00
|
|
|
|
|
|
|
context "type = 'follow'" do
|
|
|
|
let(:type) { "follow" }
|
|
|
|
|
|
|
|
include_examples "valid relationship type"
|
2022-01-23 03:28:54 -08:00
|
|
|
|
|
|
|
context "using screen names" do
|
2022-06-12 00:34:49 -07:00
|
|
|
let(:source_user) { user1 }
|
|
|
|
let(:target_user) { user2 }
|
|
|
|
|
|
|
|
include_examples "valid relationship type"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "type = 'block'" do
|
|
|
|
let(:type) { "block" }
|
|
|
|
|
|
|
|
include_examples "valid relationship type"
|
|
|
|
|
|
|
|
context "using screen names" do
|
|
|
|
let(:source_user) { user1 }
|
|
|
|
let(:target_user) { user2 }
|
2022-01-23 03:28:54 -08:00
|
|
|
|
|
|
|
include_examples "valid relationship type"
|
|
|
|
end
|
2022-01-16 09:38:06 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "type = 'dick'" do
|
|
|
|
let(:type) { "dick" }
|
|
|
|
|
|
|
|
include_examples "raises an error", Dry::Types::ConstraintError
|
|
|
|
end
|
|
|
|
end
|