fix(procedure): auto_archive_on must be in future
This commit is contained in:
parent
a69cf8b7d2
commit
ec244f1a94
5 changed files with 43 additions and 5 deletions
|
@ -353,6 +353,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
validates :api_entreprise_token, jwt_token: true, allow_blank: true
|
||||
validates :api_particulier_token, format: { with: /\A[A-Za-z0-9\-_=.]{15,}\z/ }, allow_blank: true
|
||||
validate :validate_auto_archive_on_in_the_future, if: :will_save_change_to_auto_archive_on?
|
||||
validates :routing_criteria_name, presence: true, allow_blank: false
|
||||
|
||||
before_save :update_juridique_required
|
||||
|
@ -963,4 +964,13 @@ class Procedure < ApplicationRecord
|
|||
super
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_auto_archive_on_in_the_future
|
||||
return if auto_archive_on.nil?
|
||||
return if auto_archive_on.future?
|
||||
|
||||
errors.add(:auto_archive_on, 'doit être dans le futur')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,6 @@ en:
|
|||
declarative_with_state/en_instruction: Instruction
|
||||
declarative_with_state/accepte: Accepted
|
||||
api_particulier_token: Token API Particulier
|
||||
lien_dpo: DPO contact
|
||||
routing_criteria_name: Routing criteria name
|
||||
initiated_mail: File sorted for processing notification email
|
||||
received_mail: File submitted notification email
|
||||
|
@ -37,6 +36,7 @@ en:
|
|||
without_continuation_mail: File sorted with no further action notification email
|
||||
attestation_template: Attestation template
|
||||
draft_revision: The form
|
||||
auto_archive_on: Application deadline
|
||||
procedure_export:
|
||||
id: Id
|
||||
libelle: Libelle
|
||||
|
|
|
@ -34,7 +34,6 @@ fr:
|
|||
declarative_with_state/en_instruction: En instruction
|
||||
declarative_with_state/accepte: Accepté
|
||||
api_particulier_token: Jeton API Particulier
|
||||
lien_dpo: Contact du DPO
|
||||
routing_criteria_name: Nomination du routage
|
||||
initiated_mail: L’email de notification de passage de dossier en instruction
|
||||
received_mail: L’email de notification de dépot de dossier
|
||||
|
@ -43,6 +42,7 @@ fr:
|
|||
without_continuation_mail: L’email de notification de classement sans suite de dossier
|
||||
attestation_template: Le modèle d’attestation
|
||||
draft_revision: Le formulaire
|
||||
auto_archive_on: Date limite de dépôt des dossiers
|
||||
procedure_export:
|
||||
id: Id
|
||||
libelle: Libelle
|
||||
|
@ -61,3 +61,5 @@ fr:
|
|||
format: 'L’annotation privée %{message}'
|
||||
lien_dpo:
|
||||
invalid_uri_or_email: "Veuillez saisir un mail ou un lien"
|
||||
auto_archive_on:
|
||||
future: doit être dans le futur
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
|
||||
let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) }
|
||||
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) }
|
||||
let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur, auto_archive_on: Time.zone.today) }
|
||||
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur) }
|
||||
let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur) }
|
||||
let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now.to_date) }
|
||||
let!(:job) { Cron::AutoArchiveProcedureJob.new }
|
||||
|
||||
before do
|
||||
procedure_hier.auto_archive_on = 1.day.ago.to_date
|
||||
procedure_hier.save!(validate: false)
|
||||
procedure_aujourdhui.auto_archive_on = Date.current
|
||||
procedure_aujourdhui.save!(validate: false)
|
||||
end
|
||||
|
||||
subject { job.perform }
|
||||
|
||||
context "when procedures have no auto_archive_on" do
|
||||
|
@ -66,9 +73,12 @@ RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
|
|||
end
|
||||
|
||||
context 'when an error occurs' do
|
||||
let!(:buggy_procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) }
|
||||
let!(:buggy_procedure) { create(:procedure, :published, :with_instructeur) }
|
||||
|
||||
before do
|
||||
buggy_procedure.auto_archive_on = 1.day.ago.to_date
|
||||
buggy_procedure.save!(validate: false)
|
||||
|
||||
error = StandardError.new('nop')
|
||||
expect(buggy_procedure).to receive(:close!).and_raise(error)
|
||||
expect(job).to receive(:procedures_to_close).and_return([buggy_procedure, procedure_hier])
|
||||
|
|
|
@ -385,6 +385,22 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with auto archive' do
|
||||
let(:procedure) { create(:procedure, auto_archive_on: 1.day.from_now) }
|
||||
|
||||
it { expect(procedure).to be_valid }
|
||||
|
||||
context 'when auto_archive_on is in the past' do
|
||||
it 'validates only when attribute is changed' do
|
||||
procedure.auto_archive_on = 1.day.ago
|
||||
expect(procedure).not_to be_valid
|
||||
|
||||
procedure.save!(validate: false)
|
||||
expect(procedure).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'opendata' do
|
||||
|
|
Loading…
Reference in a new issue