2018-09-07 18:16:29 +02:00
|
|
|
describe Champs::DossierLinkController, type: :controller do
|
|
|
|
let(:user) { create(:user) }
|
2022-04-28 15:06:04 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :with_dossier_link) }
|
2018-09-07 18:16:29 +02:00
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
2022-04-28 15:06:04 +02:00
|
|
|
let(:champ) { dossier.champs.first }
|
2018-09-07 18:16:29 +02:00
|
|
|
|
|
|
|
context 'when user is connected' do
|
|
|
|
render_views
|
|
|
|
before { sign_in user }
|
|
|
|
|
2022-04-28 15:06:04 +02:00
|
|
|
let(:champs_attributes) do
|
|
|
|
champ_attributes = []
|
|
|
|
champ_attributes[champ.id] = { value: dossier_id }
|
|
|
|
champ_attributes
|
|
|
|
end
|
2018-09-07 18:16:29 +02:00
|
|
|
let(:params) do
|
|
|
|
{
|
2022-04-28 15:06:04 +02:00
|
|
|
champ_id: champ.id,
|
2018-09-07 18:16:29 +02:00
|
|
|
dossier: {
|
2022-04-28 15:06:04 +02:00
|
|
|
champs_attributes: champs_attributes
|
|
|
|
}
|
2018-09-07 18:16:29 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:dossier_id) { dossier.id }
|
|
|
|
|
|
|
|
context 'when the dossier exist' do
|
2021-06-22 11:37:48 +02:00
|
|
|
before do
|
|
|
|
get :show, params: params, format: :js, xhr: true
|
|
|
|
end
|
2018-09-07 18:16:29 +02:00
|
|
|
|
2018-10-10 21:59:53 +02:00
|
|
|
it 'renders the procedure name' do
|
2018-09-07 18:16:29 +02:00
|
|
|
expect(response.body).to include('Dossier en brouillon')
|
|
|
|
expect(response.body).to include(procedure.libelle)
|
|
|
|
expect(response.body).to include(procedure.organisation)
|
2022-04-28 15:06:04 +02:00
|
|
|
expect(response.body).to include("##{champ.input_group_id} .help-block")
|
2018-09-07 18:16:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the dossier does not exist' do
|
|
|
|
let(:dossier_id) { '13' }
|
2021-06-22 11:37:48 +02:00
|
|
|
before do
|
|
|
|
get :show, params: params, format: :js, xhr: true
|
|
|
|
end
|
2018-09-07 18:16:29 +02:00
|
|
|
|
2018-10-10 21:59:53 +02:00
|
|
|
it 'renders error message' do
|
|
|
|
expect(response.body).to include('Ce dossier est inconnu')
|
2022-04-28 15:06:04 +02:00
|
|
|
expect(response.body).to include("##{champ.input_group_id} .help-block")
|
2018-10-10 21:59:53 +02:00
|
|
|
end
|
2018-09-07 18:16:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not connected' do
|
2021-06-22 11:37:48 +02:00
|
|
|
before do
|
2022-04-28 15:06:04 +02:00
|
|
|
get :show, params: { champ_id: champ.id }, format: :js, xhr: true
|
2021-06-22 11:37:48 +02:00
|
|
|
end
|
2018-09-07 18:16:29 +02:00
|
|
|
|
|
|
|
it { expect(response.code).to eq('401') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|