Merge branch 'dev'

This commit is contained in:
gregoirenovel 2017-12-01 14:42:14 +01:00
commit 24545bae25
35 changed files with 327 additions and 91 deletions

View file

Before

Width:  |  Height:  |  Size: 357 B

After

Width:  |  Height:  |  Size: 357 B

View file

@ -1,14 +1,14 @@
@import "colors"; @import "colors";
@import "constants"; @import "constants";
.backoffice-title { .accompagnateur-title {
font-size: 30px; font-size: 30px;
font-weight: normal; font-weight: normal;
margin-top: 3 * $default-spacer; margin-top: 3 * $default-spacer;
margin-bottom: 3 * $default-spacer; margin-bottom: 3 * $default-spacer;
} }
.backoffice-header { .accompagnateur-header {
background-color: $light-grey; background-color: $light-grey;
padding-top: $default-padding; padding-top: $default-padding;
margin-bottom: 2 * $default-spacer; margin-bottom: 2 * $default-spacer;

View file

@ -29,8 +29,8 @@
background-image: image-url("icons/accept.svg"); background-image: image-url("icons/accept.svg");
} }
&.close { &.refuse {
background-image: image-url("icons/close.svg"); background-image: image-url("icons/refuse.svg");
} }
&.without-continuation { &.without-continuation {

View file

@ -2,7 +2,7 @@
@import "fonts"; @import "fonts";
.new-header, .new-header,
.backoffice-header, .accompagnateur-header,
footer { footer {
display: none; display: none;
} }
@ -37,3 +37,23 @@ th {
font-size: 1.2em; font-size: 1.2em;
} }
} }
.messagerie {
.messages-list {
list-style: none;
padding-left: 0;
max-height: none;
li {
margin-bottom: 40px;
}
h2 {
font-size: 110%;
}
.person-icon {
display: none;
}
}
}

View file

@ -101,7 +101,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
current_gestionnaire.follow(dossier) current_gestionnaire.follow(dossier)
flash.notice = 'Dossier passé en instruction.' flash.notice = 'Dossier passé en instruction.'
redirect_to_dossier(dossier) redirect_to backoffice_dossier_path(id: dossier.id)
end end
def process_dossier def process_dossier
@ -143,7 +143,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now! NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now!
redirect_to_dossier(dossier) redirect_to backoffice_dossier_path(id: dossier.id)
end end
def reload_smartlisting def reload_smartlisting
@ -182,19 +182,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
@facade.dossier.initiated! @facade.dossier.initiated!
flash.notice = 'Dossier repassé en construction.' flash.notice = 'Dossier repassé en construction.'
redirect_to_dossier(@facade.dossier) redirect_to backoffice_dossier_path(id: @facade.dossier.id)
end end
private private
def redirect_to_dossier(dossier)
if params[:new_ui] # TODO delete new_ui when old UI is no longer used
redirect_to dossier_path(dossier.procedure, dossier)
else
redirect_to backoffice_dossier_path(id: dossier.id)
end
end
def check_attestation_emailable(dossier) def check_attestation_emailable(dossier)
if dossier&.attestation&.emailable? == false if dossier&.attestation&.emailable? == false
human_size = number_to_human_size(dossier.attestation.pdf.size) human_size = number_to_human_size(dossier.attestation.pdf.size)

View file

