2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-04-21 11:40:23 +02:00
|
|
|
RSpec.describe Cron::StalledDeclarativeProceduresJob, type: :job do
|
|
|
|
describe "perform" do
|
|
|
|
let(:state) { nil }
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_instructeur, declarative_with_state: state) }
|
2023-06-13 16:23:40 +02:00
|
|
|
let!(:brouillon) { create(:dossier, :brouillon, procedure:) }
|
|
|
|
let!(:en_construction) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:) }
|
|
|
|
let!(:en_construction_triggered) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:, declarative_triggered_at: 1.minute.ago) }
|
|
|
|
let!(:en_instruction) { create(:dossier, :en_instruction, :with_individual, procedure:) }
|
2023-04-21 11:40:23 +02:00
|
|
|
|
|
|
|
subject(:perform_job) do
|
2023-06-13 16:23:40 +02:00
|
|
|
described_class.perform_now
|
2023-04-21 11:40:23 +02:00
|
|
|
end
|
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
context "declarative en instruction" do
|
|
|
|
let(:state) { Dossier.states.fetch(:en_instruction) }
|
2023-04-21 11:40:23 +02:00
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
it {
|
|
|
|
perform_job
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(brouillon)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).to have_been_enqueued.with(en_construction)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(en_construction_triggered)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(en_instruction)
|
|
|
|
}
|
|
|
|
end
|
2023-04-21 11:40:23 +02:00
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
context "declarative accepte" do
|
|
|
|
let(:state) { Dossier.states.fetch(:accepte) }
|
2023-04-21 11:40:23 +02:00
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
it {
|
|
|
|
perform_job
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(brouillon)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).to have_been_enqueued.with(en_construction)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(en_construction_triggered)
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued.with(en_instruction)
|
|
|
|
}
|
2023-04-21 11:40:23 +02:00
|
|
|
end
|
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
context "not declarative" do
|
|
|
|
let(:state) { nil }
|
2023-04-21 11:40:23 +02:00
|
|
|
|
2023-06-13 16:23:40 +02:00
|
|
|
it {
|
|
|
|
perform_job
|
|
|
|
expect(ProcessStalledDeclarativeDossierJob).not_to have_been_enqueued
|
|
|
|
}
|
2023-04-21 11:40:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|