2015-09-22 15:00:59 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Backoffice::DossiersController, type: :controller do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, :with_user) }
|
2015-11-27 15:09:16 +01:00
|
|
|
let(:dossier_archived) { create(:dossier, :with_entreprise, :with_user, archived: true) }
|
|
|
|
|
2015-09-22 15:00:59 +02:00
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
let(:bad_dossier_id) { Dossier.count + 10 }
|
2015-11-13 15:23:21 +01:00
|
|
|
let(:gestionnaire) { create(:gestionnaire, administrateur: create(:administrateur)) }
|
2015-09-22 15:00:59 +02:00
|
|
|
|
|
|
|
describe 'GET #show' do
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'gestionnaire is connected' do
|
2015-09-22 15:00:59 +02:00
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :show, id: dossier_id
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
2015-11-27 15:09:16 +01:00
|
|
|
it 'dossier is archived' do
|
|
|
|
get :show, id: dossier_archived
|
|
|
|
expect(response).to redirect_to('/backoffice')
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
it 'dossier id doesnt exist' do
|
2015-09-22 15:00:59 +02:00
|
|
|
get :show, id: bad_dossier_id
|
2015-09-23 16:56:30 +02:00
|
|
|
expect(response).to redirect_to('/backoffice')
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'gestionnaire doesnt connected but dossier id is correct' do
|
2015-09-22 15:00:59 +02:00
|
|
|
subject { get :show, id: dossier_id }
|
|
|
|
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
|
|
|
|
end
|
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-13 15:23:21 +01:00
|
|
|
describe 'GET #a_traiter' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :a_traiter
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #en_attente' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :en_attente
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #termine' do
|
|
|
|
context 'when gestionnaire is connected' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :termine
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
describe 'POST #search' do
|
|
|
|
before do
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
post :search, search_terms: 'test'
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
describe 'POST #valid' do
|
2015-11-02 16:36:52 +01:00
|
|
|
before do
|
|
|
|
dossier.initiated!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
it 'dossier change is state for validated' do
|
|
|
|
post :valid, dossier_id: dossier_id
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
dossier.reload
|
|
|
|
expect(dossier.state).to eq('validated')
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
describe 'POST #close' do
|
2015-11-02 16:36:52 +01:00
|
|
|
before do
|
|
|
|
dossier.submitted!
|
|
|
|
sign_in gestionnaire
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
it 'dossier change is state to closed' do
|
|
|
|
post :close, dossier_id: dossier_id
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
dossier.reload
|
|
|
|
expect(dossier.state).to eq('closed')
|
2015-10-09 12:05:07 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-22 15:00:59 +02:00
|
|
|
end
|