@ -1,5 +1,6 @@
module NewGestionnaire module NewGestionnaire
class DossiersController < ProceduresController class DossiersController < ProceduresController
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
def attestation def attestation
@ -52,6 +53,59 @@ module NewGestionnaire
redirect_back(fallback_location: procedures_url) redirect_back(fallback_location: procedures_url)
end end
def passer_en_instruction
dossier.received!
current_gestionnaire.follow(dossier)
flash.notice = 'Dossier passé en instruction.'
redirect_to dossier_path(procedure, dossier)
end
def repasser_en_construction
dossier.initiated!
flash.notice = 'Dossier repassé en construction.'
redirect_to dossier_path(procedure, dossier)
end
def terminer
if params[:dossier] && params[:dossier][:motivation].present?
motivation = params[:dossier][:motivation]
end
case params[:process_action]
when "refuser"
next_step = "refuse"
notice = "Dossier considéré comme refusé."
template = procedure.refused_mail_template
when "classer_sans_suite"
next_step = "without_continuation"
notice = "Dossier considéré comme sans suite."
template = procedure.without_continuation_mail_template
when "accepter"
next_step = "close"
notice = "Dossier traité avec succès."
template = procedure.closed_mail_template
end
dossier.next_step!('gestionnaire', next_step, motivation)
# needed to force Carrierwave to provide dossier.attestation.pdf.read
# when the Feature.remote_storage is true, otherwise pdf.read is a closed stream.
dossier.reload
attestation_pdf = nil
if check_attestation_emailable
attestation_pdf = dossier.attestation.pdf.read
end
flash.notice = notice
NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now!
redirect_to dossier_path(procedure, dossier)
end
def create_commentaire def create_commentaire
commentaire_hash = commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier) commentaire_hash = commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier)
@ -122,5 +176,15 @@ module NewGestionnaire
def champs_private_params def champs_private_params
params.require(:dossier).permit(champs_private_attributes: [:id, :value, value: []]) params.require(:dossier).permit(champs_private_attributes: [:id, :value, value: []])
end end
def check_attestation_emailable
if dossier&.attestation&.emailable? == false
human_size = number_to_human_size(dossier.attestation.pdf.size)
msg = "the attestation of the dossier #{dossier.id} cannot be mailed because it is too heavy: #{human_size}"
capture_message(msg, level: 'error')
end
dossier&.attestation&.emailable?
end
end end
end end

View file

@ -17,12 +17,12 @@ class SIADE::API
end end
def self.exercices(siret) def self.exercices(siret)
endpoint = "/v1/etablissements/exercices/#{siret}" endpoint = "/v2/exercices/#{siret}"
call(base_url + endpoint) call(base_url + endpoint)
end end
def self.rna(siret) def self.rna(siret)
endpoint = "/v1/associations/#{siret}" endpoint = "/v2/associations/#{siret}"
call(base_url + endpoint) call(base_url + endpoint)
end end

View file

@ -10,14 +10,14 @@ class SIADE::ExercicesAdapter
end end
def to_params def to_params
data_source[:exercices] data_source[:exercices].map do |exercice|
{
ca: exercice[:ca],
dateFinExercice: exercice[:date_fin_exercice],
date_fin_exercice_timestamp: exercice[:date_fin_exercice_timestamp]
}
end
rescue rescue
nil nil
end end
def attr_to_fetch
[:ca,
:dateFinExercice,
:date_fin_exercice_timestamp]
end
end end

View file

@ -64,6 +64,8 @@ class Champ < ActiveRecord::Base
case type_champ case type_champ
when 'date' when 'date'
Date.parse(value).strftime('%d/%m/%Y') Date.parse(value).strftime('%d/%m/%Y')
when 'multiple_drop_down_list'
drop_down_list.selected_options_without_decorator(self).join(', ')
else else
value.to_s value.to_s
end end

View file

@ -58,7 +58,7 @@ class Dossier < ActiveRecord::Base
scope :nouveaux, -> { not_archived.state_nouveaux } scope :nouveaux, -> { not_archived.state_nouveaux }
scope :en_instruction, -> { not_archived.state_en_instruction } scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine } scope :termine, -> { not_archived.state_termine }
scope :downloadable, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private) } scope :downloadable_sorted, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private).order(initiated_at: 'asc') }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :with_unread_notifications, -> { where(notifications: { already_read: false }) } scope :with_unread_notifications, -> { where(notifications: { already_read: false }) }

View file

