2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-22 15:00:52 +02:00
|
|
|
describe Champs::CarteController, type: :controller do
|
|
|
|
let(:user) { create(:user) }
|
2024-03-28 12:42:29 +01:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :carte, options: { cadastres: true } }]) }
|
2018-10-22 15:00:52 +02:00
|
|
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
dossier: {
|
2022-11-10 22:21:14 +01:00
|
|
|
champs_public_attributes: {
|
2024-03-28 12:42:29 +01:00
|
|
|
champ.public_id => { value: value }
|
2018-10-22 15:00:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
position: '1',
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id
|
2018-10-22 15:00:52 +02:00
|
|
|
}
|
|
|
|
end
|
2024-03-28 12:42:29 +01:00
|
|
|
let(:champ) { dossier.champs.first }
|
2020-05-14 11:21:33 +02:00
|
|
|
|
2020-05-05 15:09:29 +02:00
|
|
|
describe 'features' do
|
|
|
|
let(:feature) { attributes_for(:geo_area, :polygon) }
|
|
|
|
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon, champ: champ) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id,
|
2021-05-06 18:50:06 +02:00
|
|
|
feature: feature,
|
|
|
|
source: GeoArea.sources.fetch(:selection_utilisateur)
|
2020-05-05 15:09:29 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
request.accept = "application/json"
|
|
|
|
request.content_type = "application/json"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
before do
|
|
|
|
post :create, params: params
|
|
|
|
end
|
|
|
|
|
2021-06-02 12:43:24 +02:00
|
|
|
context 'success' do
|
|
|
|
it { expect(response.status).to eq 201 }
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
2021-06-02 12:43:24 +02:00
|
|
|
context 'error' do
|
2023-04-07 15:24:28 +02:00
|
|
|
let(:feature) { attributes_for(:geo_area, :invalid_point) }
|
2020-06-04 11:32:59 +02:00
|
|
|
let(:params) do
|
|
|
|
{
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id,
|
2021-06-02 12:43:24 +02:00
|
|
|
feature: feature,
|
|
|
|
source: GeoArea.sources.fetch(:selection_utilisateur)
|
2020-06-04 11:32:59 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-06-02 12:43:24 +02:00
|
|
|
it { expect(response.status).to eq 422 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id,
|
2021-06-02 12:43:24 +02:00
|
|
|
id: geo_area.id,
|
|
|
|
feature: feature
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
patch :update, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'update geometry' do
|
2020-06-04 11:32:59 +02:00
|
|
|
it { expect(response.status).to eq 204 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'update description' do
|
|
|
|
let(:feature) do
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
description: 'un point'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(response.status).to eq 204
|
|
|
|
expect(geo_area.reload.description).to eq('un point')
|
|
|
|
}
|
|
|
|
end
|
2021-06-02 12:43:24 +02:00
|
|
|
|
|
|
|
context 'error' do
|
2023-04-07 15:24:28 +02:00
|
|
|
let(:feature) { attributes_for(:geo_area, :invalid_point) }
|
2021-06-02 12:43:24 +02:00
|
|
|
|
|
|
|
it { expect(response.status).to eq 422 }
|
|
|
|
end
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE #destroy' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id,
|
2020-05-05 15:09:29 +02:00
|
|
|
id: geo_area.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
delete :destroy, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 204 }
|
|
|
|
end
|
|
|
|
|
2021-05-06 18:50:06 +02:00
|
|
|
describe 'GET #index' do
|
2020-05-07 12:06:42 +02:00
|
|
|
render_views
|
|
|
|
|
2020-05-05 15:09:29 +02:00
|
|
|
before do
|
2022-05-03 19:43:25 +02:00
|
|
|
get :index, params: params, format: :turbo_stream
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
2021-06-22 11:37:48 +02:00
|
|
|
context 'without focus' do
|
|
|
|
let(:params) do
|
2024-03-28 12:42:29 +01:00
|
|
|
{
|
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id
|
|
|
|
}
|
2021-06-22 11:37:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the list' do
|
2022-05-03 19:43:25 +02:00
|
|
|
expect(response.body).not_to include("map:feature:focus")
|
2020-05-05 15:09:29 +02:00
|
|
|
expect(response.status).to eq 200
|
2021-06-22 11:37:48 +02:00
|
|
|
end
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
2021-05-06 18:50:06 +02:00
|
|
|
context "update list and focus" do
|
2020-05-05 15:09:29 +02:00
|
|
|
let(:params) do
|
|
|
|
{
|
2024-03-28 12:42:29 +01:00
|
|
|
dossier_id: champ.dossier_id,
|
|
|
|
stable_id: champ.stable_id,
|
2021-05-06 18:50:06 +02:00
|
|
|
focus: true
|
2020-05-05 15:09:29 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-06-22 11:37:48 +02:00
|
|
|
it 'updates the list and focuses the map' do
|
2022-05-03 19:43:25 +02:00
|
|
|
expect(response.body).to include(ActionView::RecordIdentifier.dom_id(champ, :geo_areas))
|
|
|
|
expect(response.body).to include("map:feature:focus")
|
2020-05-05 15:09:29 +02:00
|
|
|
expect(response.status).to eq 200
|
2021-06-22 11:37:48 +02:00
|
|
|
end
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-22 15:00:52 +02:00
|
|
|
end
|