Remove quartiers prioritaires

This commit is contained in:
Paul Chavard 2020-04-09 19:08:18 +02:00
parent f6aef9fb66
commit 52d2ace823
12 changed files with 7 additions and 223 deletions

View file

@ -39,14 +39,6 @@ class Champs::CarteController < ApplicationController
end end
end end
if @champ.quartiers_prioritaires?
quartiers_prioritaires = ApiCartoService.generate_qp(coordinates)
geo_areas += quartiers_prioritaires.map do |qp|
qp[:source] = GeoArea.sources.fetch(:quartier_prioritaire)
qp
end
end
selection_utilisateur = ApiCartoService.generate_selection_utilisateur(coordinates) selection_utilisateur = ApiCartoService.generate_selection_utilisateur(coordinates)
selection_utilisateur[:source] = GeoArea.sources.fetch(:selection_utilisateur) selection_utilisateur[:source] = GeoArea.sources.fetch(:selection_utilisateur)
geo_areas << selection_utilisateur geo_areas << selection_utilisateur

View file

@ -136,10 +136,6 @@ const TypeDeChamp = sortableElement(
url={typeDeChamp.piece_justificative_template_url} url={typeDeChamp.piece_justificative_template_url}
/> />
<TypeDeChampCarteOptions isVisible={isCarte}> <TypeDeChampCarteOptions isVisible={isCarte}>
<TypeDeChampCarteOption
label="Quartiers prioritaires"
handler={updateHandlers.quartiers_prioritaires}
/>
<TypeDeChampCarteOption <TypeDeChampCarteOption
label="Cadastres" label="Cadastres"
handler={updateHandlers.cadastres} handler={updateHandlers.cadastres}

View file

@ -2,11 +2,6 @@ class ApiCarto::API
class ResourceNotFound < StandardError class ResourceNotFound < StandardError
end end
def self.search_qp(geojson)
url = [API_CARTO_URL, "quartiers-prioritaires", "search"].join("/")
call(url, geojson)
end
def self.search_cadastre(geojson) def self.search_cadastre(geojson)
url = [API_CARTO_URL, "cadastre", "geometrie"].join("/") url = [API_CARTO_URL, "cadastre", "geometrie"].join("/")
call(url, geojson) call(url, geojson)

View file

@ -1,15 +0,0 @@
class ApiCarto::QuartiersPrioritairesAdapter
def initialize(coordinates)
@coordinates = GeojsonService.to_json_polygon_for_qp(coordinates)
end
def data_source
@data_source ||= JSON.parse(ApiCarto::API.search_qp(@coordinates), symbolize_names: true)
end
def results
data_source[:features].map do |feature|
feature[:properties].merge({ geometry: feature[:geometry] })
end
end
end

View file

@ -1,15 +1,4 @@
class GeojsonService class GeojsonService
def self.to_json_polygon_for_qp(coordinates)
polygon = {
geo: {
type: "Polygon",
coordinates: [coordinates]
}
}
polygon.to_json
end
def self.to_json_polygon_for_cadastre(coordinates) def self.to_json_polygon_for_cadastre(coordinates)
polygon = { polygon = {
geom: { geom: {
@ -26,17 +15,6 @@ class GeojsonService
polygon.to_json polygon.to_json
end end
def self.to_json_polygon_for_rpg(coordinates)
polygon = {
polygonIntersects: {
type: "Polygon",
coordinates: [coordinates]
}
}
polygon.to_json
end
def self.to_json_polygon_for_selection_utilisateur(coordinates) def self.to_json_polygon_for_selection_utilisateur(coordinates)
coordinates = coordinates.map do |lat_longs| coordinates = coordinates.map do |lat_longs|
outbounds = lat_longs.map do |lat_long| outbounds = lat_longs.map do |lat_long|

View file

@ -16,7 +16,7 @@ describe Champs::CarteController, type: :controller do
let(:geojson) { [] } let(:geojson) { [] }
let(:champ) do let(:champ) do
create(:type_de_champ_carte, options: { create(:type_de_champ_carte, options: {
quartiers_prioritaires: true cadastres: true
}).champ.create(dossier: dossier, value: geojson.to_json) }).champ.create(dossier: dossier, value: geojson.to_json)
end end
@ -29,9 +29,9 @@ describe Champs::CarteController, type: :controller do
before do before do
sign_in user sign_in user
allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter) allow_any_instance_of(ApiCarto::CadastreAdapter)
.to receive(:results) .to receive(:results)
.and_return([{ code: "QPCODE1234", geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) .and_return([{ code: "QPCODE1234", surface_parcelle: 4, geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }])
post :show, params: params, format: 'js' post :show, params: params, format: 'js'
end end
@ -71,7 +71,7 @@ describe Champs::CarteController, type: :controller do
before do before do
sign_in user sign_in user
allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter) allow_any_instance_of(ApiCarto::CadastreAdapter)
.to receive(:results) .to receive(:results)
.and_raise(ApiCarto::API::ResourceNotFound) .and_raise(ApiCarto::API::ResourceNotFound)

View file

@ -120,16 +120,15 @@ feature 'As an administrateur I can edit types de champ', js: true do
select('Carte', from: 'champ-0-type_champ') select('Carte', from: 'champ-0-type_champ')
fill_in 'champ-0-libelle', with: 'Libellé de champ carte', fill_options: { clear: :backspace } fill_in 'champ-0-libelle', with: 'Libellé de champ carte', fill_options: { clear: :backspace }
check 'Quartiers prioritaires' check 'Cadastres'
wait_until { procedure.types_de_champ.first.quartiers_prioritaires == true } wait_until { procedure.types_de_champ.first.cadastres == true }
expect(page).to have_content('Formulaire enregistré') expect(page).to have_content('Formulaire enregistré')
preview_window = window_opened_by { click_on 'Prévisualiser le formulaire' } preview_window = window_opened_by { click_on 'Prévisualiser le formulaire' }
within_window(preview_window) do within_window(preview_window) do
expect(page).to have_content('Libellé de champ carte') expect(page).to have_content('Libellé de champ carte')
expect(page).to have_content('Quartiers prioritaires') expect(page).to have_content('Parcelles cadastrales')
expect(page).not_to have_content('Cadastres')
end end
end end

View file

@ -1,29 +0,0 @@
{
"geo": {
"type": "Polygon",
"coordinates": [
[
[
5.93536376953125,
48.91888968903368
],
[
5.93536376953125,
49.26780455063753
],
[
7.094421386718749,
49.26780455063753
],
[
7.094421386718749,
48.91888968903368
],
[
5.93536376953125,
48.91888968903368
]
]
]
}
}

View file

@ -1,30 +0,0 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
6.2136923480551,
49.1342109827851
],
[
6.21416055031881,
49.1338823553928
]
]
]
]
},
"properties": {
"code": "QP057019",
"nom": "Hauts De Vallières",
"commune": "Metz"
}
}
]
}