@ -151,7 +151,7 @@ class Procedure < ActiveRecord::Base
end end
def generate_export def generate_export
exportable_dossiers = dossiers.downloadable exportable_dossiers = dossiers.downloadable_sorted
headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : [] headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : []
data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]] data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]]

View file

@ -1,4 +1,4 @@
.backoffice-header .accompagnateur-header
.container .container
%ul.breadcrumbs %ul.breadcrumbs
%li= link_to('Avis', avis_index_path) %li= link_to('Avis', avis_index_path)

View file

@ -2,7 +2,7 @@
- content_for(:title, "Avis #{avis_statut}") - content_for(:title, "Avis #{avis_statut}")
#avis-index #avis-index
.backoffice-header .accompagnateur-header
.container.flex .container.flex
.width-100 .width-100
%h1 Avis %h1 Avis

View file

@ -4,7 +4,7 @@
= render partial: 'header', locals: { avis: @avis, dossier: @dossier } = render partial: 'header', locals: { avis: @avis, dossier: @dossier }
.container .container
.backoffice-title Identité du demandeur .accompagnateur-title Identité du demandeur
.card .card
- if @dossier.entreprise.present? - if @dossier.entreprise.present?
= render partial: 'new_gestionnaire/dossiers/identite_entreprise', locals: { entreprise: @dossier.entreprise } = render partial: 'new_gestionnaire/dossiers/identite_entreprise', locals: { entreprise: @dossier.entreprise }
@ -12,18 +12,18 @@
- if @dossier.individual.present? - if @dossier.individual.present?
= render partial: 'new_gestionnaire/dossiers/identite_individual', locals: { individual: @dossier.individual } = render partial: 'new_gestionnaire/dossiers/identite_individual', locals: { individual: @dossier.individual }
.backoffice-title Formulaire .accompagnateur-title Formulaire
- champs = @dossier.ordered_champs.decorate - champs = @dossier.ordered_champs.decorate
- if champs.any? - if champs.any?
.card .card
= render partial: 'new_gestionnaire/dossiers/champs', locals: { champs: champs } = render partial: 'new_gestionnaire/dossiers/champs', locals: { champs: champs }
- if @dossier.procedure.use_api_carto - if @dossier.procedure.use_api_carto
.backoffice-title Cartographie .accompagnateur-title Cartographie
.card .card
= render partial: 'new_gestionnaire/dossiers/map', locals: { dossier: @dossier } = render partial: 'new_gestionnaire/dossiers/map', locals: { dossier: @dossier }
- if @dossier.procedure.cerfa_flag? || @dossier.types_de_piece_justificative.any? - if @dossier.procedure.cerfa_flag? || @dossier.types_de_piece_justificative.any?
.backoffice-title Pièces jointes .accompagnateur-title Pièces jointes
.card .card
= render partial: "new_gestionnaire/dossiers/pieces_jointes", locals: { dossier: @dossier } = render partial: "new_gestionnaire/dossiers/pieces_jointes", locals: { dossier: @dossier }

View file

@ -1,4 +1,4 @@
.backoffice-header .accompagnateur-header
.container .container
.flex.justify-between .flex.justify-between
%ul.breadcrumbs %ul.breadcrumbs

View file

