[#1946] Set en_instruction_at for factorybot-created dossiers

This commit is contained in:
Frederic Merizen 2018-08-31 12:29:11 +02:00
parent e00aa4a250
commit 5e16b5d80e
2 changed files with 15 additions and 14 deletions

View file

@ -80,7 +80,7 @@ FactoryBot.define do
trait :en_construction do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:en_construction)
dossier.en_construction_at = dossier.created_at + 1.minute
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.save!
end
end
@ -88,8 +88,8 @@ FactoryBot.define do
trait :en_instruction do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:en_instruction)
dossier.en_construction_at = dossier.created_at + 1.minute
dossier.created_at = dossier.created_at + 2.minutes
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.save!
end
end
@ -97,9 +97,9 @@ FactoryBot.define do
trait :accepte do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:accepte)
dossier.processed_at ||= dossier.created_at + 1.minute
dossier.en_construction_at ||= dossier.created_at + 2.minutes
dossier.created_at ||= dossier.created_at + 3.minutes
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.processed_at ||= dossier.en_instruction_at + 1.minute
dossier.save!
end
end
@ -107,9 +107,9 @@ FactoryBot.define do
trait :refuse do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:refuse)
dossier.processed_at = dossier.created_at + 1.minute
dossier.en_construction_at = dossier.created_at + 2.minutes
dossier.created_at = dossier.created_at + 3.minutes
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.processed_at ||= dossier.en_instruction_at + 1.minute
dossier.save!
end
end
@ -117,9 +117,9 @@ FactoryBot.define do
trait :sans_suite do
after(:create) do |dossier, _evaluator|
dossier.state = Dossier.states.fetch(:sans_suite)
dossier.processed_at = dossier.created_at + 1.minute
dossier.en_construction_at = dossier.created_at + 2.minutes
dossier.created_at = dossier.created_at + 3.minutes
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.processed_at ||= dossier.en_instruction_at + 1.minute
dossier.save!
end
end

View file

@ -3,6 +3,7 @@ require 'rails_helper'
RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
describe "perform" do
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }
let(:instruction_date) { date + 120 }
before do
Timecop.freeze(date)
@ -28,7 +29,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
it { expect(nouveau_dossier2.reload.en_instruction_at).to eq(date) }
it { expect(dossier_recu.reload.en_instruction?).to be true }
it { expect(dossier_recu.reload.en_instruction_at).to eq(date) }
it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) }
it { expect(dossier_brouillon.reload.brouillon?).to be true }
it { expect(dossier_brouillon.reload.en_instruction_at).to eq(nil) }
@ -46,7 +47,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
it { expect(nouveau_dossier2.reload.processed_at).to eq(date) }
it { expect(dossier_recu.reload.en_instruction?).to be true }
it { expect(dossier_recu.reload.en_instruction_at).to eq(date) }
it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) }
it { expect(dossier_recu.reload.processed_at).to eq(nil) }
it { expect(dossier_brouillon.reload.brouillon?).to be true }