From 52d2ace823ace22b2f18bea5fe86695142a82104 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 9 Apr 2020 19:08:18 +0200 Subject: [PATCH] Remove quartiers prioritaires --- app/controllers/champs/carte_controller.rb | 8 ---- .../components/TypeDeChamp.js | 4 -- app/lib/api_carto/api.rb | 5 -- .../quartiers_prioritaires_adapter.rb | 15 ------ app/services/geojson_service.rb | 22 --------- .../champs/carte_controller_spec.rb | 8 ++-- .../new_administrateur/types_de_champ_spec.rb | 7 ++- spec/fixtures/files/api_carto/request_qp.json | 29 ----------- .../fixtures/files/api_carto/response_qp.json | 30 ------------ spec/lib/api_carto/api_spec.rb | 48 ------------------- .../quartiers_prioritaires_adapter_spec.rb | 36 -------------- spec/services/geojson_service_spec.rb | 18 ------- 12 files changed, 7 insertions(+), 223 deletions(-) delete mode 100644 app/lib/api_carto/quartiers_prioritaires_adapter.rb delete mode 100644 spec/fixtures/files/api_carto/request_qp.json delete mode 100644 spec/fixtures/files/api_carto/response_qp.json delete mode 100644 spec/lib/api_carto/quartiers_prioritaires_adapter_spec.rb diff --git a/app/controllers/champs/carte_controller.rb b/app/controllers/champs/carte_controller.rb index 3fdd88b7b..4459ab781 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -39,14 +39,6 @@ class Champs::CarteController < ApplicationController 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[:source] = GeoArea.sources.fetch(:selection_utilisateur) geo_areas << selection_utilisateur diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js index 5b4dc12fa..3787639e5 100644 --- a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js @@ -136,10 +136,6 @@ const TypeDeChamp = sortableElement( url={typeDeChamp.piece_justificative_template_url} /> - /.*/, - :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 subject { described_class.search_cadastre(geojson) } diff --git a/spec/lib/api_carto/quartiers_prioritaires_adapter_spec.rb b/spec/lib/api_carto/quartiers_prioritaires_adapter_spec.rb deleted file mode 100644 index 4f1988bae..000000000 --- a/spec/lib/api_carto/quartiers_prioritaires_adapter_spec.rb +++ /dev/null @@ -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 diff --git a/spec/services/geojson_service_spec.rb b/spec/services/geojson_service_spec.rb index bcd9fdea3..7a3bd7c80 100644 --- a/spec/services/geojson_service_spec.rb +++ b/spec/services/geojson_service_spec.rb @@ -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 subject { JSON.parse(described_class.to_json_polygon_for_cadastre coordinates) }