@ -10,7 +10,7 @@
%h4 En construction %h4 En construction
Vous permettez à l'usager de modifier ses réponses au formulaire Vous permettez à l'usager de modifier ses réponses au formulaire
%li %li
= link_to backoffice_dossier_receive_path(dossier, new_ui: true), method: :post, data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do = link_to passer_en_instruction_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do
.icon.in-progress .icon.in-progress
.description .description
%h4 Passer en instruction %h4 Passer en instruction
@ -18,7 +18,7 @@
- if dossier.en_instruction? - if dossier.en_instruction?
%li %li
= link_to backoffice_dossier_reopen_path(dossier, new_ui: true), method: :post, data: { confirm: "Confirmer vous la réouverture de ce dossier ?" } do = link_to repasser_en_construction_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en construction de ce dossier ?" } do
.icon.edit .icon.edit
.description .description
%h4 Repasser en construction %h4 Repasser en construction
@ -38,14 +38,14 @@
.description .description
%h4 Classer sans suite %h4 Classer sans suite
L'usager ne recevra aucune notification L'usager ne recevra aucune notification
%li{ onclick: "TPS.showMotivation('close');" } %li{ onclick: "TPS.showMotivation('refuse');" }
.icon.close .icon.refuse
.description .description
%h4 Refuser %h4 Refuser
L'usager sera notifié que son dossier a été refusé L'usager sera notifié que son dossier a été refusé
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Accepter le dossier', popup_class: 'accept', process_action: 'close', title: 'Accepter', confirm: 'Accepter ce dossier ?' } = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Accepter le dossier', popup_class: 'accept', process_action: 'accepter', title: 'Accepter', confirm: 'Accepter ce dossier ?' }
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Classer le dossier sans suite', popup_class: 'without-continuation', process_action: 'without_continuation', title: 'Classer sans suite', confirm: 'Confirmer vous le classement sans suite de ce dossier ?' } = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Classer le dossier sans suite', popup_class: 'without-continuation', process_action: 'classer_sans_suite', title: 'Classer sans suite', confirm: 'Confirmer vous le classement sans suite de ce dossier ?' }
= render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Refuser le dossier', popup_class: 'close', process_action: 'refuse', title: 'Refuser', confirm: 'Confirmer vous le refus de ce dossier ?' } = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Refuser le dossier', popup_class: 'refuse', process_action: 'refuser', title: 'Refuser', confirm: 'Confirmer vous le refus de ce dossier ?' }
- else - else
- if dossier.motivation.present? || dossier.attestation.present? - if dossier.motivation.present? || dossier.attestation.present?

View file

@ -3,7 +3,7 @@
.icon{ class: popup_class } .icon{ class: popup_class }
#{popup_title} nº #{dossier.id} #{popup_title} nº #{dossier.id}
= form_tag(backoffice_dossier_process_dossier_url(dossier.id, new_ui: true), method: :post, class: 'form') do = form_tag(terminer_dossier_path(dossier.procedure, dossier), method: :post, class: 'form') do
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)' = text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)'
- if title == 'Accepter' - if title == 'Accepter'
%p.help %p.help

View file

@ -87,20 +87,11 @@
%h2 Messagerie %h2 Messagerie
%table .messagerie
- @dossier.commentaires.each do |commentaire| %ul.messages-list
%tr - @dossier.commentaires.each do |commentaire|
%th %li
= render partial: 'new_gestionnaire/shared/commentaires/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire } = render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
(invité)
%br
= I18n.l(commentaire.created_at.localtime, format: 'le %d/%m/%Y à %H:%M')
%td
%p= sanitize(commentaire.body)
- if file = commentaire.piece_justificative
%br
= file.original_filename
%script{ type: "text/javascript" } %script{ type: "text/javascript" }
window.print(); window.print();

View file

