demarches-normaliennes/spec/models/expert_spec.rb

79 lines
2.2 KiB
Ruby
Raw Normal View History

2021-01-07 15:45:02 +01:00
RSpec.describe Expert, type: :model do
describe 'an expert could be add to a procedure' do
let(:procedure) { create(:procedure) }
2021-01-15 16:33:36 +01:00
let(:expert) { create(:expert) }
2021-01-07 15:45:02 +01:00
before do
procedure.experts << expert
procedure.reload
end
it { expect(procedure.experts).to eq([expert]) }
it { expect(ExpertsProcedure.where(expert: expert, procedure: procedure).count).to eq(1) }
it { expect(ExpertsProcedure.where(expert: expert, procedure: procedure).first.allow_decision_access).to be_falsy }
2021-01-07 15:45:02 +01:00
end
2021-10-07 14:34:01 +02:00
describe '#merge' do
let(:old_expert) { create(:expert) }
let(:new_expert) { create(:expert) }
subject { new_expert.merge(old_expert) }
context 'when an old expert access a procedure' do
let(:procedure) { create(:procedure) }
before do
procedure.experts << old_expert
subject
end
it 'transfers the access to the new expert' do
expect(procedure.reload.experts). to match_array(new_expert)
end
end
context 'when both expert access a procedure' do
let(:procedure) { create(:procedure) }
before do
procedure.experts << old_expert
procedure.experts << new_expert
subject
end
it 'removes the old one' do
expect(procedure.reload.experts). to match_array(new_expert)
end
end
context 'when an old expert has a commentaire' do
let(:dossier) { create(:dossier) }
let(:commentaire) { CommentaireService.build(old_expert, dossier, body: "Mon commentaire") }
before do
commentaire.save
subject
end
it 'transfers the commentaire to the new expert' do
expect(new_expert.reload.commentaires).to match_array(commentaire)
end
end
context 'when an old expert claims for an avis' do
let!(:avis) { create(:avis, dossier: create(:dossier), claimant: old_expert) }
before do
subject
end
it 'transfers the claim to the new expert' do
avis_claimed_by_new_expert = Avis
.where(claimant_id: new_expert.id, claimant_type: Expert.name)
expect(avis_claimed_by_new_expert).to match_array(avis)
end
end
end
2021-01-07 15:45:02 +01:00
end