chore(spec): fix commune spec
This commit is contained in:
parent
f274748acd
commit
00fc2f519f
7 changed files with 208 additions and 28 deletions
46
spec/fixtures/cassettes/api_geo_all.yml
vendored
46
spec/fixtures/cassettes/api_geo_all.yml
vendored
File diff suppressed because one or more lines are too long
50
spec/fixtures/cassettes/api_geo_communes.yml
vendored
50
spec/fixtures/cassettes/api_geo_communes.yml
vendored
File diff suppressed because one or more lines are too long
79
spec/fixtures/cassettes/graphql_communes.yml
vendored
Normal file
79
spec/fixtures/cassettes/graphql_communes.yml
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -26,7 +26,7 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'dossier with champs' do
|
||||
describe 'dossier with champs', vcr: { cassette_name: 'graphql_communes' } do
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }, { type: :address }, { type: :siret }]) }
|
||||
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
|
||||
let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
|
||||
|
|
|
@ -1,19 +1,43 @@
|
|||
describe Champs::CommuneChamp do
|
||||
let(:type_de_champ) { create(:type_de_champ_communes, libelle: 'Ma commune') }
|
||||
let(:champ) { Champs::CommuneChamp.new(value: value, external_id: code_insee, departement: departement, code_departement: code_departement, type_de_champ: type_de_champ) }
|
||||
let(:value) { 'Châteldon (63290)' }
|
||||
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
|
||||
|
||||
before do
|
||||
allow(Rails).to receive(:cache).and_return(memory_store)
|
||||
Rails.cache.clear
|
||||
end
|
||||
|
||||
let(:code_insee) { '63102' }
|
||||
let(:departement) { '' }
|
||||
let(:code_departement) { '' }
|
||||
let(:code_postal) { '63290' }
|
||||
let(:code_departement) { '63' }
|
||||
|
||||
it { expect(champ.value).to eq('Châteldon (63290)') }
|
||||
it { expect(champ.external_id).to eq('63102') }
|
||||
it { expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '']) }
|
||||
describe 'value', vcr: { cassette_name: 'api_geo_communes' } do
|
||||
let(:champ) { create(:champ_communes, code_postal: code_postal) }
|
||||
|
||||
context do
|
||||
let(:departement) { 'Puy-de-Dôme' }
|
||||
let(:code_departement) { '63' }
|
||||
it 'with code_postal' do
|
||||
champ.update(value: code_insee)
|
||||
expect(champ.name).to eq('Châteldon (63290)')
|
||||
expect(champ.external_id).to eq(code_insee)
|
||||
expect(champ.code).to eq(code_insee)
|
||||
expect(champ.code_departement).to eq(code_departement)
|
||||
expect(champ.code_postal).to eq(code_postal)
|
||||
expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 – Puy-de-Dôme'])
|
||||
expect(champ.communes.size).to eq(8)
|
||||
end
|
||||
|
||||
it { expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 - Puy-de-Dôme']) }
|
||||
context 'when code_postal is nil', vcr: { cassette_name: 'api_geo_communes' } do
|
||||
let(:champ) { create(:champ_communes, external_id: code_insee, code_departement:) }
|
||||
|
||||
it 'with value' do
|
||||
champ.update_column(:value, 'Châteldon (63290)')
|
||||
expect(champ.name).to eq('Châteldon (63290)')
|
||||
expect(champ.external_id).to eq(code_insee)
|
||||
expect(champ.code).to eq(code_insee)
|
||||
expect(champ.code_departement).to eq(code_departement)
|
||||
expect(champ.code_postal).to be_nil
|
||||
expect(champ.code_postal_with_fallback).to eq(code_postal)
|
||||
expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 – Puy-de-Dôme'])
|
||||
expect(champ.communes.size).to eq(8)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1573,7 +1573,7 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe "champs_for_export" do
|
||||
describe "champs_for_export", vcr: { cassette_name: 'api_geo_communes' } do
|
||||
context 'with a unconditionnal procedure' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication, :with_commune, :with_repetition, zones: [create(:zone)]) }
|
||||
let(:text_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
|
||||
|
|
|
@ -44,8 +44,8 @@ describe 'The user' do
|
|||
select('Australie', from: form_id_for('pays'))
|
||||
select('Martinique', from: form_id_for('regions'))
|
||||
select('02 – Aisne', from: form_id_for('departements'))
|
||||
select_combobox('communes', 'Ai', '02 - Aisne', check: false)
|
||||
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
|
||||
fill_in('Code postal de la commune', with: '60400')
|
||||
select('Brétigny (60400)', from: form_id_for('communes'))
|
||||
|
||||
fill_in('dossier_link', with: '123')
|
||||
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
|
||||
|
@ -74,7 +74,7 @@ describe 'The user' do
|
|||
expect(champ_value_for('pays')).to eq('Australie')
|
||||
expect(champ_value_for('regions')).to eq('Martinique')
|
||||
expect(champ_value_for('departements')).to eq('Aisne')
|
||||
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
|
||||
expect(champ_value_for('communes')).to eq('Brétigny')
|
||||
expect(champ_value_for('dossier_link')).to eq('123')
|
||||
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
|
||||
|
||||
|
@ -98,7 +98,8 @@ describe 'The user' do
|
|||
expect(page).to have_selected_value('regions', selected: 'Martinique')
|
||||
expect(page).to have_selected_value('departements', selected: '02 – Aisne')
|
||||
check_selected_value('multiple_choice_drop_down_list_long', with: ['alpha', 'charly'])
|
||||
check_selected_value('communes', with: 'Ambléon (01300)')
|
||||
expect(page).to have_selected_value('communes', selected: 'Brétigny (60400)')
|
||||
expect(page).to have_selected_value('pays', selected: 'Australie')
|
||||
expect(page).to have_field('dossier_link', with: '123')
|
||||
expect(page).to have_text('file.pdf')
|
||||
expect(page).to have_text('Analyse antivirus en cours')
|
||||
|
|
Loading…
Reference in a new issue