@ -3,7 +3,7 @@
= render partial: "header", locals: { dossier: @dossier } = render partial: "header", locals: { dossier: @dossier }
.container .container
.backoffice-title Identité du demandeur .accompagnateur-title Identité du demandeur
.card .card
- if @dossier.entreprise.present? - if @dossier.entreprise.present?
= render partial: "identite_entreprise", locals: { entreprise: @dossier.entreprise } = render partial: "identite_entreprise", locals: { entreprise: @dossier.entreprise }
@ -11,18 +11,18 @@
- if @dossier.individual.present? - if @dossier.individual.present?
= render partial: "identite_individual", locals: { individual: @dossier.individual } = render partial: "identite_individual", locals: { individual: @dossier.individual }
.backoffice-title Formulaire .accompagnateur-title Formulaire
- champs = @dossier.ordered_champs.decorate - champs = @dossier.ordered_champs.decorate
- if champs.any? - if champs.any?
.card .card
= render partial: "champs", locals: { champs: champs } = render partial: "champs", locals: { champs: champs }
- if @dossier.procedure.use_api_carto - if @dossier.procedure.use_api_carto
.backoffice-title Cartographie .accompagnateur-title Cartographie
.card .card
= render partial: "map", locals: { dossier: @dossier } = render partial: "map", locals: { dossier: @dossier }
- if @dossier.procedure.cerfa_flag? || @dossier.types_de_piece_justificative.any? - if @dossier.procedure.cerfa_flag? || @dossier.types_de_piece_justificative.any?
.backoffice-title Pièces jointes .accompagnateur-title Pièces jointes
.card .card
= render partial: "pieces_jointes", locals: { dossier: @dossier } = render partial: "pieces_jointes", locals: { dossier: @dossier }

View file

@ -1,7 +1,7 @@
- content_for(:title, "Procédures") - content_for(:title, "Procédures")
.container .container
%h1.backoffice-title Procédures %h1.accompagnateur-title Procédures
%ul.procedure-list %ul.procedure-list
- @procedures.each do |p| - @procedures.each do |p|

View file

@ -1,7 +1,7 @@
- content_for(:title, "#{@procedure.libelle}") - content_for(:title, "#{@procedure.libelle}")
#procedure-show #procedure-show
.backoffice-header .accompagnateur-header
.container.flex .container.flex
.procedure-logo .procedure-logo

View file

@ -1,7 +1,7 @@
- content_for(:title, "Recherche : #{@search_terms}") - content_for(:title, "Recherche : #{@search_terms}")
.container .container
.backoffice-title .accompagnateur-title
Résultat de la recherche : Résultat de la recherche :
= pluralize(@dossiers.count, "dossier trouvé", "dossiers trouvés") = pluralize(@dossiers.count, "dossier trouvé", "dossiers trouvés")

View file

@ -8,7 +8,7 @@
.icon.unarchive .icon.unarchive
.icon.folder .icon.folder
.icon.accept .icon.accept
.icon.close .icon.refuse
.icon.without-continuation .icon.without-continuation
.icon.edit .icon.edit
.icon.in-progress .icon.in-progress
@ -135,7 +135,7 @@
%td Table Data 3 %td Table Data 3
%h1 Header %h1 Header
.backoffice-header .accompagnateur-header
.container .container
Titre Titre
%ul.tabs %ul.tabs

View file

@ -254,6 +254,9 @@ Rails.application.routes.draw do
patch 'unarchive' patch 'unarchive'
patch 'annotations' => 'dossiers#update_annotations' patch 'annotations' => 'dossiers#update_annotations'
post 'commentaire' => 'dossiers#create_commentaire' post 'commentaire' => 'dossiers#create_commentaire'
post 'passer-en-instruction' => 'dossiers#passer_en_instruction'
post 'repasser-en-construction' => 'dossiers#repasser_en_construction'
post 'terminer'
scope :carte do scope :carte do
get 'position' get 'position'
end end

View file

@ -9,6 +9,23 @@ namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do
end end
end end
task fix: :environment do
commentaires_to_fix = Commentaire.where.not(file: nil).where.not(piece_justificative_id: nil).reorder(id: :desc)
puts "#{commentaires_to_fix.count} commentaires to fix..."
commentaires_to_fix.each do |c|
process_commentaire(c)
end
end
def sanitize_name(name) # from https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/sanitized_file.rb#L323
name = name.gsub(/[^[:word:]\.\-\+]/,"_")
name = "_#{name}" if name =~ /\A\.+\z/
name = "unnamed" if name.size == 0
return name.mb_chars.to_s
end
def process_commentaire commentaire def process_commentaire commentaire
puts "Processing commentaire #{commentaire.id}" puts "Processing commentaire #{commentaire.id}"
if commentaire.piece_justificative.present? if commentaire.piece_justificative.present?
@ -16,7 +33,7 @@ namespace :'2017_10_30_copy_commentaire_piece_justificative_to_file' do
commentaire.remote_file_url = commentaire.piece_justificative.content_url commentaire.remote_file_url = commentaire.piece_justificative.content_url
if commentaire.piece_justificative.original_filename.present? if commentaire.piece_justificative.original_filename.present?
commentaire.file.define_singleton_method(:filename) { commentaire.piece_justificative.original_filename } commentaire.file.define_singleton_method(:filename) { sanitize_name(commentaire.piece_justificative.original_filename) }
end end
if commentaire.body.blank? if commentaire.body.blank?

