2015-09-23 12:04:57 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::DossiersController, type: :controller do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:user) { create(:user) }
|
2015-11-27 13:56:54 +01:00
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
let(:procedure) { create(:procedure, :published) }
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:procedure_id) { procedure.id }
|
2016-06-20 13:57:57 +02:00
|
|
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
2015-09-23 19:20:03 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
let(:siret_not_found) { 999_999_999_999 }
|
|
|
|
|
2015-12-11 12:36:44 +01:00
|
|
|
let(:rna_status) { 404 }
|
|
|
|
let(:rna_body) { '' }
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
let(:user) { create :user }
|
|
|
|
|
2016-01-20 10:34:22 +01:00
|
|
|
let(:exercices_status) { 200 }
|
|
|
|
let(:exercices_body) { File.read('spec/support/files/exercices.json') }
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
let(:siren) { '440117620' }
|
|
|
|
let(:siret) { '44011762001530' }
|
2016-05-24 15:43:05 +02:00
|
|
|
let(:siret_with_whitespaces) { '440 1176 2001 530' }
|
2015-09-23 19:20:03 +02:00
|
|
|
let(:bad_siret) { 1 }
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
before do
|
2015-11-27 13:56:54 +01:00
|
|
|
sign_in dossier.user
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
it 'returns http success with dossier_id valid' do
|
2018-01-16 13:34:24 +01:00
|
|
|
get :show, params: { id: dossier_id }
|
2015-09-23 19:20:03 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'redirection vers liste dossier si mauvais dossier ID' do
|
2018-01-16 13:34:24 +01:00
|
|
|
get :show, params: { id: siret_not_found }
|
2016-01-25 15:54:21 +01:00
|
|
|
expect(response).to redirect_to root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'before_action authorized_routes?' do
|
|
|
|
context 'when dossier does not have a valid state' do
|
|
|
|
before do
|
2018-08-28 14:10:55 +02:00
|
|
|
dossier.state = Dossier.states.fetch(:en_instruction)
|
2016-01-25 15:54:21 +01:00
|
|
|
dossier.save
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
get :show, params: { id: dossier.id }
|
2016-01-25 15:54:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to redirect_to root_path }
|
|
|
|
end
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { get :new, params: { procedure_id: procedure_id } }
|
2015-12-03 12:00:22 +01:00
|
|
|
|
|
|
|
context 'when params procedure_id is present' do
|
|
|
|
context 'when procedure_id is valid' do
|
|
|
|
context 'when user is logged in' do
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
it { is_expected.to have_http_status(302) }
|
|
|
|
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
|
|
|
|
|
|
|
|
it { expect { subject }.to change(Dossier, :count).by 1 }
|
|
|
|
|
|
|
|
describe 'save user siret' do
|
|
|
|
context 'when user have not a saved siret' do
|
|
|
|
context 'when siret is present on request' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { get :new, params: { procedure_id: procedure_id, siret: siret } }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
user.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(user.siret).to eq siret }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siret is not present on the request' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
user.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(user.siret).to eq nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user have a saved siret' do
|
|
|
|
before do
|
|
|
|
user.siret = '53029478400026'
|
|
|
|
user.save
|
|
|
|
user.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siret is present on request' do
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { get :new, params: { procedure_id: procedure_id, siret: siret } }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
user.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(user.siret).to eq siret }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siret is not present on the request' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
user.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(user.siret).to eq '53029478400026' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-03 12:00:22 +01:00
|
|
|
|
|
|
|
context 'when procedure is archived' do
|
2018-08-14 11:47:47 +02:00
|
|
|
let(:procedure) { create(:procedure, :archived) }
|
2015-12-03 12:00:22 +01:00
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when user is not logged' do
|
|
|
|
it { is_expected.to have_http_status(302) }
|
2016-06-20 13:57:57 +02:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure_id is not valid' do
|
|
|
|
let(:procedure_id) { 0 }
|
|
|
|
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
context 'when procedure is not published' do
|
2018-08-14 11:47:47 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
|
|
|
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2018-08-14 11:47:47 +02:00
|
|
|
|
|
|
|
context 'and brouillon param is passed' do
|
|
|
|
subject { get :new, params: { procedure_id: procedure_id, brouillon: true } }
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(302) }
|
|
|
|
it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) }
|
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-29 17:35:34 +02:00
|
|
|
describe 'GET #commencer' do
|
2018-05-23 15:36:50 +02:00
|
|
|
subject { get :commencer, params: { procedure_path: path } }
|
|
|
|
let(:path) { procedure.path }
|
2016-06-29 17:35:34 +02:00
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
2016-11-07 17:08:33 +01:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
context 'when procedure path does not exist' do
|
|
|
|
let(:path) { 'hello' }
|
2016-11-07 17:08:33 +01:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
it { expect(subject).to redirect_to(root_path) }
|
2016-11-07 17:08:33 +01:00
|
|
|
end
|
2018-08-14 11:47:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #commencer_test' do
|
|
|
|
before do
|
|
|
|
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { get :commencer_test, params: { procedure_path: path } }
|
|
|
|
let(:procedure) { create(:procedure, :with_path) }
|
|
|
|
let(:path) { procedure.path }
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) }
|
2017-07-06 14:40:06 +02:00
|
|
|
|
2018-08-14 11:47:47 +02:00
|
|
|
context 'when procedure path does not exist' do
|
2018-05-23 15:36:50 +02:00
|
|
|
let(:path) { 'hello' }
|
|
|
|
|
|
|
|
it { expect(subject).to redirect_to(root_path) }
|
|
|
|
end
|
2016-06-29 17:35:34 +02:00
|
|
|
end
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
describe 'POST #siret_informations' do
|
2016-07-22 11:34:34 +02:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
before do
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret_not_found}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: 404, body: 'fake body')
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: status_entreprise_call, body: File.read('spec/support/files/etablissement.json'))
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json'))
|
2015-11-16 11:23:29 +01:00
|
|
|
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: exercices_status, body: exercices_body)
|
2015-12-11 12:36:44 +01:00
|
|
|
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(status: rna_status, body: rna_body)
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
dossier
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
2015-12-11 12:36:44 +01:00
|
|
|
describe 'dossier attributs' do
|
2016-07-22 11:34:34 +02:00
|
|
|
let(:status_entreprise_call) { 200 }
|
2016-05-24 15:43:05 +02:00
|
|
|
shared_examples 'with valid siret' do
|
2015-12-03 12:00:22 +01:00
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { post :siret_informations, params: { dossier_id: dossier.id, dossier: { siret: example_siret } } }
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'create a dossier' do
|
2016-06-20 13:57:57 +02:00
|
|
|
expect { subject }.to change { Dossier.count }.by(0)
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it "links dossier to user" do
|
|
|
|
subject
|
|
|
|
expect(Dossier.last.user).to eq(user)
|
|
|
|
end
|
2015-09-24 11:17:17 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'creates etablissement for dossier' do
|
|
|
|
expect { subject }.to change { Etablissement.count }.by(1)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'links etablissement to dossier' do
|
|
|
|
subject
|
|
|
|
expect(Etablissement.last.dossier).to eq(Dossier.last)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'links etablissement to entreprise' do
|
|
|
|
subject
|
2018-04-23 12:01:03 +02:00
|
|
|
expect(Etablissement.last.entreprise).to be_truthy
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'creates exercices for dossier' do
|
|
|
|
expect { subject }.to change { Exercice.count }.by(3)
|
|
|
|
expect(Exercice.last.etablissement).to eq(Dossier.last.etablissement)
|
|
|
|
end
|
2015-11-16 11:23:29 +01:00
|
|
|
|
2016-01-20 10:34:22 +01:00
|
|
|
context 'when siret have no exercices' do
|
|
|
|
let(:exercices_status) { 404 }
|
|
|
|
let(:exercices_body) { '' }
|
|
|
|
|
|
|
|
it { expect { subject }.not_to change { Exercice.count } }
|
|
|
|
end
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'links procedure to dossier' do
|
|
|
|
subject
|
|
|
|
expect(Dossier.last.procedure).to eq(Procedure.last)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
it 'state of dossier is brouillon' do
|
2015-12-03 12:00:22 +01:00
|
|
|
subject
|
2018-08-28 14:10:55 +02:00
|
|
|
expect(Dossier.last.state).to eq(Dossier.states.fetch(:brouillon))
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
2015-12-11 12:36:44 +01:00
|
|
|
|
|
|
|
describe 'get rna informations' do
|
|
|
|
context 'when siren have not rna informations' do
|
|
|
|
let(:rna_status) { 404 }
|
|
|
|
let(:rna_body) { '' }
|
|
|
|
|
2018-04-23 12:01:03 +02:00
|
|
|
it 'not creates association information for etablissement' do
|
|
|
|
subject
|
|
|
|
expect(Dossier.last.etablissement.association?).to be_falsey
|
2015-12-11 12:36:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siren have rna informations' do
|
|
|
|
let(:rna_status) { 200 }
|
|
|
|
let(:rna_body) { File.read('spec/support/files/rna.json') }
|
|
|
|
|
|
|
|
it 'creates rna information for entreprise' do
|
|
|
|
subject
|
2018-04-23 12:01:03 +02:00
|
|
|
expect(Dossier.last.etablissement.association?).to be_truthy
|
2015-12-11 12:36:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2016-05-24 15:43:05 +02:00
|
|
|
describe "with siret without whitespaces" do
|
|
|
|
let(:example_siret) { siret }
|
2017-02-21 22:05:22 +01:00
|
|
|
if ENV['CIRCLECI'].nil?
|
|
|
|
it_should_behave_like "with valid siret"
|
|
|
|
end
|
2016-05-24 15:43:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "with siret with whitespaces" do
|
|
|
|
let(:example_siret) { siret_with_whitespaces }
|
2017-02-21 22:05:22 +01:00
|
|
|
if ENV['CIRCLECI'].nil?
|
|
|
|
it_should_behave_like "with valid siret"
|
|
|
|
end
|
2016-05-24 15:43:05 +02:00
|
|
|
end
|
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
context 'with non existant siret' do
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
sign_in user
|
|
|
|
subject
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:siret_not_found) { '11111111111111' }
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { post :siret_informations, params: { dossier_id: dossier.id, dossier: { siret: siret_not_found } } }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'does not create new dossier' do
|
|
|
|
expect { subject }.not_to change { Dossier.count }
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
it { expect(response.status).to eq 200 }
|
|
|
|
it { expect(flash.alert).to eq 'Le siret est incorrect' }
|
|
|
|
it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody }
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
|
|
context 'when REST error 400 is return' do
|
|
|
|
let(:status_entreprise_call) { 400 }
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { post :siret_informations, params: { dossier_id: dossier.id, dossier: { siret: siret } } }
|
2016-07-22 11:34:34 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 200 }
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
2017-07-25 17:26:40 +02:00
|
|
|
let(:params) { { id: dossier_id, dossier: { id: dossier_id, autorisation_donnees: autorisation_donnees, individual_attributes: individual_params } } }
|
|
|
|
let(:individual_params) { { gender: 'M.', nom: 'Julien', prenom: 'Xavier', birthdate: birthdate } }
|
|
|
|
let(:birthdate) { '20/01/1991' }
|
2016-12-20 17:02:36 +01:00
|
|
|
subject { put :update, params: params }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
before do
|
2015-10-09 17:33:33 +02:00
|
|
|
sign_in dossier.user
|
2018-02-08 17:13:15 +01:00
|
|
|
dossier.update_columns(autorisation_donnees: nil)
|
|
|
|
dossier.reload
|
2016-06-20 13:57:57 +02:00
|
|
|
subject
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
context 'when Checkbox is checked' do
|
|
|
|
let(:autorisation_donnees) { '1' }
|
2015-09-28 18:55:16 +02:00
|
|
|
|
|
|
|
context 'procedure not use api carto' do
|
|
|
|
it 'redirects to demande' do
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(response).to redirect_to(brouillon_dossier_path(dossier))
|
2015-09-28 18:55:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'procedure use api carto' do
|
2015-12-08 10:11:58 +01:00
|
|
|
let(:procedure) { create(:procedure, :with_api_carto) }
|
2015-09-28 18:55:16 +02:00
|
|
|
|
|
|
|
before do
|
2016-06-20 13:57:57 +02:00
|
|
|
subject
|
2015-09-28 18:55:16 +02:00
|
|
|
end
|
|
|
|
it 'redirects to carte' do
|
|
|
|
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'update dossier' do
|
|
|
|
dossier.reload
|
|
|
|
expect(dossier.autorisation_donnees).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Checkbox is not checked' do
|
|
|
|
let(:autorisation_donnees) { '0' }
|
|
|
|
it 'uses flash alert to display message' do
|
2017-07-25 17:26:40 +02:00
|
|
|
expect(flash[:alert]).to have_content('La validation des conditions d\'utilisation est obligatoire')
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't update dossier autorisation_donnees" do
|
|
|
|
dossier.reload
|
|
|
|
expect(dossier.autorisation_donnees).to be_falsy
|
|
|
|
end
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
it { is_expected.to redirect_to users_dossier_path(id: dossier.id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-25 17:39:53 +02:00
|
|
|
describe 'DELETE #destroy' do
|
2016-11-15 05:54:27 +01:00
|
|
|
let(:user) { create(:user) }
|
2018-08-28 14:10:55 +02:00
|
|
|
let!(:dossier_brouillon) { create :dossier, state: Dossier.states.fetch(:brouillon), user: user }
|
|
|
|
let!(:dossier_not_brouillon) { create :dossier, state: Dossier.states.fetch(:en_construction), user: user }
|
2016-10-25 17:39:53 +02:00
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { delete :destroy, params: { id: dossier.id } }
|
2016-10-25 17:39:53 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
context 'when dossier is brouillon' do
|
|
|
|
let(:dossier) { dossier_brouillon }
|
2016-10-25 17:39:53 +02:00
|
|
|
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
|
|
|
|
describe 'flash notice' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(flash[:notice]).to be_present }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'destroy dossier is call' do
|
|
|
|
expect_any_instance_of(Dossier).to receive(:destroy)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { subject }.to change { Dossier.count }.by(-1) }
|
|
|
|
end
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
context 'when dossier is not a brouillon' do
|
|
|
|
let(:dossier) { dossier_not_brouillon }
|
2016-10-25 17:39:53 +02:00
|
|
|
|
|
|
|
it { expect { subject }.to change { Dossier.count }.by(0) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-20 13:57:57 +02:00
|
|
|
describe 'PUT #change_siret' do
|
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
subject { put :change_siret, params: { dossier_id: dossier.id } }
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
|
|
|
|
|
|
|
it 'function dossier.reset! is call' do
|
|
|
|
expect_any_instance_of(Dossier).to receive(:reset!)
|
|
|
|
subject
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
2016-10-25 17:39:53 +02:00
|
|
|
end
|