View file

@ -1,52 +1,4 @@
describe ApiCarto::API do describe ApiCarto::API do
describe '.search_qp' do
subject { described_class.search_qp(geojson) }
before do
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/quartiers-prioritaires/search")
.with(:body => /.*/,
:headers => { 'Content-Type' => 'application/json' })
.to_return(status: status, body: body)
end
context 'when geojson is empty' do
let(:geojson) { '' }
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiCarto::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound)
end
end
context 'when request return 500' do
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_qp.json') }
let(:status) { 500 }
let(:body) { 'toto' }
it 'raises ApiCarto::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound)
end
end
context 'when geojson exist' do
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_qp.json') }
let(:status) { 200 }
let(:body) { 'toto' }
it 'returns response body' do
expect(subject).to eq(body)
end
context 'when geojson is at format JSON' do
let(:geojson) { JSON.parse(File.read('spec/fixtures/files/api_carto/request_qp.json')) }
it 'returns response body' do
expect(subject).to eq(body)
end
end
end
end
describe '.search_cadastre' do describe '.search_cadastre' do
subject { described_class.search_cadastre(geojson) } subject { described_class.search_cadastre(geojson) }

View file

@ -1,36 +0,0 @@
describe ApiCarto::QuartiersPrioritairesAdapter do
subject { described_class.new(coordinates).results }
before do
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/quartiers-prioritaires/search")
.with(:body => /.*/,
:headers => { 'Content-Type' => 'application/json' })
.to_return(status: status, body: body)
end
context 'coordinates are filled' do
let(:coordinates) { '[[2.252728, 43.27151][2.323223, 32.835332]]' }
let(:status) { 200 }
let(:body) { File.read('spec/fixtures/files/api_carto/response_qp.json') }
it { expect(subject).to be_a_instance_of(Array) }
context 'Attributes' do
let(:qp_code) { 'QP057019' }
it { expect(subject.first[:code]).to eq(qp_code) }
it { expect(subject.first[:nom]).to eq('Hauts De Vallières') }
it { expect(subject.first[:commune]).to eq('Metz') }
it { expect(subject.first[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
end
end
context 'coordinates are empty' do
let(:coordinates) { '' }
let(:status) { 404 }
let(:body) { '' }
it { expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound) }
end
end

View file

@ -9,24 +9,6 @@ describe GeojsonService do
] ]
} }
describe '.toGeoJsonPolygonForQp' do
subject { JSON.parse(described_class.to_json_polygon_for_qp coordinates) }
describe 'coordinates are empty' do
let(:coordinates) { '' }
it { expect(subject['geo']['type']).to eq('Polygon') }
it { expect(subject['geo']['coordinates']).to eq([coordinates]) }
end
describe 'coordinates are informed' do
let(:coordinates) { good_coordinates }
it { expect(subject['geo']['type']).to eq('Polygon') }
it { expect(subject['geo']['coordinates']).to eq([coordinates]) }
end
end
describe '.toGeoJsonPolygonForCadastre' do describe '.toGeoJsonPolygonForCadastre' do
subject { JSON.parse(described_class.to_json_polygon_for_cadastre coordinates) } subject { JSON.parse(described_class.to_json_polygon_for_cadastre coordinates) }