View file

@ -77,6 +77,156 @@ describe NewGestionnaire::DossiersController, type: :controller do
it { expect(response).to redirect_to(procedures_url) } it { expect(response).to redirect_to(procedures_url) }
end end
describe '#passer_en_instruction' do
before do
dossier.initiated!
sign_in gestionnaire
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }
dossier.reload
end
it { expect(dossier.state).to eq('received') }
it { is_expected.to redirect_to dossier_path(procedure, dossier) }
it { expect(gestionnaire.follow?(dossier)).to be true }
end
describe '#repasser_en_construction' do
before do
dossier.received!
sign_in gestionnaire
end
subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id} }
it 'change state to initiated' do
subject
dossier.reload
expect(dossier.state).to eq('initiated')
end
it { is_expected.to redirect_to dossier_path(procedure, dossier) }
end
describe '#terminer' do
context "with refuser" do
before do
dossier.received!
sign_in gestionnaire
end
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id} }
it 'change state to refused' do
subject
dossier.reload
expect(dossier.state).to eq('refused')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::RefusedMail), nil).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
it { is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) }
end
context "with classer_sans_suite" do
before do
dossier.received!
sign_in gestionnaire
end
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id} }
it 'change state to without_continuation' do
subject
dossier.reload
expect(dossier.state).to eq('without_continuation')
end
it 'Notification email is sent' do
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::WithoutContinuationMail), nil).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
it { is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) }
end
context "with accepter" do
let(:expected_attestation) { nil }
before do
dossier.received!
sign_in gestionnaire
expect(NotificationMailer).to receive(:send_notification)
.with(dossier, kind_of(Mails::ClosedMail), expected_attestation)
.and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
end
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id} }
it 'change state to closed' do
subject
dossier.reload
expect(dossier.state).to eq('closed')
end
context 'when the dossier does not have any attestation' do
it 'Notification email is sent' do
subject
end
end
context 'when the dossier has an attestation' do
before do
attestation = Attestation.new
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
allow(attestation).to receive(:emailable?).and_return(emailable)
expect_any_instance_of(Dossier).to receive(:reload)
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
end
context 'emailable' do
let(:emailable) { true }
let(:expected_attestation) { 'pdf' }
it 'Notification email is sent with the attestation' do
subject
is_expected.to redirect_to redirect_to dossier_path(procedure, dossier)
end
end
context 'when the dossier has an attestation not emailable' do
let(:emailable) { false }
let(:expected_attestation) { nil }
it 'Notification email is sent without the attestation' do
expect(controller).to receive(:capture_message)
subject
is_expected.to redirect_to redirect_to dossier_path(procedure, dossier)
end
end
end
end
end
describe '#show #messagerie #annotations_privees #avis' do describe '#show #messagerie #annotations_privees #avis' do
before do before do
dossier.notifications = %w(champs annotations_privees avis commentaire).map{ |type| Notification.create!(type_notif: type) } dossier.notifications = %w(champs annotations_privees avis commentaire).map{ |type| Notification.create!(type_notif: type) }

View file

@ -187,10 +187,10 @@ describe Users::DossiersController, type: :controller do
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json')) .to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: exercices_status, body: exercices_body) .to_return(status: exercices_status, body: exercices_body)
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: rna_status, body: rna_body) .to_return(status: rna_status, body: rna_body)
dossier dossier

