- Correction des tests suite à la modification du schéma de la base de données.

This commit is contained in:
Xavier J 2015-09-21 17:59:03 +02:00
parent 5f3a320f2f
commit b3383bec9f
51 changed files with 462 additions and 585 deletions

View file

@ -1,106 +1,108 @@
require 'spec_helper'
RSpec.describe CarteController, type: :controller do
let(:bad_adresse) { 'babouba' }
#NOT USED ACTUALY
let(:dossier) { create(:dossier) }
let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
let(:ref_dossier) { 'IATRQPQY' }
let(:adresse) { etablissement.adresse }
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
it 'redirection vers start si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to(controller: :start, action: :error_dossier)
end
end
describe 'POST #save_ref_api_carto' do
context 'Aucune localisation n\'a jamais été enregistrée' do
it do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier, back_url: ''
expect(response).to redirect_to("/dossiers/#{dossier_id}/description")
end
end
context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, ref_dossier: ref_dossier) }
before do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier
end
context 'Enregistrement d\'un commentaire informant la modification' do
subject { dossier.commentaires.last }
it 'champs email' do
expect(subject.email).to eq('Modification localisation')
end
it 'champs body' do
expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
end
it 'champs dossier' do
expect(subject.dossier.id).to eq(dossier_id)
end
end
it 'Redirection vers la page récapitulatif' do
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
end
end
end
describe '#get_position' do
context 'Geocodeur renvoie des positions nil' do
let(:etablissement) { create(:etablissement, adresse: bad_adresse) }
let(:dossier) { create(:dossier, etablissement: etablissement) }
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}")
.to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
get :get_position, dossier_id: dossier.id
end
subject { dossier.reload }
it 'on enregistre des coordonnées lat et lon à 0' do
expect(subject.position_lat).to eq('0')
expect(subject.position_lon).to eq('0')
end
end
context 'retour d\'un fichier JSON avec 3 attributs' do
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}")
.to_return(status: 200, body: '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
get :get_position, dossier_id: dossier_id
end
subject { JSON.parse(response.body) }
it 'format JSON valide' do
expect(response.content_type).to eq('application/json')
end
it 'latitude' do
expect(subject['lat']).to eq('48.870374')
end
it 'longitude' do
expect(subject['lon']).to eq('2.306888')
end
it 'dossier_id' do
expect(subject['dossier_id']).to eq(dossier.id.to_s)
end
end
end
# let(:bad_adresse) { 'babouba' }
#
# let(:dossier) { create(:dossier) }
# let!(:entreprise) { create(:entreprise, dossier: dossier) }
# let!(:etablissement) { create(:etablissement, dossier: dossier) }
# let(:dossier_id) { dossier.id }
# let(:bad_dossier_id) { Dossier.count + 10 }
# let(:ref_dossier) { 'IATRQPQY' }
# let(:adresse) { etablissement.adresse }
#
# describe 'GET #show' do
# it 'returns http success' do
# get :show, dossier_id: dossier_id
# expect(response).to have_http_status(:success)
# end
#
# it 'redirection vers start si mauvais dossier ID' do
# get :show, dossier_id: bad_dossier_id
# expect(response).to redirect_to(controller: :start, action: :error_dossier)
# end
# end
#
# describe 'POST #save_ref_api_carto' do
# context 'Aucune localisation n\'a jamais été enregistrée' do
# it do
# post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier, back_url: ''
# expect(response).to redirect_to("/dossiers/#{dossier_id}/description")
# end
# end
#
# context 'En train de modifier la localisation' do
# let(:dossier) { create(:dossier, ref_dossier: ref_dossier) }
# before do
# post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier
# end
#
# context 'Enregistrement d\'un commentaire informant la modification' do
# subject { dossier.commentaires.last }
#
# it 'champs email' do
# expect(subject.email).to eq('Modification localisation')
# end
#
# it 'champs body' do
# expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
# end
#
# it 'champs dossier' do
# expect(subject.dossier.id).to eq(dossier_id)
# end
# end
#
# it 'Redirection vers la page récapitulatif' do
# expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
# end
# end
# end
#
# describe '#get_position' do
# context 'Geocodeur renvoie des positions nil' do
# let(:etablissement) { create(:etablissement, adresse: bad_adresse) }
# let(:dossier) { create(:dossier, etablissement: etablissement) }
# before do
# stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}")
# .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
# get :get_position, dossier_id: dossier.id
# end
#
# subject { dossier.reload }
#
# it 'on enregistre des coordonnées lat et lon à 0' do
# expect(subject.position_lat).to eq('0')
# expect(subject.position_lon).to eq('0')
# end
# end
#
# context 'retour d\'un fichier JSON avec 3 attributs' do
# before do
# stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}")
# .to_return(status: 200, body: '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
#
# get :get_position, dossier_id: dossier_id
# end
# subject { JSON.parse(response.body) }
#
# it 'format JSON valide' do
# expect(response.content_type).to eq('application/json')
# end
#
# it 'latitude' do
# expect(subject['lat']).to eq('48.870374')
# end
#
# it 'longitude' do
# expect(subject['lon']).to eq('2.306888')
# end
#
# it 'dossier_id' do
# expect(subject['dossier_id']).to eq(dossier.id.to_s)
# end
# end
# end
end

View file

@ -1,29 +0,0 @@
require 'spec_helper'
RSpec.describe DemandesController, type: :controller do
let(:dossier) { create(:dossier, formulaire_id: '') }
let(:dossier_id) { dossier.id }
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
end
describe 'POST #upated' do
context 'when dossier is not linked to formulaire' do
it 'redirect to carte controller' do
post :update, dossier_id: dossier_id, formulaire: '1'
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier_id)
end
end
context 'when dossier is already linked to formaulaire' do
let(:dossier) { create(:dossier) }
subject { post :update, dossier_id: dossier_id, formulaire: '1' }
it 'raise error' do
expect { subject }.to raise_error("La modification du formulaire n'est pas possible")
end
end
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe DescriptionController, type: :controller do
let(:dossier) { create(:dossier) }
let(:dossier) { create(:dossier, :with_procedure) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
@ -26,13 +26,13 @@ describe DescriptionController, type: :controller do
let(:date_previsionnelle) { '20/01/2016' }
let(:mail_contact) { 'test@test.com' }
let(:name_piece_jointe) { 'dossierPDF.pdf' }
let(:name_piece_jointe_103) { 'piece_jointe_103.pdf' }
let(:name_piece_jointe_692) { 'piece_jointe_692.pdf' }
let(:name_piece_justificative) { 'dossierPDF.pdf' }
let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' }
let(:name_piece_justificative_1) { 'piece_justificative_1.pdf' }
let(:cerfa_pdf) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe}", 'application/pdf') }
let(:piece_jointe_103) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_103}", 'application/pdf') }
let(:piece_jointe_692) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_692}", 'application/pdf') }
let(:cerfa_pdf) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative}", 'application/pdf') }
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_0}", 'application/pdf') }
let(:piece_justificative_1) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_1}", 'application/pdf') }
context 'Tous les attributs sont bons' do
# TODO separer en deux tests : check donnees et check redirect
@ -143,7 +143,7 @@ describe DescriptionController, type: :controller do
context 'un CERFA PDF est envoyé' do
subject { dossier.cerfa }
it 'content' do
expect(subject['content']).to eq(name_piece_jointe)
expect(subject['content']).to eq(name_piece_justificative)
end
it 'dossier_id' do
@ -154,7 +154,7 @@ describe DescriptionController, type: :controller do
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
it 'il n\'y a qu\'un CERFA PDF par dossier' do
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact, cerfa_pdf: cerfa_pdf
cerfa = PieceJointe.where(type_piece_jointe_id: '0', dossier_id: dossier_id)
cerfa = PieceJustificative.where(type_de_piece_justificative_id: '0', dossier_id: dossier_id)
expect(cerfa.many?).to eq(false)
end
end
@ -164,26 +164,27 @@ describe DescriptionController, type: :controller do
end
end
context 'Sauvegarde des pièces jointes' do
context 'Sauvegarde des pièces justificatives' do
let(:all_pj_type){ dossier.procedure.type_de_piece_justificative_ids }
before do
post :create, dossier_id: dossier_id,
post :create, {dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
montant_projet: montant_projet,
montant_aide_demande: montant_aide_demande,
date_previsionnelle: date_previsionnelle,
mail_contact: mail_contact,
piece_jointe_692: piece_jointe_692,
piece_jointe_103: piece_jointe_103
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
dossier.reload
end
context 'for piece 692' do
subject { dossier.retrieve_piece_jointe_by_type 692 }
context 'for piece 0' do
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[0].to_s }
it { expect(subject.content).not_to be_nil }
end
context 'for piece 103' do
subject { dossier.retrieve_piece_jointe_by_type 103 }
context 'for piece 1' do
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[1].to_s }
it { expect(subject.content).not_to be_nil }
end
end