2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-17 11:43:01 +02:00
|
|
|
describe Commentaire do
|
|
|
|
it { is_expected.to have_db_column(:email) }
|
|
|
|
it { is_expected.to have_db_column(:body) }
|
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
|
|
|
it { is_expected.to have_db_column(:updated_at) }
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2019-07-01 18:14:02 +02:00
|
|
|
describe 'messagerie_available validation' do
|
|
|
|
subject { commentaire.valid?(:create) }
|
|
|
|
|
|
|
|
context 'with a commentaire created by the DS system' do
|
|
|
|
let(:commentaire) { build :commentaire, email: CONTACT_EMAIL }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on an archived dossier' do
|
|
|
|
let(:dossier) { create :dossier, :archived }
|
|
|
|
let(:commentaire) { build :commentaire, dossier: dossier }
|
|
|
|
|
2021-07-22 14:33:39 +02:00
|
|
|
it { is_expected.to be_truthy }
|
2019-07-01 18:14:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a dossier en_construction' do
|
|
|
|
let(:dossier) { create :dossier, :en_construction }
|
|
|
|
let(:commentaire) { build :commentaire, dossier: dossier }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#sent_by_system?" do
|
|
|
|
subject { commentaire.sent_by_system? }
|
2019-07-01 18:14:02 +02:00
|
|
|
|
|
|
|
let(:commentaire) { build :commentaire, email: email }
|
|
|
|
|
|
|
|
context 'with a commentaire created by the DS system' do
|
|
|
|
let(:email) { CONTACT_EMAIL }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-15 12:01:56 +01:00
|
|
|
describe "sent_by?" do
|
|
|
|
let(:commentaire) { build(:commentaire, instructeur: build(:instructeur)) }
|
|
|
|
subject { commentaire.sent_by?(nil) }
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
end
|
|
|
|
|
2019-07-01 18:14:02 +02:00
|
|
|
describe "#redacted_email" do
|
|
|
|
subject { commentaire.redacted_email }
|
|
|
|
|
2024-08-31 21:04:32 +02:00
|
|
|
let(:procedure) { create(:procedure, hide_instructeurs_email: false) }
|
2020-05-12 17:58:00 +02:00
|
|
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'with a commentaire created by a instructeur' do
|
2021-10-25 15:50:48 +02:00
|
|
|
let(:instructeur) { create :instructeur, email: 'some_user@exemple.fr' }
|
2020-05-12 17:58:00 +02:00
|
|
|
let(:commentaire) { build :commentaire, instructeur: instructeur, dossier: dossier }
|
2019-07-01 18:14:02 +02:00
|
|
|
|
2020-05-12 17:58:00 +02:00
|
|
|
context 'when the procedure shows instructeurs email' do
|
|
|
|
it { is_expected.to eq 'some_user' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure hides instructeurs email' do
|
2024-08-31 21:04:32 +02:00
|
|
|
let(:procedure) { create(:procedure, hide_instructeurs_email: true) }
|
2020-05-12 17:58:00 +02:00
|
|
|
it { is_expected.to eq "Instructeur n° #{instructeur.id}" }
|
|
|
|
end
|
2019-07-01 18:14:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a commentaire created by a user' do
|
2021-04-22 15:44:58 +02:00
|
|
|
let(:commentaire) { build :commentaire, email: user.email }
|
2019-07-01 18:14:02 +02:00
|
|
|
let(:user) { build :user, email: 'some_user@exemple.fr' }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'some_user@exemple.fr' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 13:32:48 +02:00
|
|
|
describe "#notify" do
|
|
|
|
let(:procedure) { create(:procedure) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2021-04-22 15:44:58 +02:00
|
|
|
let(:expert) { create(:expert) }
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:assign_to) { create(:assign_to, instructeur: instructeur, procedure: procedure) }
|
2017-05-12 13:32:48 +02:00
|
|
|
let(:user) { create(:user) }
|
2019-07-01 18:14:02 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure, user: user) }
|
2017-05-12 13:32:48 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context "with a commentaire created by a instructeur" do
|
2021-04-22 15:44:58 +02:00
|
|
|
let(:commentaire) { CommentaireService.build(instructeur, dossier, body: "Mon commentaire") }
|
|
|
|
|
2021-11-15 15:38:57 +01:00
|
|
|
it "calls notify_user with delay so instructeur can destroy his comment in case of failure" do
|
2021-11-16 15:12:05 +01:00
|
|
|
expect(commentaire).to receive(:notify_user).with(wait: 5.minutes)
|
2021-04-22 15:44:58 +02:00
|
|
|
commentaire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a commentaire created by an expert" do
|
|
|
|
let(:commentaire) { CommentaireService.build(expert, dossier, body: "Mon commentaire") }
|
2017-05-12 13:32:48 +02:00
|
|
|
|
2022-03-31 15:33:59 +02:00
|
|
|
it "calls notify_user with delay so expert can destroy his comment in case of failure" do
|
|
|
|
expect(commentaire).to receive(:notify_user).with(wait: 5.minutes)
|
2017-05-12 13:32:48 +02:00
|
|
|
commentaire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a commentaire automatically created (notification)" do
|
2021-11-30 18:56:12 +01:00
|
|
|
let(:commentaire) { CommentaireService.build(CONTACT_EMAIL, dossier, body: "Mon commentaire") }
|
2017-05-12 13:32:48 +02:00
|
|
|
|
2021-04-22 15:44:58 +02:00
|
|
|
it "does not call notify_user" do
|
2021-11-16 15:12:05 +01:00
|
|
|
expect(commentaire).not_to receive(:notify_user).with(no_args)
|
2017-05-12 13:32:48 +02:00
|
|
|
commentaire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|