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) }
|
|
|
|
let!(:token) { admin.renew_api_token }
|
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
|
|
|
|
context 'when procedure does not exist' do
|
2018-09-26 15:07:33 +02:00
|
|
|
subject { get :show, params: { id: 999_999_999, token: token } }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject.status).to eq(404) }
|
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
context 'when procedure does not belong to administrateur' do
|
|
|
|
let(:procedure) { create(:procedure, administrateur: create(:administrateur)) }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2018-09-26 15:07:33 +02:00
|
|
|
subject { get :show, params: { id: procedure, token: token } }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject.status).to eq(404) }
|
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
context 'when procedure exist' do
|
2016-02-26 14:16:17 +01:00
|
|
|
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin) }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2018-09-26 15:07:33 +02:00
|
|
|
subject { get :show, params: { id: procedure, token: token } }
|
2016-02-22 19:42:47 +01:00
|
|
|
|
|
|
|
it 'return REST code 200', :show_in_doc do
|
|
|
|
expect(subject.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
describe 'body' do
|
2016-02-22 19:42:47 +01:00
|
|
|
let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true) }
|
2016-01-12 15:11:42 +01:00
|
|
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, module_api_carto: module_api_carto, 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] }
|
|
|
|
|
|
|
|
it { expect(subject[:id]).to eq(procedure.id) }
|
2016-01-12 15:11:42 +01:00
|
|
|
it { expect(subject[:label]).to eq(procedure.libelle) }
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject[:description]).to eq(procedure.description) }
|
|
|
|
it { expect(subject[:organisation]).to eq(procedure.organisation) }
|
2016-03-02 15:21:45 +01:00
|
|
|
it { expect(subject[:direction]).to eq(procedure.direction) }
|
2016-01-12 15:11:42 +01:00
|
|
|
it { expect(subject[:link]).to eq(procedure.lien_demarche) }
|
2017-07-10 23:42:33 +02:00
|
|
|
it { expect(subject[:archived_at]).to eq(procedure.archived_at) }
|
2016-07-22 15:06:30 +02:00
|
|
|
it { expect(subject[:total_dossier]).to eq(procedure.total_dossier) }
|
2015-12-21 17:51:49 +01:00
|
|
|
it { is_expected.to have_key(:types_de_champ) }
|
|
|
|
it { expect(subject[:types_de_champ]).to be_an(Array) }
|
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
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
let(:champ) { procedure.types_de_champ.first }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject[:id]).to eq(champ.id) }
|
|
|
|
it { expect(subject[:libelle]).to eq(champ.libelle) }
|
2016-11-15 09:54:17 +01:00
|
|
|
it { expect(subject[:type_champ]).to eq(champ.type_champ) }
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject[:order_place]).to eq(champ.order_place) }
|
|
|
|
it { expect(subject[:description]).to eq(champ.description) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_key(:types_de_piece_justificative) }
|
|
|
|
it { expect(subject[:types_de_piece_justificative]).to be_an(Array) }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
describe 'type_de_piece_jointe' do
|
|
|
|
subject { super()[:types_de_piece_justificative][0] }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
let(:pj) { procedure.types_de_piece_justificative.first }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2015-12-21 17:51:49 +01:00
|
|
|
it { expect(subject[:id]).to eq(pj.id) }
|
|
|
|
it { expect(subject[:libelle]).to eq(pj.libelle) }
|
|
|
|
it { expect(subject[:description]).to eq(pj.description) }
|
|
|
|
end
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2016-01-12 15:11:42 +01:00
|
|
|
it { is_expected.to have_key(:geographic_information) }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2016-01-12 15:11:42 +01:00
|
|
|
describe 'geographic_information' do
|
|
|
|
subject { super()[:geographic_information] }
|
2018-09-26 14:39:17 +02:00
|
|
|
|
2016-01-12 15:11:42 +01:00
|
|
|
it { expect(subject[:use_api_carto]).to be_truthy }
|
|
|
|
it { expect(subject[:quartiers_prioritaires]).to be_truthy }
|
|
|
|
it { expect(subject[:cadastre]).to be_truthy }
|
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|