Merge pull request #3526 from Keirua/feat/2631-upload-avis
[#2631] implementation du systeme de PJ de motivation
This commit is contained in:
commit
3435349b66
18 changed files with 186 additions and 47 deletions
|
@ -43,4 +43,12 @@
|
||||||
padding-left: $default-spacer * 1.5;
|
padding-left: $default-spacer * 1.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.optional-justificatif {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[data-direct-upload-url] {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,16 +93,17 @@ module Gestionnaires
|
||||||
|
|
||||||
def terminer
|
def terminer
|
||||||
motivation = params[:dossier] && params[:dossier][:motivation]
|
motivation = params[:dossier] && params[:dossier][:motivation]
|
||||||
|
justificatif = params[:dossier] && params[:dossier][:justificatif_motivation]
|
||||||
|
|
||||||
case params[:process_action]
|
case params[:process_action]
|
||||||
when "refuser"
|
when "refuser"
|
||||||
dossier.refuser!(current_gestionnaire, motivation)
|
dossier.refuser!(current_gestionnaire, motivation, justificatif)
|
||||||
flash.notice = "Dossier considéré comme refusé."
|
flash.notice = "Dossier considéré comme refusé."
|
||||||
when "classer_sans_suite"
|
when "classer_sans_suite"
|
||||||
dossier.classer_sans_suite!(current_gestionnaire, motivation)
|
dossier.classer_sans_suite!(current_gestionnaire, motivation, justificatif)
|
||||||
flash.notice = "Dossier considéré comme sans suite."
|
flash.notice = "Dossier considéré comme sans suite."
|
||||||
when "accepter"
|
when "accepter"
|
||||||
dossier.accepter!(current_gestionnaire, motivation)
|
dossier.accepter!(current_gestionnaire, motivation, justificatif)
|
||||||
flash.notice = "Dossier traité avec succès."
|
flash.notice = "Dossier traité avec succès."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,3 +11,8 @@ export function motivationCancel() {
|
||||||
document.querySelectorAll('.motivation').forEach(hide);
|
document.querySelectorAll('.motivation').forEach(hide);
|
||||||
show(document.querySelector('.dropdown-items'));
|
show(document.querySelector('.dropdown-items'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showImportJustificatif(name) {
|
||||||
|
show(document.querySelector('#justificatif_motivation_import_' + name));
|
||||||
|
hide(document.querySelector('#justificatif_motivation_suggest_' + name));
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,11 @@ import '../new_design/champs/repetition';
|
||||||
|
|
||||||
import { toggleCondidentielExplanation } from '../new_design/avis';
|
import { toggleCondidentielExplanation } from '../new_design/avis';
|
||||||
import { scrollMessagerie } from '../new_design/messagerie';
|
import { scrollMessagerie } from '../new_design/messagerie';
|
||||||
import { showMotivation, motivationCancel } from '../new_design/state-button';
|
import {
|
||||||
|
showMotivation,
|
||||||
|
motivationCancel,
|
||||||
|
showImportJustificatif
|
||||||
|
} from '../new_design/state-button';
|
||||||
import { toggleChart } from '../new_design/toggle-chart';
|
import { toggleChart } from '../new_design/toggle-chart';
|
||||||
import { replaceSemicolonByComma } from '../new_design/avis';
|
import { replaceSemicolonByComma } from '../new_design/avis';
|
||||||
|
|
||||||
|
@ -40,6 +44,7 @@ const DS = {
|
||||||
scrollMessagerie,
|
scrollMessagerie,
|
||||||
showMotivation,
|
showMotivation,
|
||||||
motivationCancel,
|
motivationCancel,
|
||||||
|
showImportJustificatif,
|
||||||
toggleChart,
|
toggleChart,
|
||||||
replaceSemicolonByComma
|
replaceSemicolonByComma
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,8 +10,12 @@ addEventListener(INITIALIZE_EVENT, ({ target, detail: { id, file } }) => {
|
||||||
ProgressBar.init(target, id, file);
|
ProgressBar.init(target, id, file);
|
||||||
});
|
});
|
||||||
|
|
||||||
addEventListener(START_EVENT, ({ detail: { id } }) => {
|
addEventListener(START_EVENT, ({ target, detail: { id } }) => {
|
||||||
ProgressBar.start(id);
|
ProgressBar.start(id);
|
||||||
|
const button = target.form.querySelector('button.primary');
|
||||||
|
if (button) {
|
||||||
|
delete button.dataset.confirm;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addEventListener(PROGRESS_EVENT, ({ detail: { id, progress } }) => {
|
addEventListener(PROGRESS_EVENT, ({ detail: { id, progress } }) => {
|
||||||
|
|
|
@ -59,7 +59,13 @@ module TagsSubstitutionConcern
|
||||||
{
|
{
|
||||||
libelle: 'lien attestation',
|
libelle: 'lien attestation',
|
||||||
description: '',
|
description: '',
|
||||||
lambda: -> (d) { external_link(attestation_dossier_url(d)) },
|
lambda: -> (d) {
|
||||||
|
links = [external_link(attestation_dossier_url(d))]
|
||||||
|
if d.justificatif_motivation.attached?
|
||||||
|
links.push external_link("Télécharger le justificatif", url_for_justificatif_motivation(d))
|
||||||
|
end
|
||||||
|
links.join "<br />\n"
|
||||||
|
},
|
||||||
available_for_states: [Dossier.states.fetch(:accepte)]
|
available_for_states: [Dossier.states.fetch(:accepte)]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -138,8 +144,14 @@ module TagsSubstitutionConcern
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_link(url)
|
def external_link(url, title = nil)
|
||||||
link_to(url, url, target: '_blank', rel: 'noopener')
|
link_to(title || url, url, target: '_blank', rel: 'noopener')
|
||||||
|
end
|
||||||
|
|
||||||
|
def url_for_justificatif_motivation(dossier)
|
||||||
|
if dossier.justificatif_motivation.attached?
|
||||||
|
Rails.application.routes.url_helpers.url_for(dossier.justificatif_motivation)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_tags
|
def dossier_tags
|
||||||
|
|
|
@ -20,6 +20,8 @@ class Dossier < ApplicationRecord
|
||||||
has_one :attestation, dependent: :destroy
|
has_one :attestation, dependent: :destroy
|
||||||
|
|
||||||
has_many :pieces_justificatives, dependent: :destroy
|
has_many :pieces_justificatives, dependent: :destroy
|
||||||
|
has_one_attached :justificatif_motivation
|
||||||
|
|
||||||
has_many :champs, -> { root.public_only.ordered }, dependent: :destroy
|
has_many :champs, -> { root.public_only.ordered }, dependent: :destroy
|
||||||
has_many :champs_private, -> { root.private_only.ordered }, class_name: 'Champ', dependent: :destroy
|
has_many :champs_private, -> { root.private_only.ordered }, class_name: 'Champ', dependent: :destroy
|
||||||
has_many :commentaires, dependent: :destroy
|
has_many :commentaires, dependent: :destroy
|
||||||
|
@ -296,10 +298,12 @@ class Dossier < ApplicationRecord
|
||||||
log_dossier_operation(gestionnaire, :repasser_en_construction)
|
log_dossier_operation(gestionnaire, :repasser_en_construction)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepter!(gestionnaire, motivation)
|
def accepter!(gestionnaire, motivation, justificatif = nil)
|
||||||
self.motivation = motivation
|
self.motivation = motivation
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
if justificatif
|
||||||
|
self.justificatif_motivation.attach(justificatif)
|
||||||
|
end
|
||||||
accepte!
|
accepte!
|
||||||
|
|
||||||
if attestation.nil?
|
if attestation.nil?
|
||||||
|
@ -330,20 +334,24 @@ class Dossier < ApplicationRecord
|
||||||
DeletedDossier.create_from_dossier(self)
|
DeletedDossier.create_from_dossier(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refuser!(gestionnaire, motivation)
|
def refuser!(gestionnaire, motivation, justificatif = nil)
|
||||||
self.motivation = motivation
|
self.motivation = motivation
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
if justificatif
|
||||||
|
self.justificatif_motivation.attach(justificatif)
|
||||||
|
end
|
||||||
refuse!
|
refuse!
|
||||||
|
|
||||||
NotificationMailer.send_refused_notification(self).deliver_later
|
NotificationMailer.send_refused_notification(self).deliver_later
|
||||||
log_dossier_operation(gestionnaire, :refuser)
|
log_dossier_operation(gestionnaire, :refuser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def classer_sans_suite!(gestionnaire, motivation)
|
def classer_sans_suite!(gestionnaire, motivation, justificatif = nil)
|
||||||
self.motivation = motivation
|
self.motivation = motivation
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
if justificatif
|
||||||
|
self.justificatif_motivation.attach(justificatif)
|
||||||
|
end
|
||||||
sans_suite!
|
sans_suite!
|
||||||
|
|
||||||
NotificationMailer.send_without_continuation_notification(self).deliver_later
|
NotificationMailer.send_without_continuation_notification(self).deliver_later
|
||||||
|
|
|
@ -22,6 +22,7 @@ class DossierSerializer < ActiveModel::Serializer
|
||||||
has_many :champs_private
|
has_many :champs_private
|
||||||
has_many :pieces_justificatives
|
has_many :pieces_justificatives
|
||||||
has_many :types_de_piece_justificative
|
has_many :types_de_piece_justificative
|
||||||
|
has_one :justificatif_motivation
|
||||||
|
|
||||||
has_many :champs, serializer: ChampSerializer
|
has_many :champs, serializer: ChampSerializer
|
||||||
|
|
||||||
|
@ -52,6 +53,12 @@ class DossierSerializer < ActiveModel::Serializer
|
||||||
PiecesJustificativesService.serialize_champs_as_pjs(object)
|
PiecesJustificativesService.serialize_champs_as_pjs(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def justificatif_motivation
|
||||||
|
if object.justificatif_motivation.attached?
|
||||||
|
Rails.application.routes.url_helpers.url_for(object.justificatif_motivation)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def types_de_piece_justificative
|
def types_de_piece_justificative
|
||||||
ActiveModelSerializers::SerializableResource.new(object.types_de_piece_justificative).serializable_hash +
|
ActiveModelSerializers::SerializableResource.new(object.types_de_piece_justificative).serializable_hash +
|
||||||
PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object)
|
PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object)
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
- if dossier.motivation.present?
|
- if dossier.motivation.present?
|
||||||
%h4 Motivation
|
%h4 Motivation
|
||||||
%p.dossier-motivation= dossier.motivation
|
%p.dossier-motivation= dossier.motivation
|
||||||
|
= render partial: 'new_user/dossiers/show/download_justificatif', locals: { dossier: dossier }
|
||||||
|
|
||||||
- if dossier.attestation.present?
|
- if dossier.attestation.present?
|
||||||
%h4 Attestation
|
%h4 Attestation
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
%li= unspecified_annotations_privee.libelle
|
%li= unspecified_annotations_privee.libelle
|
||||||
- else
|
- else
|
||||||
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: placeholder, required: true
|
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: placeholder, required: true
|
||||||
|
.optional-justificatif{ id: "justificatif_motivation_suggest_#{popup_class}", onclick: "DS.showImportJustificatif('#{popup_class}');" }
|
||||||
|
.button Ajouter un justificatif (optionnel)
|
||||||
|
.hidden{ id: "justificatif_motivation_import_#{popup_class}" }
|
||||||
|
= file_field :dossier, :justificatif_motivation, direct_upload: true
|
||||||
.text-right
|
.text-right
|
||||||
- if title == 'Accepter' && dossier.procedure.attestation_template&.activated?
|
- if title == 'Accepter' && dossier.procedure.attestation_template&.activated?
|
||||||
= link_to "Voir l'attestation", apercu_attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', rel: 'noopener', class: 'button', title: "Voir l'attestation qui sera envoyée au demandeur"
|
= link_to "Voir l'attestation", apercu_attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', rel: 'noopener', class: 'button', title: "Voir l'attestation qui sera envoyée au demandeur"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
- if dossier.present?
|
||||||
|
- justificatif = dossier.justificatif_motivation
|
||||||
|
- if dossier.justificatif_motivation.attached? and dossier.justificatif_motivation.virus_scanner.safe?
|
||||||
|
.action
|
||||||
|
= link_to (justificatif), target: '_blank', class: 'button primary' do
|
||||||
|
%span.icon.download
|
||||||
|
Télécharger le justificatif
|
|
@ -1,7 +1,7 @@
|
||||||
.container
|
.container
|
||||||
- if dossier.en_construction_at.present?
|
- if dossier.en_construction_at.present?
|
||||||
.card
|
.card
|
||||||
= render partial: "shared/dossiers/horodatage", locals: { dossier: dossier }
|
= render partial: "shared/dossiers/infos_generales", locals: { dossier: dossier }
|
||||||
|
|
||||||
.tab-title Identité du demandeur
|
.tab-title Identité du demandeur
|
||||||
.card
|
.card
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
%table.table.vertical.dossier-champs
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%th.libelle Déposé le :
|
|
||||||
%td= l(dossier.en_construction_at, format: '%d %B %Y')
|
|
11
app/views/shared/dossiers/_infos_generales.html.haml
Normal file
11
app/views/shared/dossiers/_infos_generales.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
%table.table.vertical.dossier-champs
|
||||||
|
%tbody
|
||||||
|
%tr
|
||||||
|
%th.libelle Déposé le :
|
||||||
|
%td= l(dossier.en_construction_at, format: '%d %B %Y')
|
||||||
|
- if dossier.justificatif_motivation.attached?
|
||||||
|
%tr
|
||||||
|
%th.libelle Justificatif :
|
||||||
|
%td
|
||||||
|
.action
|
||||||
|
= render partial: 'shared/piece_jointe/pj_link', locals: { object: dossier, pj: dossier.justificatif_motivation }
|
|
@ -50,12 +50,15 @@
|
||||||
%h3 Motif de l’acceptation
|
%h3 Motif de l’acceptation
|
||||||
%blockquote= dossier.motivation
|
%blockquote= dossier.motivation
|
||||||
|
|
||||||
|
= render partial: 'new_user/dossiers/show/download_justificatif', locals: { dossier: dossier }
|
||||||
|
|
||||||
- if dossier.attestation.present?
|
- if dossier.attestation.present?
|
||||||
.action
|
.action
|
||||||
= link_to attestation_dossier_path(dossier), target: '_blank', rel: 'noopener', class: 'button primary' do
|
= link_to attestation_dossier_path(dossier), target: '_blank', rel: 'noopener', class: 'button primary' do
|
||||||
%span.icon.download
|
%span.icon.download
|
||||||
Télécharger l’attestation
|
Télécharger l’attestation
|
||||||
|
|
||||||
|
|
||||||
- elsif dossier.refuse?
|
- elsif dossier.refuse?
|
||||||
.refuse
|
.refuse
|
||||||
%p.decision
|
%p.decision
|
||||||
|
@ -68,6 +71,7 @@
|
||||||
%h3 Motif du refus
|
%h3 Motif du refus
|
||||||
%blockquote= dossier.motivation
|
%blockquote= dossier.motivation
|
||||||
|
|
||||||
|
= render partial: 'new_user/dossiers/show/download_justificatif', locals: { dossier: @dossier }
|
||||||
.action
|
.action
|
||||||
= link_to 'Envoyer un message à l’administration', messagerie_dossier_url(dossier, anchor: 'new_commentaire'), class: 'button'
|
= link_to 'Envoyer un message à l’administration', messagerie_dossier_url(dossier, anchor: 'new_commentaire'), class: 'button'
|
||||||
|
|
||||||
|
@ -79,6 +83,8 @@
|
||||||
= succeed '.' do
|
= succeed '.' do
|
||||||
%strong sans suite
|
%strong sans suite
|
||||||
|
|
||||||
|
= render partial: 'new_user/dossiers/show/download_justificatif', locals: { dossier: @dossier }
|
||||||
|
|
||||||
- if dossier.motivation.present?
|
- if dossier.motivation.present?
|
||||||
%h3 Motif du classement sans suite
|
%h3 Motif du classement sans suite
|
||||||
%blockquote= dossier.motivation
|
%blockquote= dossier.motivation
|
||||||
|
|
|
@ -139,7 +139,7 @@ describe API::V1::DossiersController do
|
||||||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure, motivation: "Motivation") } }
|
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :en_construction, procedure: procedure, motivation: "Motivation") } }
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs] }
|
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :justificatif_motivation] }
|
||||||
subject { body[:dossier] }
|
subject { body[:dossier] }
|
||||||
|
|
||||||
it 'return REST code 200', :show_in_doc do
|
it 'return REST code 200', :show_in_doc do
|
||||||
|
|
|
@ -7,6 +7,7 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
let(:gestionnaires) { [gestionnaire] }
|
let(:gestionnaires) { [gestionnaire] }
|
||||||
let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) }
|
let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) }
|
||||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
let(:fake_justificatif) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
before { sign_in(gestionnaire) }
|
before { sign_in(gestionnaire) }
|
||||||
|
|
||||||
|
@ -141,6 +142,7 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
sign_in gestionnaire
|
sign_in gestionnaire
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'simple refusal' do
|
||||||
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
||||||
|
|
||||||
it 'change state to refuse' do
|
it 'change state to refuse' do
|
||||||
|
@ -148,6 +150,7 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
|
|
||||||
dossier.reload
|
dossier.reload
|
||||||
expect(dossier.state).to eq(Dossier.states.fetch(:refuse))
|
expect(dossier.state).to eq(Dossier.states.fetch(:refuse))
|
||||||
|
expect(dossier.justificatif_motivation).to_not be_attached
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'Notification email is sent' do
|
it 'Notification email is sent' do
|
||||||
|
@ -157,16 +160,29 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
|
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'refusal with a justificatif' do
|
||||||
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
||||||
|
|
||||||
|
it 'attachs a justificatif' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
dossier.reload
|
||||||
|
expect(dossier.state).to eq(Dossier.states.fetch(:refuse))
|
||||||
|
expect(dossier.justificatif_motivation).to be_attached
|
||||||
|
end
|
||||||
|
|
||||||
it { expect(subject.body).to include('.state-button') }
|
it { expect(subject.body).to include('.state-button') }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with classer_sans_suite" do
|
context "with classer_sans_suite" do
|
||||||
before do
|
before do
|
||||||
dossier.en_instruction!
|
dossier.en_instruction!
|
||||||
sign_in gestionnaire
|
sign_in gestionnaire
|
||||||
end
|
end
|
||||||
|
context 'without attachment' do
|
||||||
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
||||||
|
|
||||||
it 'change state to sans_suite' do
|
it 'change state to sans_suite' do
|
||||||
|
@ -174,6 +190,7 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
|
|
||||||
dossier.reload
|
dossier.reload
|
||||||
expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite))
|
expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite))
|
||||||
|
expect(dossier.justificatif_motivation).to_not be_attached
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'Notification email is sent' do
|
it 'Notification email is sent' do
|
||||||
|
@ -187,6 +204,21 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
it { expect(subject.body).to include('.state-button') }
|
it { expect(subject.body).to include('.state-button') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with attachment' do
|
||||||
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
||||||
|
|
||||||
|
it 'change state to sans_suite' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
dossier.reload
|
||||||
|
expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite))
|
||||||
|
expect(dossier.justificatif_motivation).to be_attached
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject.body).to include('.state-button') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with accepter" do
|
context "with accepter" do
|
||||||
before do
|
before do
|
||||||
dossier.en_instruction!
|
dossier.en_instruction!
|
||||||
|
@ -206,6 +238,7 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
|
|
||||||
dossier.reload
|
dossier.reload
|
||||||
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
||||||
|
expect(dossier.justificatif_motivation).to_not be_attached
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the dossier does not have any attestation' do
|
context 'when the dossier does not have any attestation' do
|
||||||
|
@ -261,6 +294,20 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
|
|
||||||
it { subject }
|
it { subject }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with an attachment' do
|
||||||
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
||||||
|
|
||||||
|
it 'change state to accepte' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
dossier.reload
|
||||||
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
||||||
|
expect(dossier.justificatif_motivation).to be_attached
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject.body).to include('.state-button') }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ describe MailTemplateConcern do
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let(:dossier2) { create(:dossier, procedure: procedure) }
|
let(:dossier2) { create(:dossier, procedure: procedure) }
|
||||||
let(:initiated_mail) { create(:initiated_mail, procedure: procedure) }
|
let(:initiated_mail) { create(:initiated_mail, procedure: procedure) }
|
||||||
|
let(:justificatif) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
shared_examples "can replace tokens in template" do
|
shared_examples "can replace tokens in template" do
|
||||||
describe 'with no token to replace' do
|
describe 'with no token to replace' do
|
||||||
|
@ -74,10 +75,21 @@ describe MailTemplateConcern do
|
||||||
mail.body = "--lien attestation--"
|
mail.body = "--lien attestation--"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "in closed mail" do
|
describe "in closed mail without justificatif" do
|
||||||
|
let(:mail) { create(:closed_mail, procedure: procedure) }
|
||||||
|
it { is_expected.to eq("<a target=\"_blank\" rel=\"noopener\" href=\"http://localhost:3000/dossiers/#{dossier.id}/attestation\">http://localhost:3000/dossiers/#{dossier.id}/attestation</a>") }
|
||||||
|
it { is_expected.to_not include("Télécharger le justificatif") }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "in closed mail with justificatif" do
|
||||||
|
before do
|
||||||
|
dossier.justificatif_motivation.attach(justificatif)
|
||||||
|
end
|
||||||
let(:mail) { create(:closed_mail, procedure: procedure) }
|
let(:mail) { create(:closed_mail, procedure: procedure) }
|
||||||
|
|
||||||
it { is_expected.to eq("<a target=\"_blank\" rel=\"noopener\" href=\"http://localhost:3000/dossiers/#{dossier.id}/attestation\">http://localhost:3000/dossiers/#{dossier.id}/attestation</a>") }
|
it { expect(dossier.justificatif_motivation).to be_attached }
|
||||||
|
it { is_expected.to include("<a target=\"_blank\" rel=\"noopener\" href=\"http://localhost:3000/dossiers/#{dossier.id}/attestation\">http://localhost:3000/dossiers/#{dossier.id}/attestation</a>") }
|
||||||
|
it { is_expected.to include("Télécharger le justificatif") }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "in refuse mail" do
|
describe "in refuse mail" do
|
||||||
|
@ -85,6 +97,12 @@ describe MailTemplateConcern do
|
||||||
|
|
||||||
it { is_expected.to eq("--lien attestation--") }
|
it { is_expected.to eq("--lien attestation--") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "in without continuation mail" do
|
||||||
|
let(:mail) { create(:without_continuation_mail, procedure: procedure) }
|
||||||
|
|
||||||
|
it { is_expected.to eq("--lien attestation--") }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue