Merge pull request #789 from sgmap/poc_declaratoire

Poc declaratoire
This commit is contained in:
Mathieu Magnin 2017-10-06 17:56:10 +02:00 committed by GitHub
commit ef671efb88
7 changed files with 66 additions and 5 deletions

View file

@ -68,6 +68,7 @@ Afin de générer la BDD de l'application, il est nécessaire d'éxécuter les c
AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later
WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id)
## Exécution des tests (RSpec)

View file

@ -0,0 +1,10 @@
class AutoReceiveDossiersForProcedureJob < ApplicationJob
queue_as :cron
def perform(procedure_id)
procedure = Procedure.find_by(id: procedure_id)
if procedure
procedure.dossiers.state_nouveaux.update_all(state: "received", received_at: Time.now)
end
end
end

View file

@ -1,4 +1,5 @@
class DossiersSerializer < ActiveModel::Serializer
attributes :id,
:updated_at
:updated_at,
:initiated_at
end

View file

@ -13,7 +13,8 @@
{
"id": 2,
"nom_projet": "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger",
"updated_at": "2008-09-01T08:05:00.000Z"
"updated_at": "2008-09-01T08:05:00.000Z",
"initiated_at": "2008-09-02T08:05:00.000Z"
}
],
"pagination": {

View file

@ -25,7 +25,7 @@ describe API::V1::DossiersController do
context 'when procedure is found and belongs to admin' do
let(:procedure_id) { procedure.id }
let(:date_creation) { Time.utc(2008, 9, 1, 10, 5, 0) }
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') } }
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :initiated, procedure: procedure) } }
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
it 'return REST code 200', :show_in_doc do
@ -53,7 +53,8 @@ describe API::V1::DossiersController do
subject { super().first }
it { expect(subject[:id]).to eq(dossier.id) }
it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000Z") }
it { expect(subject.keys.size).to eq(2) }
it { expect(subject[:initiated_at]).to eq("2008-09-01T10:06:00.000Z") }
it { expect(subject.keys.size).to eq(3) }
end
end

View file

@ -73,7 +73,20 @@ FactoryGirl.define do
end
trait :initiated do
state 'initiated'
after(:create) do |dossier, _evaluator|
dossier.state = 'initiated'
dossier.initiated_at = dossier.created_at + 1.minute
dossier.save!
end
end
trait :received do
after(:create) do |dossier, _evaluator|
dossier.state = 'received'
dossier.initiated_at = dossier.created_at + 1.minute
dossier.created_at = dossier.created_at + 2.minute
dossier.save!
end
end
end
end

View file

@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
describe "perform" do
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }
before { Timecop.freeze(date) }
subject { AutoReceiveDossiersForProcedureJob.new.perform(procedure_id) }
context "with some dossiers" do
let(:nouveau_dossier1) { create(:dossier, :initiated) }
let(:nouveau_dossier2) { create(:dossier, :initiated, procedure: nouveau_dossier1.procedure) }
let(:dossier_recu) { create(:dossier, :received, procedure: nouveau_dossier2.procedure) }
let(:dossier_draft) { create(:dossier, procedure: dossier_recu.procedure) }
let(:procedure_id) { dossier_draft.procedure_id }
it do
subject
expect(nouveau_dossier1.reload.received?).to be true
expect(nouveau_dossier1.reload.received_at).to eq(date)
expect(nouveau_dossier2.reload.received?).to be true
expect(nouveau_dossier2.reload.received_at).to eq(date)
expect(dossier_recu.reload.received?).to be true
expect(dossier_recu.reload.received_at).to eq(date)
expect(dossier_draft.reload.draft?).to be true
expect(dossier_draft.reload.received_at).to eq(nil)
end
end
end
end