2016-11-15 09:54:17 +01:00
|
|
|
describe API::V1::ProceduresController, type: :controller do
|
2018-09-26 15:07:33 +02:00
|
|
|
let!(:admin) { create(:administrateur, :with_api_token) }
|
2022-11-30 10:13:55 +01:00
|
|
|
let!(:token) { APIToken.generate(admin)[1] }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(described_class).to be < APIController }
|
2016-02-22 19:42:47 +01:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
describe 'GET show' do
|
2018-09-26 15:15:46 +02:00
|
|
|
subject { get :show, params: { id: procedure_id, token: token } }
|
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
context 'when procedure does not exist' do
|
2018-09-26 15:15:46 +02:00
|
|
|
let(:procedure_id) { 999_999_999 }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2018-09-26 15:27:59 +02:00
|
|
|
it { is_expected.to have_http_status(404) }
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2018-09-26 16:38:35 +02:00
|
|
|
context 'when procedure belongs to administrateur without token' do
|
2018-09-26 15:23:11 +02:00
|
|
|
let(:procedure_id) { create(:procedure).id }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2023-09-20 09:31:14 +02:00
|
|
|
it { is_expected.to have_http_status(404) }
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2023-09-20 09:28:03 +02:00
|
|
|
context 'when procedure exist but bad token' do
|
|
|
|
let(:token) { 'bad' }
|
|
|
|
let(:procedure_id) { create(:procedure, administrateur: admin).id }
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(401) }
|
|
|
|
end
|
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
context 'when procedure exist' do
|
2018-09-26 15:23:11 +02:00
|
|
|
let(:procedure_id) { create(:procedure, administrateur: admin).id }
|
2016-02-22 19:42:47 +01:00
|
|
|
|
2018-09-26 15:27:59 +02:00
|
|
|
it { is_expected.to have_http_status(200) }
|
2016-02-22 19:42:47 +01:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
describe 'body' do
|
2019-09-09 16:18:42 +02:00
|
|
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, administrateur: admin) }
|
2018-09-26 15:07:33 +02:00
|
|
|
let(:response) { get :show, params: { id: procedure.id, token: token } }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
subject { JSON.parse(response.body, symbolize_names: true)[:procedure] }
|
|
|
|
|
2023-09-19 23:05:52 +02:00
|
|
|
it do
|
|
|
|
expect(subject[:id]).to eq(procedure.id)
|
|
|
|
expect(subject[:label]).to eq(procedure.libelle)
|
|
|
|
expect(subject[:description]).to eq(procedure.description)
|
|
|
|
expect(subject[:organisation]).to eq(procedure.organisation)
|
|
|
|
expect(subject[:archived_at]).to eq(procedure.closed_at)
|
|
|
|
expect(subject[:direction]).to eq("")
|
|
|
|
expect(subject[:total_dossier]).to eq(procedure.total_dossier)
|
|
|
|
is_expected.to have_key(:types_de_champ)
|
|
|
|
expect(subject[:types_de_champ]).to be_an(Array)
|
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
describe 'type_de_champ' do
|
|
|
|
subject { super()[:types_de_champ][0] }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2022-11-16 12:46:33 +01:00
|
|
|
let(:champ) { procedure.active_revision.types_de_champ_public.first }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2023-09-19 23:05:52 +02:00
|
|
|
it do
|
|
|
|
expect(subject[:id]).to eq(champ.id)
|
|
|
|
expect(subject[:libelle]).to eq(champ.libelle)
|
|
|
|
expect(subject[:type_champ]).to eq(champ.type_champ)
|
|
|
|
expect(subject[:description]).to eq(champ.description)
|
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
2019-09-09 16:18:42 +02:00
|
|
|
|
|
|
|
describe 'service' do
|
|
|
|
subject { super()[:service] }
|
|
|
|
|
|
|
|
let(:service) { procedure.service }
|
|
|
|
|
2023-09-19 23:05:52 +02:00
|
|
|
it do
|
|
|
|
expect(subject[:id]).to eq(service.id)
|
|
|
|
expect(subject[:email]).to eq(service.email)
|
|
|
|
expect(subject[:name]).to eq(service.nom)
|
|
|
|
expect(subject[:type_organization]).to eq(service.type_organisme)
|
|
|
|
expect(subject[:organization]).to eq(service.organisme)
|
|
|
|
expect(subject[:phone]).to eq(service.telephone)
|
|
|
|
expect(subject[:schedule]).to eq(service.horaires)
|
|
|
|
expect(subject[:address]).to eq(service.adresse)
|
|
|
|
end
|
2019-09-09 16:18:42 +02:00
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|