|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -describe Dossier, type: :model do |
| 3 | +describe Dossier, :oaken, type: :model do |
4 | 4 | include ActionView::Helpers::SanitizeHelper |
5 | 5 |
|
6 | 6 | let(:user) { create(:user) } |
|
22 | 22 |
|
23 | 23 | subject { Dossier.all } |
24 | 24 |
|
25 | | - it { is_expected.to match_array([dossier]) } |
| 25 | + it { is_expected.to include(dossier) } |
26 | 26 | end |
27 | 27 |
|
28 | 28 | describe '.without_followers' do |
29 | 29 | let!(:dossier_with_follower) { create(:dossier, :followed, :with_entreprise, user: user) } |
30 | 30 | let!(:dossier_without_follower) { create(:dossier, :with_entreprise, user: user) } |
31 | 31 |
|
32 | | - it { expect(Dossier.without_followers.to_a).to eq([dossier_without_follower]) } |
| 32 | + it do |
| 33 | + expect(Dossier.without_followers).to include(dossier_without_follower) |
| 34 | + expect(Dossier.without_followers).not_to include(dossier_with_follower) |
| 35 | + end |
33 | 36 | end |
34 | 37 |
|
35 | 38 | describe 'brouillons_recently_updated' do |
36 | 39 | let!(:dossier_en_brouillon) { create(:dossier) } |
37 | 40 | let!(:dossier_en_brouillon_2) { create(:dossier) } |
38 | 41 |
|
39 | | - it { expect(Dossier.brouillons_recently_updated).to eq([dossier_en_brouillon_2, dossier_en_brouillon]) } |
| 42 | + it 'returns brouillons most recently updated first' do |
| 43 | + recently_updated = Dossier.brouillons_recently_updated.to_a |
| 44 | + |
| 45 | + expect(recently_updated).to include(dossier_en_brouillon_2, dossier_en_brouillon) |
| 46 | + expect(recently_updated.index(dossier_en_brouillon_2)).to be < recently_updated.index(dossier_en_brouillon) |
| 47 | + end |
40 | 48 | end |
41 | 49 |
|
42 | 50 | describe 'by_statut' do |
|
137 | 145 | end |
138 | 146 |
|
139 | 147 | it 'returns only visible brouillon dossiers whose expiration notice period has passed' do |
140 | | - expect(Dossier.brouillon_expired_after_notice_grace).to contain_exactly(dossier_brouillon_expired_and_noticed_long_time_ago) |
| 148 | + expect(Dossier.brouillon_expired_after_notice_grace).to include(dossier_brouillon_expired_and_noticed_long_time_ago) |
| 149 | + expect(Dossier.brouillon_expired_after_notice_grace).not_to include( |
| 150 | + dossier_brouillon_not_expired, |
| 151 | + dossier_brouillon_expired_but_noticed_recently, |
| 152 | + dossier_brouillon_expired_but_not_noticed_yet, |
| 153 | + dossier_instruction_expired, |
| 154 | + dossier_hidden |
| 155 | + ) |
141 | 156 | end |
142 | 157 | end |
143 | 158 |
|
|
160 | 175 |
|
161 | 176 | it 'returns only expired brouillons structurally outside the notice path' do |
162 | 177 | expect(Dossier.brouillon_expired_without_notice) |
163 | | - .to contain_exactly(expired_on_closed, expired_on_draft, expired_preview) |
| 178 | + .to include(expired_on_closed, expired_on_draft, expired_preview) |
| 179 | + expect(Dossier.brouillon_expired_without_notice) |
| 180 | + .not_to include(expired_on_published, not_expired_on_closed, hidden_on_closed, en_construction_on_closed) |
164 | 181 | end |
165 | 182 | end |
166 | 183 | end |
|
1535 | 1552 | end |
1536 | 1553 |
|
1537 | 1554 | describe '#accepter!' do |
1538 | | - let(:procedure) { create(:procedure, :for_individual, :published) } |
1539 | | - let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:) } |
| 1555 | + let(:procedure) { procedures.demo } |
| 1556 | + let(:dossier) { dossiers.en_instruction } |
1540 | 1557 | let(:last_operation) { dossier.dossier_operation_logs.last } |
1541 | 1558 | let(:operation_serialized) { last_operation.data } |
1542 | | - let!(:instructeur) { create(:instructeur) } |
| 1559 | + let(:instructeur) { instructeurs.demo } |
1543 | 1560 | let!(:now) { Time.zone.parse('01/01/2100') } |
1544 | 1561 | let!(:attestation_template) { create(:attestation_template, procedure:, kind: :acceptation, state: :published) } |
1545 | 1562 |
|
|
1673 | 1690 | end |
1674 | 1691 |
|
1675 | 1692 | describe '#passer_en_instruction!' do |
1676 | | - let(:dossier) { create(:dossier, :en_construction) } |
| 1693 | + let(:dossier) { dossiers.en_construction } |
1677 | 1694 | let(:last_operation) { dossier.dossier_operation_logs.last } |
1678 | 1695 | let(:operation_serialized) { last_operation.data } |
1679 | | - let(:instructeur) { create(:instructeur) } |
| 1696 | + let(:instructeur) { instructeurs.demo } |
1680 | 1697 | let!(:correction) { create(:dossier_correction, dossier:) } # correction has a commentaire |
1681 | 1698 |
|
1682 | 1699 | subject(:passer_en_instruction) { dossier.passer_en_instruction!(instructeur: instructeur) } |
|
2317 | 2334 | end |
2318 | 2335 |
|
2319 | 2336 | describe '#repasser_en_instruction!' do |
2320 | | - let(:dossier) { create(:dossier, :refuse, :with_attestation_acceptation, :with_justificatif, archived: true, termine_close_to_expiration_notice_sent_at: Time.zone.now, sva_svr_decision_on: 1.day.ago) } |
2321 | | - let!(:instructeur) { create(:instructeur) } |
| 2337 | + let(:dossier) { dossiers.refuse } |
| 2338 | + let(:instructeur) { instructeurs.demo } |
2322 | 2339 | let(:last_operation) { dossier.dossier_operation_logs.last } |
2323 | 2340 |
|
2324 | 2341 | before do |
2325 | 2342 | freeze_time |
| 2343 | + create(:attestation_template, procedure: dossier.procedure, state: :published) |
| 2344 | + AttestationPdfGenerationJob.perform_now(dossier) |
| 2345 | + dossier.justificatif_motivation.attach( |
| 2346 | + io: StringIO.new('Hello World'), |
| 2347 | + filename: 'hello.txt', |
| 2348 | + # we don't want to run virus scanner on this file |
| 2349 | + metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } |
| 2350 | + ) |
| 2351 | + dossier.update!(archived: true, termine_close_to_expiration_notice_sent_at: Time.zone.now, sva_svr_decision_on: 1.day.ago) |
2326 | 2352 | allow(NotificationMailer).to receive(:send_repasser_en_instruction_notification).and_return(double(deliver_later: true)) |
2327 | 2353 | dossier.repasser_en_instruction!(instructeur: instructeur) |
2328 | 2354 | dossier.reload |
|
2483 | 2509 | end |
2484 | 2510 |
|
2485 | 2511 | it do |
2486 | | - expect(Dossier.en_brouillon_expired_to_delete.count).to eq(2) |
2487 | | - expect(Dossier.en_construction_expired_to_delete.count).to eq(2) |
| 2512 | + expect(Dossier.en_brouillon_expired_to_delete.where(user:).count).to eq(2) |
| 2513 | + expect(Dossier.en_construction_expired_to_delete.where(user:).count).to eq(2) |
2488 | 2514 | end |
2489 | 2515 | end |
2490 | 2516 |
|
|
2552 | 2578 | let(:dossiers) { Dossier.with_notifiable_procedure(notify_on_closed: notify_on_closed) } |
2553 | 2579 |
|
2554 | 2580 | it 'should find dossiers with notifiable procedure' do |
2555 | | - expect(dossiers).to match_array([dossier_on_published_procedure, dossier_on_unpublished_procedure]) |
| 2581 | + expect(dossiers).to include(dossier_on_published_procedure, dossier_on_unpublished_procedure) |
| 2582 | + expect(dossiers).not_to include(dossier_on_test_procedure, dossier_on_closed_procedure) |
2556 | 2583 | end |
2557 | 2584 |
|
2558 | 2585 | context 'when notify on closed is true' do |
2559 | 2586 | let(:notify_on_closed) { true } |
2560 | 2587 |
|
2561 | 2588 | it 'should find dossiers with notifiable procedure' do |
2562 | | - expect(dossiers).to match_array([dossier_on_published_procedure, dossier_on_closed_procedure, dossier_on_unpublished_procedure]) |
| 2589 | + expect(dossiers).to include(dossier_on_published_procedure, dossier_on_closed_procedure, dossier_on_unpublished_procedure) |
| 2590 | + expect(dossiers).not_to include(dossier_on_test_procedure) |
2563 | 2591 | end |
2564 | 2592 | end |
2565 | 2593 | end |
|
2815 | 2843 |
|
2816 | 2844 | describe '#archivable_in_month' do |
2817 | 2845 | let(:dossier_accepte_at) { DateTime.new(2022, 3, 31, 12, 0) } |
2818 | | - before do |
2819 | | - travel_to(dossier_accepte_at) do |
2820 | | - dossier = create(:dossier, :accepte) |
2821 | | - end |
2822 | | - end |
| 2846 | + let!(:dossier) { travel_to(dossier_accepte_at) { create(:dossier, :accepte) } } |
2823 | 2847 |
|
2824 | 2848 | context 'given a date' do |
2825 | 2849 | let(:archive_date) { Date.new(2022, 3, 1) } |
2826 | 2850 | it 'includes a dossier processed_at at last day of month' do |
2827 | | - expect(Dossier.archivable_in_month(archive_date).count).to eq(1) |
| 2851 | + expect(Dossier.archivable_in_month(archive_date)).to include(dossier) |
2828 | 2852 | end |
2829 | 2853 | end |
2830 | 2854 |
|
2831 | 2855 | context 'given a datetime' do |
2832 | 2856 | let(:archive_date) { DateTime.new(2022, 3, 1, 12, 0) } |
2833 | 2857 | it 'includes a dossier processed_at at last day of month' do |
2834 | | - expect(Dossier.archivable_in_month(archive_date).count).to eq(1) |
| 2858 | + expect(Dossier.archivable_in_month(archive_date)).to include(dossier) |
2835 | 2859 | end |
2836 | 2860 | end |
2837 | 2861 |
|
2838 | 2862 | context 'with a dossier hidden by administration' do |
2839 | | - before do |
| 2863 | + let!(:hidden_dossier) do |
2840 | 2864 | travel_to(dossier_accepte_at) do |
2841 | 2865 | create(:dossier, :accepte, :hidden_by_administration) |
2842 | 2866 | end |
2843 | 2867 | end |
2844 | 2868 |
|
2845 | 2869 | it 'excludes hidden dossiers' do |
2846 | | - expect(Dossier.archivable_in_month(Date.new(2022, 3, 1)).count).to eq(1) |
| 2870 | + expect(Dossier.archivable_in_month(Date.new(2022, 3, 1))).to include(dossier) |
| 2871 | + expect(Dossier.archivable_in_month(Date.new(2022, 3, 1))).not_to include(hidden_dossier) |
2847 | 2872 | end |
2848 | 2873 | end |
2849 | 2874 | end |
|
3012 | 3037 |
|
3013 | 3038 | subject { Dossier.never_touched_brouillon_expired } |
3014 | 3039 |
|
3015 | | - it { is_expected.to contain_exactly(dossier) } |
| 3040 | + it do |
| 3041 | + is_expected.to include(dossier) |
| 3042 | + is_expected.not_to include(dossier_2, dossier_with_champ_updated, dossier_en_construction) |
| 3043 | + end |
3016 | 3044 |
|
3017 | 3045 | context 'when the dossier has been cloned' do |
3018 | 3046 | let!(:cloned_dossier) { travel_to(3.weeks.ago) { dossier.clone } } |
3019 | 3047 | let!(:cloned_dossier_2) { travel_to(3.weeks.ago) { dossier_with_champ_updated.clone } } |
3020 | 3048 |
|
3021 | | - it { is_expected.to contain_exactly(dossier) } |
| 3049 | + it do |
| 3050 | + is_expected.to include(dossier) |
| 3051 | + is_expected.not_to include(cloned_dossier, cloned_dossier_2) |
| 3052 | + end |
3022 | 3053 | end |
3023 | 3054 |
|
3024 | 3055 | context 'when the dossier has an etablissement' do |
|
0 commit comments