View file

@ -35,9 +35,9 @@ feature 'user path for dossier creation' do
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json')) .to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
page.find_by_id('dossier-siret').set siret page.find_by_id('dossier-siret').set siret

View file

@ -50,9 +50,9 @@ feature 'As a User I wanna create a dossier' do
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) .to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json')) .to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
page.find_by_id('dossier-siret').set siret page.find_by_id('dossier-siret').set siret
page.find_by_id('submit-siret').trigger('click') page.find_by_id('submit-siret').trigger('click')

View file

@ -30,9 +30,9 @@ feature 'user arrive on siret page' do
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) .to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json')) .to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") stub_request(:get, "https://api-dev.apientreprise.fr/v2/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
page.find_by_id('dossier-siret').set siret page.find_by_id('dossier-siret').set siret

View file

@ -57,7 +57,7 @@ describe SIADE::API do
describe '.exercices' do describe '.exercices' do
before do before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v1\/etablissements\/exercices\/.*token=/) stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v2\/exercices\/.*token=/)
.to_return(status: status, body: body) .to_return(status: status, body: body)
end end
@ -88,7 +88,7 @@ describe SIADE::API do
describe '.rna' do describe '.rna' do
before do before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v1\/associations\/.*token=/) stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v2\/associations\/.*token=/)
.to_return(status: status, body: body) .to_return(status: status, body: body)
end end

View file

@ -5,7 +5,7 @@ describe SIADE::ExercicesAdapter do
subject { described_class.new(siret).to_params } subject { described_class.new(siret).to_params }
before do before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v1\/etablissements\/exercices\/.*token=/) stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v2\/exercices\/.*token=/)
.to_return(body: File.read('spec/support/files/exercices.json', status: 200)) .to_return(body: File.read('spec/support/files/exercices.json', status: 200))
end end

View file

@ -8,7 +8,7 @@ describe SIADE::RNAAdapter do
subject { described_class.new(siret).to_params } subject { described_class.new(siret).to_params }
before do before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v1\/associations\/.*token=/) stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/v2\/associations\/.*token=/)
.to_return(body: body, status: status) .to_return(body: body, status: status)
end end

View file

@ -758,19 +758,16 @@ describe Dossier do
end end
end end
describe '.downloadable' do describe '.downloadable_sorted' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) } let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) } let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated, initiated_at: DateTime.parse('03/01/2010')) }
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received) } let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, initiated_at: DateTime.parse('01/01/2010')) }
let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true) } let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true, initiated_at: DateTime.parse('02/01/2010')) }
subject { procedure.dossiers.downloadable } subject { procedure.dossiers.downloadable_sorted }
it { is_expected.not_to include(dossier)} it { is_expected.to match([dossier3, dossier4, dossier2])}
it { is_expected.to include(dossier2)}
it { is_expected.to include(dossier3)}
it { is_expected.to include(dossier4)}
end end
describe "#send_dossier_received" do describe "#send_dossier_received" do

View file

@ -2,18 +2,18 @@
"exercices":[ "exercices":[
{ {
"ca":"21009417", "ca":"21009417",
"dateFinExercice":"2013-12-31T00:00:00+01:00", "date_fin_exercice":"2013-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1388444400 "date_fin_exercice_timestamp": 1388444400
}, },
{ {
"ca":"18968298", "ca":"18968298",
"dateFinExercice":"2012-12-31T00:00:00+01:00", "date_fin_exercice":"2012-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1356908400 "date_fin_exercice_timestamp": 1356908400
}, },
{ {
"ca":"17768838", "ca":"17768838",
"dateFinExercice":"2011-12-31T00:00:00+01:00", "date_fin_exercice":"2011-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1325286000 "date_fin_exercice_timestamp": 1325286000
} }
] ]
} }