2016-11-14 18:36:09 +01:00
|
|
|
require 'spec_helper'
|
2015-09-22 10:15:12 +02:00
|
|
|
|
|
|
|
describe Gestionnaire, type: :model do
|
2016-07-18 18:24:29 +02:00
|
|
|
let(:admin) { create :administrateur }
|
2017-07-18 15:26:33 +02:00
|
|
|
let!(:procedure) { create :procedure, :published, administrateur: admin }
|
|
|
|
let!(:procedure_2) { create :procedure, :published, administrateur: admin }
|
|
|
|
let!(:procedure_3) { create :procedure, :published, administrateur: admin }
|
2018-02-26 17:25:28 +01:00
|
|
|
let(:gestionnaire) { create :gestionnaire, administrateurs: [admin] }
|
2018-12-03 13:51:45 +01:00
|
|
|
let!(:procedure_assign) { assign(procedure) }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
|
|
|
before do
|
2018-12-03 13:51:45 +01:00
|
|
|
assign(procedure_2)
|
2016-07-18 18:24:29 +02:00
|
|
|
end
|
|
|
|
|
2019-06-27 16:19:08 +02:00
|
|
|
describe 'default features' do
|
|
|
|
it { expect(gestionnaire.features).to eq({ "enable_email_login_token" => true }) }
|
|
|
|
end
|
|
|
|
|
2018-12-03 13:57:59 +01:00
|
|
|
describe '#visible_procedures' do
|
|
|
|
let(:procedure_not_assigned) { create :procedure, administrateur: admin }
|
2019-03-06 14:42:27 +01:00
|
|
|
let(:procedure_with_default_path) { create :procedure, administrateur: admin }
|
|
|
|
let(:procedure_with_custom_path) { create :procedure, :with_path, administrateur: admin }
|
2018-12-03 13:57:59 +01:00
|
|
|
let(:procedure_archived_manually) { create :procedure, :archived, administrateur: admin }
|
|
|
|
let(:procedure_archived_automatically) { create :procedure, :archived_automatically, administrateur: admin }
|
|
|
|
|
|
|
|
before do
|
2019-03-06 14:42:27 +01:00
|
|
|
assign(procedure_with_default_path)
|
|
|
|
assign(procedure_with_custom_path)
|
2018-12-03 13:57:59 +01:00
|
|
|
assign(procedure_archived_manually)
|
|
|
|
assign(procedure_archived_automatically)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { gestionnaire.visible_procedures }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(subject).not_to include(procedure_not_assigned)
|
2019-03-06 14:42:27 +01:00
|
|
|
expect(subject).to include(procedure_with_default_path)
|
|
|
|
expect(subject).to include(procedure_with_custom_path)
|
2018-12-03 13:57:59 +01:00
|
|
|
expect(subject).to include(procedure_archived_manually)
|
|
|
|
expect(subject).to include(procedure_archived_automatically)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-17 11:28:14 +02:00
|
|
|
describe 'follow' do
|
|
|
|
let(:dossier) { create :dossier }
|
|
|
|
let(:already_followed_dossier) { create :dossier }
|
|
|
|
|
|
|
|
before { gestionnaire.followed_dossiers << already_followed_dossier }
|
|
|
|
|
|
|
|
context 'when a gestionnaire follow a dossier for the first time' do
|
|
|
|
before { gestionnaire.follow(dossier) }
|
|
|
|
|
|
|
|
it { expect(gestionnaire.follow?(dossier)).to be true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a gestionnaire follows a dossier already followed' do
|
|
|
|
before { gestionnaire.follow(already_followed_dossier) }
|
|
|
|
|
|
|
|
it { expect(gestionnaire.follow?(already_followed_dossier)).to be true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-05 14:10:49 +02:00
|
|
|
describe '#unfollow' do
|
|
|
|
let(:already_followed_dossier) { create(:dossier) }
|
|
|
|
before { gestionnaire.followed_dossiers << already_followed_dossier }
|
|
|
|
|
|
|
|
context 'when a gestionnaire unfollow a dossier already followed' do
|
|
|
|
before do
|
|
|
|
gestionnaire.unfollow(already_followed_dossier)
|
|
|
|
already_followed_dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(gestionnaire.follow?(already_followed_dossier)).to be false }
|
2019-06-07 14:59:49 +02:00
|
|
|
it { expect(gestionnaire.previously_followed_dossiers).to include(already_followed_dossier) }
|
2017-10-05 14:10:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
describe '#follow?' do
|
|
|
|
let!(:dossier) { create :dossier, procedure: procedure }
|
|
|
|
|
2017-07-17 13:13:20 +02:00
|
|
|
subject { gestionnaire.follow?(dossier) }
|
2016-07-18 18:24:29 +02:00
|
|
|
|
|
|
|
context 'when gestionnaire follow a dossier' do
|
|
|
|
before do
|
|
|
|
create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire not follow a dossier' do
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 11:24:32 +01:00
|
|
|
describe "#assign_to_procedure" do
|
|
|
|
subject { gestionnaire.assign_to_procedure(procedure_to_assign) }
|
|
|
|
|
|
|
|
context "with a procedure not already assigned" do
|
|
|
|
let(:procedure_to_assign) { procedure_3 }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
2018-12-24 17:28:20 +01:00
|
|
|
it { expect { subject }.to change(gestionnaire.procedures, :count) }
|
2018-02-20 11:24:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with an already assigned procedure" do
|
|
|
|
let(:procedure_to_assign) { procedure }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
2018-12-24 17:28:20 +01:00
|
|
|
it { expect { subject }.not_to change(gestionnaire.procedures, :count) }
|
2018-02-20 11:24:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#remove_from_procedure" do
|
|
|
|
subject { gestionnaire.remove_from_procedure(procedure_to_remove) }
|
|
|
|
|
|
|
|
context "with an assigned procedure" do
|
|
|
|
let(:procedure_to_remove) { procedure }
|
|
|
|
let!(:procedure_presentation) { procedure_assign.procedure_presentation }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
|
|
|
describe "consequences" do
|
|
|
|
before do
|
|
|
|
procedure_assign.build_procedure_presentation
|
|
|
|
procedure_assign.save
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes the assign_to and procedure_presentation" do
|
|
|
|
expect(AssignTo.where(id: procedure_assign).count).to eq(0)
|
|
|
|
expect(ProcedurePresentation.where(assign_to_id: procedure_assign.id).count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an already unassigned procedure" do
|
|
|
|
let(:procedure_to_remove) { procedure_3 }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-18 15:49:04 +02:00
|
|
|
context 'unified login' do
|
|
|
|
it 'syncs credentials to associated user' do
|
|
|
|
gestionnaire = create(:gestionnaire)
|
|
|
|
user = create(:user, email: gestionnaire.email)
|
2016-10-11 10:31:32 +02:00
|
|
|
|
2018-03-02 16:27:03 +01:00
|
|
|
gestionnaire.update(email: 'whoami@plop.com', password: 'super secret')
|
2016-10-18 15:49:04 +02:00
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.email).to eq('whoami@plop.com')
|
|
|
|
expect(user.valid_password?('super secret')).to be(true)
|
|
|
|
end
|
2016-12-07 17:24:01 +01:00
|
|
|
|
|
|
|
it 'syncs credentials to associated administrateur' do
|
2019-01-07 15:11:55 +01:00
|
|
|
admin = create(:administrateur)
|
|
|
|
gestionnaire = admin.gestionnaire
|
2016-12-07 17:24:01 +01:00
|
|
|
|
2019-01-07 15:11:55 +01:00
|
|
|
gestionnaire.update(password: 'super secret')
|
2016-12-07 17:24:01 +01:00
|
|
|
|
|
|
|
admin.reload
|
|
|
|
expect(admin.valid_password?('super secret')).to be(true)
|
|
|
|
end
|
2016-10-11 10:31:32 +02:00
|
|
|
end
|
2016-12-26 17:25:59 +01:00
|
|
|
|
2017-05-12 16:47:18 +02:00
|
|
|
describe 'last_week_overview' do
|
|
|
|
let!(:gestionnaire2) { create(:gestionnaire) }
|
|
|
|
subject { gestionnaire2.last_week_overview }
|
2018-10-25 15:19:29 +02:00
|
|
|
let(:friday) { Time.zone.local(2017, 5, 12) }
|
2018-10-25 15:07:15 +02:00
|
|
|
let(:monday) { Time.zone.now.beginning_of_week }
|
2017-05-12 16:47:18 +02:00
|
|
|
|
2017-11-29 16:07:39 +01:00
|
|
|
before { Timecop.freeze(friday) }
|
2017-10-05 16:10:00 +02:00
|
|
|
after { Timecop.return }
|
|
|
|
|
2017-05-12 16:47:18 +02:00
|
|
|
context 'when no procedure published was active last week' do
|
2018-05-16 17:21:12 +02:00
|
|
|
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire2], libelle: 'procedure') }
|
2017-05-12 16:47:18 +02:00
|
|
|
context 'when the gestionnaire has no notifications' do
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a procedure published was active' do
|
2018-05-16 17:21:12 +02:00
|
|
|
let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire2], libelle: 'procedure') }
|
2017-05-12 16:47:18 +02:00
|
|
|
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
expect_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
|
|
|
|
end
|
|
|
|
|
2017-07-19 12:23:53 +02:00
|
|
|
it { expect(gestionnaire2.last_week_overview[:procedure_overviews]).to match([procedure_overview]) }
|
2017-05-12 16:47:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a procedure not published was active with no notifications' do
|
2018-05-16 17:21:12 +02:00
|
|
|
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure') }
|
2017-05-12 16:47:18 +02:00
|
|
|
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
allow_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
2017-05-16 15:20:38 +02:00
|
|
|
|
2018-10-23 11:39:54 +02:00
|
|
|
describe "procedure_presentation_and_errors_for_procedure_id" do
|
|
|
|
let(:procedure_presentation_and_errors) { gestionnaire.procedure_presentation_and_errors_for_procedure_id(procedure_id) }
|
|
|
|
let(:procedure_presentation) { procedure_presentation_and_errors.first }
|
|
|
|
let(:errors) { procedure_presentation_and_errors.second }
|
2017-10-02 17:03:38 +02:00
|
|
|
|
2018-10-23 11:20:16 +02:00
|
|
|
context 'with explicit presentation' do
|
|
|
|
let(:procedure_id) { procedure.id }
|
|
|
|
let!(:pp) { ProcedurePresentation.create(assign_to: procedure_assign) }
|
|
|
|
|
|
|
|
it { expect(procedure_presentation).to eq(pp) }
|
2018-10-23 11:39:54 +02:00
|
|
|
it { expect(errors).to be_nil }
|
2018-10-23 11:20:16 +02:00
|
|
|
end
|
|
|
|
|
2018-10-23 11:48:25 +02:00
|
|
|
context 'with invalid presentation' do
|
|
|
|
let(:procedure_id) { procedure.id }
|
|
|
|
before do
|
|
|
|
pp = ProcedurePresentation.create(assign_to: procedure_assign, displayed_fields: [{ 'table' => 'invalid', 'column' => 'random' }])
|
|
|
|
pp.save(:validate => false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_presentation).not_to be_persisted }
|
|
|
|
it { expect(errors).to be_present }
|
|
|
|
end
|
|
|
|
|
2018-10-23 11:20:16 +02:00
|
|
|
context 'with default presentation' do
|
|
|
|
let(:procedure_id) { procedure_2.id }
|
|
|
|
|
2018-10-23 11:21:32 +02:00
|
|
|
it { expect(procedure_presentation).not_to be_persisted }
|
2018-10-23 11:39:54 +02:00
|
|
|
it { expect(errors).to be_nil }
|
2018-10-23 11:20:16 +02:00
|
|
|
end
|
2017-10-02 17:03:38 +02:00
|
|
|
end
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
describe '#notifications_for_dossier' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
2017-10-05 16:10:00 +02:00
|
|
|
let(:gestionnaire) { dossier.follows.first.gestionnaire }
|
|
|
|
|
|
|
|
subject { gestionnaire.notifications_for_dossier(dossier) }
|
|
|
|
|
|
|
|
context 'when the gestionnaire has just followed the dossier' do
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
|
|
|
before { dossier.champs.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on private champs' do
|
|
|
|
before { dossier.champs_private.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: true, avis: false, messagerie: false }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on avis' do
|
|
|
|
before { create(:avis, dossier: dossier) }
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: true, messagerie: false }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'messagerie' do
|
|
|
|
context 'when there is a new commentaire' do
|
|
|
|
before { create(:commentaire, dossier: dossier, email: 'a@b.com') }
|
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a new commentaire issued by tps' do
|
2018-05-31 15:43:57 +02:00
|
|
|
before { create(:commentaire, dossier: dossier, email: CONTACT_EMAIL) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false }) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-17 15:20:10 +02:00
|
|
|
describe '#notifications_for_procedure' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
2017-10-05 16:10:00 +02:00
|
|
|
let(:gestionnaire) { dossier.follows.first.gestionnaire }
|
|
|
|
let(:procedure) { dossier.procedure }
|
|
|
|
let!(:gestionnaire_2) { create(:gestionnaire, procedures: [procedure]) }
|
|
|
|
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier_on_procedure_2) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
2017-10-05 16:10:00 +02:00
|
|
|
let!(:gestionnaire_on_procedure_2) { dossier_on_procedure_2.follows.first.gestionnaire }
|
|
|
|
|
|
|
|
before do
|
|
|
|
gestionnaire_2.followed_dossiers << dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { gestionnaire.notifications_for_procedure(procedure) }
|
|
|
|
|
|
|
|
context 'when the gestionnaire has just followed the dossier' do
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
|
|
|
before { dossier.champs.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
it { expect(gestionnaire_2.notifications_for_procedure(procedure)).to match([dossier.id]) }
|
|
|
|
it { expect(gestionnaire_on_procedure_2.notifications_for_procedure(procedure)).to match([]) }
|
|
|
|
|
|
|
|
context 'and there is a modification on private champs' do
|
|
|
|
before { dossier.champs_private.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire update it s public champs last seen' do
|
|
|
|
let(:follow) { gestionnaire.follows.find_by(dossier: dossier) }
|
|
|
|
|
2018-10-25 15:07:15 +02:00
|
|
|
before { follow.update_attribute('demande_seen_at', Time.zone.now) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
it { expect(gestionnaire_2.notifications_for_procedure(procedure)).to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs on a followed dossier from another procedure' do
|
|
|
|
before { dossier_on_procedure_2.champs.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on private champs' do
|
|
|
|
before { dossier.champs_private.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a modification on avis' do
|
|
|
|
before { create(:avis, dossier: dossier) }
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the messagerie' do
|
|
|
|
context 'when there is a new commentaire' do
|
|
|
|
before { create(:commentaire, dossier: dossier, email: 'a@b.com') }
|
|
|
|
|
|
|
|
it { is_expected.to match([dossier.id]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a new commentaire issued by tps' do
|
2018-05-31 15:43:57 +02:00
|
|
|
before { create(:commentaire, dossier: dossier, email: CONTACT_EMAIL) }
|
2017-10-05 16:10:00 +02:00
|
|
|
|
|
|
|
it { is_expected.to match([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#notifications_per_procedure' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
2017-10-05 16:10:00 +02:00
|
|
|
let(:gestionnaire) { dossier.follows.first.gestionnaire }
|
|
|
|
let(:procedure) { dossier.procedure }
|
|
|
|
|
|
|
|
subject { gestionnaire.notifications_per_procedure }
|
|
|
|
|
|
|
|
context 'when there is a modification on public champs' do
|
|
|
|
before { dossier.champs.first.update_attribute('value', 'toto') }
|
|
|
|
|
|
|
|
it { is_expected.to match({ procedure.id => 1 }) }
|
|
|
|
end
|
|
|
|
end
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
describe '#mark_tab_as_seen' do
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
2017-10-24 11:41:22 +02:00
|
|
|
let(:gestionnaire) { dossier.follows.first.gestionnaire }
|
2018-10-25 15:17:33 +02:00
|
|
|
let(:freeze_date) { Time.zone.parse('12/12/2012') }
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
context 'when demande is acknowledged' do
|
|
|
|
let(:follow) { gestionnaire.follows.find_by(dossier: dossier) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Timecop.freeze(freeze_date)
|
|
|
|
gestionnaire.mark_tab_as_seen(dossier, :demande)
|
|
|
|
end
|
2017-11-29 16:07:39 +01:00
|
|
|
after { Timecop.return }
|
2017-10-24 11:41:22 +02:00
|
|
|
|
|
|
|
it { expect(follow.demande_seen_at).to eq(freeze_date) }
|
|
|
|
end
|
|
|
|
end
|
2018-12-03 13:51:45 +01:00
|
|
|
|
2019-01-10 10:41:03 +01:00
|
|
|
describe '#young_login_token?' do
|
|
|
|
let!(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
|
|
|
|
context 'when there is a token' do
|
2019-02-18 17:05:30 +01:00
|
|
|
let!(:good_token) { gestionnaire.create_trusted_device_token }
|
2019-01-10 10:41:03 +01:00
|
|
|
|
|
|
|
context 'when the token has just been created' do
|
|
|
|
it { expect(gestionnaire.young_login_token?).to be true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the token is a bit old' do
|
2019-02-04 11:04:55 +01:00
|
|
|
before { gestionnaire.trusted_device_tokens.first.update(created_at: (TrustedDeviceToken::LOGIN_TOKEN_YOUTH + 1.minute).ago) }
|
2019-01-10 10:41:03 +01:00
|
|
|
it { expect(gestionnaire.young_login_token?).to be false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no token' do
|
2019-02-04 11:04:55 +01:00
|
|
|
it { expect(gestionnaire.young_login_token?).to be_falsey }
|
2019-01-10 10:41:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 17:59:33 +01:00
|
|
|
describe '#email_notification_data' do
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let(:procedure_to_assign) { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:assign_to, gestionnaire: gestionnaire, procedure: procedure_to_assign, email_notifications_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier in construction exists' do
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure_to_assign, state: Dossier.states.fetch(:en_construction)) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(gestionnaire.email_notification_data).to eq([
|
|
|
|
{
|
|
|
|
nb_en_construction: 1,
|
|
|
|
nb_notification: 0,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a notification exists' do
|
|
|
|
before do
|
2019-04-17 15:20:10 +02:00
|
|
|
allow(gestionnaire).to receive(:notifications_for_procedure)
|
|
|
|
.with(procedure_to_assign, :all)
|
2019-03-13 17:59:33 +01:00
|
|
|
.and_return([1, 2, 3])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(gestionnaire.email_notification_data).to eq([
|
|
|
|
{
|
|
|
|
nb_en_construction: 0,
|
|
|
|
nb_notification: 3,
|
|
|
|
procedure_id: procedure_to_assign.id,
|
|
|
|
procedure_libelle: procedure_to_assign.libelle
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'otherwise' do
|
|
|
|
it { expect(gestionnaire.email_notification_data).to eq([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-03 13:51:45 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def assign(procedure_to_assign)
|
|
|
|
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_to_assign
|
|
|
|
end
|
2015-09-22 10:15:12 +02:00
|
|
|
end
|