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
|
|
|
|
2015-12-08 10:11:58 +01:00
|
|
|
let(:procedure) { create(:procedure) }
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:procedure_id) { procedure.id }
|
2015-09-28 18:55:16 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, 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) { '' }
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
let(:siren) { dossier.siren }
|
|
|
|
let(:siret) { dossier.siret }
|
|
|
|
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
|
|
|
|
get :show, id: dossier_id
|
|
|
|
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
|
2015-09-23 19:20:03 +02:00
|
|
|
get :show, id: siret_not_found
|
2015-12-03 12:00:22 +01:00
|
|
|
expect(response).to redirect_to('/users/dossiers')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
subject { get :new, procedure_id: procedure_id }
|
|
|
|
|
|
|
|
context 'when params procedure_id is present' do
|
|
|
|
context 'when procedure_id is valid' do
|
|
|
|
context 'when user is logged in' do
|
|
|
|
before do
|
|
|
|
sign_in create(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(:success) }
|
|
|
|
|
|
|
|
context 'when procedure is archived' do
|
|
|
|
let(:procedure) { create(:procedure, archived: 'true') }
|
|
|
|
|
2015-12-24 15:22:30 +01:00
|
|
|
it { is_expected.to redirect_to users_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) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure_id is not valid' do
|
|
|
|
let(:procedure_id) { 0 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in create(:user)
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:22:30 +01:00
|
|
|
it { is_expected.to redirect_to users_dossiers_path }
|
2015-12-03 12:00:22 +01:00
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
before do
|
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
|
2015-11-27 13:56:54 +01:00
|
|
|
.to_return(status: 404, body: 'fake body')
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
|
2015-11-27 13:56:54 +01:00
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
|
2015-09-23 19:20:03 +02:00
|
|
|
|
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
|
2015-11-27 13:56:54 +01:00
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
|
2015-11-16 11:23:29 +01:00
|
|
|
|
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
|
|
|
|
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
|
2015-12-11 12:36:44 +01:00
|
|
|
|
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/associations/#{siret}?token=#{SIADETOKEN}")
|
|
|
|
.to_return(status: rna_status, body: rna_body)
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
|
2015-12-11 12:36:44 +01:00
|
|
|
describe 'dossier attributs' do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:user) { create(:user) }
|
2015-12-03 12:00:22 +01:00
|
|
|
context 'with valid siret ' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
subject { post :create, dossier: {siret: siret, procedure_id: Procedure.last} }
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'create a dossier' do
|
|
|
|
expect { subject }.to change { Dossier.count }.by(1)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'creates entreprise' do
|
|
|
|
expect { subject }.to change { Entreprise.count }.by(1)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'links entreprise to dossier' do
|
|
|
|
subject
|
|
|
|
expect(Entreprise.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 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
|
|
|
|
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'state of dossier is draft' do
|
|
|
|
subject
|
|
|
|
expect(Dossier.last.state).to eq('draft')
|
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) { '' }
|
|
|
|
|
|
|
|
it 'not creates rna information for entreprise' do
|
|
|
|
expect { subject }.to change { RNAInformation.count }.by(0)
|
|
|
|
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
|
|
|
|
expect { subject }.to change { RNAInformation.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'links rna informations to entreprise' do
|
|
|
|
subject
|
|
|
|
expect(RNAInformation.last.entreprise).to eq(Entreprise.last)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
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
|
|
|
context 'with non existant siret' do
|
|
|
|
before do
|
|
|
|
sign_in create(:user)
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:siret_not_found) { '11111111111111' }
|
|
|
|
subject { post :create, dossier: {siret: siret_not_found, procedure_id: procedure.id} }
|
|
|
|
it 'does not create new dossier' do
|
|
|
|
expect { subject }.not_to change { Dossier.count }
|
|
|
|
end
|
2015-09-23 19:20:03 +02:00
|
|
|
|
2015-12-03 12:00:22 +01:00
|
|
|
it 'redirects to show' do
|
|
|
|
expect(subject).to redirect_to new_users_dossiers_path(procedure_id: procedure_id)
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
before do
|
2015-10-09 17:33:33 +02:00
|
|
|
sign_in dossier.user
|
2015-12-03 12:00:22 +01:00
|
|
|
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
|
2015-09-23 19:20:03 +02:00
|
|
|
end
|
|
|
|
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
|
|
|
|
expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
|
|
|
|
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
|
2015-12-03 12:00:22 +01:00
|
|
|
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}
|
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
|
|
|
|
expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't update dossier autorisation_donnees" do
|
|
|
|
dossier.reload
|
|
|
|
expect(dossier.autorisation_donnees).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-11-27 13:56:54 +01:00
|
|
|
|
|
|
|
describe 'PUT #archive' do
|
|
|
|
let(:dossier) { create(:dossier, user: user) }
|
|
|
|
|
|
|
|
context 'when user is the owner of the file' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
put :archive, dossier_id: dossier.id
|
|
|
|
dossier.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(dossier.archived).to be_truthy }
|
|
|
|
it { expect(response).to redirect_to :users_dossiers }
|
|
|
|
it { expect(flash[:notice]).to have_content 'Dossier archivé' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not the owner of the file' do
|
2015-12-02 16:52:09 +01:00
|
|
|
let(:user_2) { create(:user) }
|
2015-11-27 13:56:54 +01:00
|
|
|
|
2015-12-02 16:52:09 +01:00
|
|
|
before do
|
|
|
|
sign_in user_2
|
2015-11-27 13:56:54 +01:00
|
|
|
|
2015-12-02 16:52:09 +01:00
|
|
|
put :archive, dossier_id: dossier.id
|
|
|
|
procedure.reload
|
|
|
|
end
|
2015-11-27 13:56:54 +01:00
|
|
|
|
2015-12-02 16:52:09 +01:00
|
|
|
it { expect(response).to redirect_to :users_dossiers }
|
|
|
|
it { expect(flash[:alert]).to have_content 'Dossier inéxistant' }
|
2015-11-27 13:56:54 +01:00
|
|
|
end
|
|
|
|
end
|
2015-11-30 14:48:37 +01:00
|
|
|
|
|
|
|
describe 'GET #a_traiter' do
|
|
|
|
context 'when user is connected' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2015-12-02 16:52:09 +01:00
|
|
|
get :index, liste: :a_traiter
|
2015-11-30 14:48:37 +01:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #en_attente' do
|
|
|
|
context 'when user is connected' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2015-12-02 16:52:09 +01:00
|
|
|
get :index, liste: :en_attente
|
2015-11-30 14:48:37 +01:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #termine' do
|
|
|
|
context 'when user is connected' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2015-12-02 16:52:09 +01:00
|
|
|
get :index, liste: :termine
|
2015-11-30 14:48:37 +01:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-23 12:04:57 +02:00
|
|
|
end
|