Simplify API carte serializer
This commit is contained in:
parent
36f6f54337
commit
d988638c58
6 changed files with 18 additions and 83 deletions
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe API::V1::DossiersController do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:token) { admin.renew_api_token }
|
||||
let(:procedure) { create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
|
||||
let(:wrong_procedure) { create(:procedure) }
|
||||
|
||||
it { expect(described_class).to be < APIController }
|
||||
|
@ -253,46 +253,6 @@ describe API::V1::DossiersController do
|
|||
it { expect(subject[:type_champ]).to eq('text') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the dossier includes a quartier prioritaire' do
|
||||
before do
|
||||
dossier.quartier_prioritaires << create(:quartier_prioritaire)
|
||||
end
|
||||
|
||||
subject do
|
||||
super().find { |champ| champ[:type_de_champ][:type_champ] == 'quartier_prioritaire' }
|
||||
end
|
||||
|
||||
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'quartier prioritaire', type_champ: 'quartier_prioritaire', order_place: -1, descripton: '' }) }
|
||||
it { expect(subject[:value]).to match(dossier.quartier_prioritaires.first.geometry.symbolize_keys) }
|
||||
end
|
||||
|
||||
context 'when the dossier includes a cadastre' do
|
||||
before do
|
||||
dossier.cadastres << create(:cadastre)
|
||||
end
|
||||
|
||||
subject do
|
||||
super().find { |champ| champ[:type_de_champ][:type_champ] == 'cadastre' }
|
||||
end
|
||||
|
||||
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'cadastre', type_champ: 'cadastre', order_place: -1, descripton: '' }) }
|
||||
it { expect(subject[:value]).to match(dossier.cadastres.first.geometry.symbolize_keys) }
|
||||
end
|
||||
|
||||
context 'when the dossier includes some user geometry' do
|
||||
before do
|
||||
dossier.json_latlngs = '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]'
|
||||
dossier.save
|
||||
end
|
||||
|
||||
subject do
|
||||
super().find { |champ| champ[:type_de_champ][:type_champ] == 'user_geometry' }
|
||||
end
|
||||
|
||||
it { expect(subject[:type_de_champ]).to match({ id: -1, libelle: 'user geometry', type_champ: 'user_geometry', order_place: -1, descripton: '' }) }
|
||||
it { expect(subject[:value]).to match(UserGeometry.new(dossier.json_latlngs).geometry) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'champs_private' do
|
||||
|
|
|
@ -25,8 +25,7 @@ describe API::V1::ProceduresController, type: :controller do
|
|||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
describe 'body' do
|
||||
let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true) }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, module_api_carto: module_api_carto, administrateur: admin) }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) }
|
||||
let(:response) { get :show, params: { id: procedure.id, token: token } }
|
||||
|
||||
subject { JSON.parse(response.body, symbolize_names: true)[:procedure] }
|
||||
|
@ -65,16 +64,6 @@ describe API::V1::ProceduresController, type: :controller do
|
|||
it { expect(subject[:libelle]).to eq(pj.libelle) }
|
||||
it { expect(subject[:description]).to eq(pj.description) }
|
||||
end
|
||||
|
||||
it { is_expected.to have_key(:geographic_information) }
|
||||
|
||||
describe 'geographic_information' do
|
||||
subject { super()[:geographic_information] }
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ describe DossierSerializer do
|
|||
context 'champs' do
|
||||
subject { super()[:champs] }
|
||||
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_two_quartier_prioritaires, procedure: create(:procedure, :published, :with_api_carto, :with_type_de_champ)) }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :published, :with_type_de_champ)) }
|
||||
|
||||
before do
|
||||
dossier.champs << create(:champ_carte)
|
||||
|
@ -29,12 +29,11 @@ describe DossierSerializer do
|
|||
end
|
||||
|
||||
it {
|
||||
expect(subject.size).to eq(8)
|
||||
expect(subject.size).to eq(6)
|
||||
|
||||
expect(subject[0][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:text))
|
||||
expect(subject[1][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:carte))
|
||||
expect(subject[2][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:siret))
|
||||
expect(subject[7][:type_de_champ][:type_champ]).to eq('quartier_prioritaire')
|
||||
|
||||
expect(subject[1][:geo_areas].size).to eq(0)
|
||||
expect(subject[2][:etablissement]).to be_present
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue