diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb index 302b8149a..0b8a328e9 100644 --- a/app/controllers/users/carte_controller.rb +++ b/app/controllers/users/carte_controller.rb @@ -32,7 +32,8 @@ class Users::CarteController < UsersController end def get_position - point = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.geo_adresse) rescue nil + etablissement = current_user_dossier.etablissement + point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) unless etablissement.nil? lon = '2.428462' lat = '46.538192' diff --git a/app/lib/carto/sgmap/api.rb b/app/lib/carto/sgmap/api.rb index 39cef144d..db29d7d0b 100644 --- a/app/lib/carto/sgmap/api.rb +++ b/app/lib/carto/sgmap/api.rb @@ -21,6 +21,9 @@ class CARTO::SGMAP::API url, verify_ssl: verify_ssl_mode, ).post params[:geojson], content_type: 'application/json' + + rescue RestClient::InternalServerError + raise RestClient::ResourceNotFound end def self.base_url diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index 65ccc2198..4ec01e39b 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -1,16 +1,16 @@ - unless smart_listing.empty? %table#dossiers_list.table %thead - %th.col-md-1.col-lg-1= smart_listing.sortable 'Numéro', 'id' - %th.col-md-5.col-lg-5= smart_listing.sortable 'Procédure', 'procedure.libelle' - %th.col-md-2.col-lg-2= smart_listing.sortable 'État', 'state' - %th.col-md-2.col-lg-2= smart_listing.sortable 'Date de mise à jour', 'updated_at' + %th#sort-id.col-md-1.col-lg-1= smart_listing.sortable 'Numéro', 'id' + %th#sort-libelle.col-md-5.col-lg-5= smart_listing.sortable 'Procédure', 'procedure.libelle' + %th#sort-state.col-md-2.col-lg-2= smart_listing.sortable 'État', 'state' + %th#sort-updated.col-md-2.col-lg-2= smart_listing.sortable 'Date de mise à jour', 'updated_at' - if @liste == "brouillon" %th.col-md-2.col-lg-2= 'Action' - @dossiers.each do |dossier| - if dossier.kind_of? Invite - -invite = dossier - -dossier = invite.dossier.decorate + - invite = dossier + - dossier = invite.dossier.decorate - else - dossier = dossier.decorate diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index f94f77b1e..438964660 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -179,6 +179,24 @@ shared_examples 'carte_controller_spec' do end describe '#get_position' do + + context 'when etablissement is nil' do + before do + dossier.update etablissement: nil + + stub_request(:get, /http:\/\/api-adresse[.]data[.]gouv[.]fr\/search[?]limit=1&q=/) + .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) + get :get_position, params: {dossier_id: dossier.id} + end + + subject { JSON.parse(response.body) } + + it 'on enregistre des coordonnées lat et lon avec les valeurs par defaut' do + expect(subject['lat']).to eq('46.538192') + expect(subject['lon']).to eq('2.428462') + end + end + context 'Geocodeur renvoie les positions par defaut' do let(:etablissement) { create(:etablissement, adresse: bad_adresse, numero_voie: 'dzj', type_voie: 'fzjfk', nom_voie: 'hdidjkz', complement_adresse: 'fjef', code_postal: 'fjeiefk', localite: 'zjfkfz') } let(:dossier) { create(:dossier, etablissement: etablissement) } diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index deeeb2acd..9a81a8ae7 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -2,20 +2,20 @@ require 'spec_helper' feature 'As a User I want to edit a dossier I own', js: true do - let(:user) { create(:user) } + let(:user) { create(:user) } let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) } before "Create dossier" do - login_as user, scope: :user - visit commencer_path(procedure_path: procedure_for_individual.path) - fill_in 'dossier_individual_attributes_nom', with: 'Nom' - fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' - fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' - find(:css, "#dossier_autorisation_donnees[value='1']").set(true) - page.find_by_id('etape_suivante').click - page.find_by_id('etape_suivante').click - page.find_by_id('suivant').click - visit root_path + login_as user, scope: :user + visit commencer_path(procedure_path: procedure_for_individual.path) + fill_in 'dossier_individual_attributes_nom', with: 'Nom' + fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' + fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' + find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + page.find_by_id('etape_suivante').click + page.find_by_id('etape_suivante').click + page.find_by_id('suivant').click + visit root_path end context 'After sign_in, I can navigate through dossiers indexes and edit a dossier' do diff --git a/spec/features/users/dossier_index_spec.rb b/spec/features/users/dossier_index_spec.rb new file mode 100644 index 000000000..2ff4fcb15 --- /dev/null +++ b/spec/features/users/dossier_index_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +feature 'As a User I want to sort and paginate dossiers', js: true do + + let(:user) { create(:user) } + let(:procedure_for_individual) { create(:procedure, :published, :for_individual) } + + before "Create dossier" do + login_as user, scope: :user + visit commencer_path(procedure_path: procedure_for_individual.path) + fill_in 'dossier_individual_attributes_nom', with: 'Nom' + fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' + fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' + find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + page.find_by_id('etape_suivante').click + page.find_by_id('suivant').click + 50.times do + Dossier.create(procedure_id: 1, user_id: 1, state: "initiated") + end + visit root_path + end + + context 'After sign_in, I can see my 51 dossiers on the index' do + + scenario 'Using sort' do + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('2') + visit "/users/dossiers?dossiers_smart_listing[sort][id]=desc" + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('51') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('50') + visit "/users/dossiers?dossiers_smart_listing[sort][id]=asc" + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('2') + end + + scenario 'Using pagination' do + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + page.find('.next_page a').click + wait_for_ajax + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('8') + page.find('.next_page a').click + wait_for_ajax + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('15') + end + end + + +end diff --git a/spec/lib/carto/sgmap/api_spec.rb b/spec/lib/carto/sgmap/api_spec.rb index fb9e5a49b..1a383a96f 100644 --- a/spec/lib/carto/sgmap/api_spec.rb +++ b/spec/lib/carto/sgmap/api_spec.rb @@ -20,6 +20,16 @@ describe CARTO::SGMAP::API do end end + context 'when request return 500' do + let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') } + let(:status) { 500 } + let(:body) { 'toto' } + + it 'raises RestClient::ResourceNotFound' do + expect { subject }.to raise_error(RestClient::ResourceNotFound) + end + end + context 'when geojson exist' do let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') } let(:status) { 200 }