clean(Champs::Engagement): migrate to Champs::Checkbox, some for TypeDeChamp

This commit is contained in:
Martin 2022-07-25 10:24:17 +02:00
parent 19eca6b5a1
commit 17ed80b18a
15 changed files with 51 additions and 103 deletions

View file

@ -82,6 +82,7 @@
// Move checkbox to the top-left side of the label
&.editable-champ-checkbox,
// TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
&.editable-champ-engagement {
p,
label {

View file

@ -59,8 +59,7 @@ module Mutations
when :checkbox
[
TypeDeChamp.type_champs.fetch(:checkbox),
TypeDeChamp.type_champs.fetch(:yes_no),
TypeDeChamp.type_champs.fetch(:engagement)
TypeDeChamp.type_champs.fetch(:yes_no)
]
when :date
TypeDeChamp.type_champs.fetch(:date)

View file

@ -2135,11 +2135,6 @@ enum TypeDeChamp {
"""
email
"""
Engagement
"""
engagement
"""
Explication
"""

View file

@ -1,3 +1,4 @@
# TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
# == Schema Information
#
# Table name: champs

View file

@ -41,7 +41,6 @@ class TypeDeChamp < ApplicationRecord
regions: 'regions',
departements: 'departements',
communes: 'communes',
engagement: 'engagement',
header_section: 'header_section',
explication: 'explication',
dossier_link: 'dossier_link',

View file

@ -1,2 +1,3 @@
# TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
class TypesDeChamp::EngagementTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
end

View file

@ -25,6 +25,7 @@ fr:
regions: 'Régions'
departements: 'Départements'
communes: 'Communes'
# TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
engagement: 'Engagement'
header_section: 'Titre de section'
explication: 'Explication'

View file

@ -0,0 +1,18 @@
namespace :after_party do
desc 'Deployment task: migrate_champs_engagement_to_checkbox'
task migrate_champs_engagement_to_checkbox: :environment do
puts "Running deploy task 'migrate_champs_engagement_to_checkbox'"
TypeDeChamp.where(type_champ: 'engagement').in_batches do |relation_type_de_champs|
relation_type_de_champs.update_all(type_champ: 'checkbox')
Champ.where(type_de_champ: relation_type_de_champs).in_batches do |relation_champs|
relation_champs.update_all(type: 'Champs::CheckboxChamp')
end
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -125,11 +125,6 @@ FactoryBot.define do
value { 'Paris' }
end
factory :champ_engagement, class: 'Champs::EngagementChamp' do
type_de_champ { association :type_de_champ_engagement, procedure: dossier.procedure }
value { 'true' }
end
factory :champ_header_section, class: 'Champs::HeaderSectionChamp' do
type_de_champ { association :type_de_champ_header_section, procedure: dossier.procedure }
value { 'une section' }

View file

@ -111,9 +111,6 @@ FactoryBot.define do
factory :type_de_champ_communes do
type_champ { TypeDeChamp.type_champs.fetch(:communes) }
end
factory :type_de_champ_engagement do
type_champ { TypeDeChamp.type_champs.fetch(:engagement) }
end
factory :type_de_champ_header_section do
type_champ { TypeDeChamp.type_champs.fetch(:header_section) }
end

View file

@ -14,9 +14,9 @@ describe '20220705164551_remove_unused_champs' do
describe 'remove_unused_champs' do
it "with bad champs" do
expect(Champ.where(dossier: dossier).count).to eq(39)
run_task
expect(Champ.where(dossier: dossier).count).to eq(38)
run_task
expect(Champ.where(dossier: dossier).count).to eq(37)
end
end
end

View file

@ -273,23 +273,6 @@ describe Champ do
it { is_expected.to eq([value]) }
end
context 'for engagement champ' do
let(:libelle) { 'je consens' }
let(:type_de_champ) { build(:type_de_champ_engagement, libelle: libelle) }
context 'when the box is checked' do
let(:value) { 'on' }
it { is_expected.to eq([libelle]) }
end
context 'when the box is unchecked' do
let(:value) { 'off' }
it { is_expected.to be_nil }
end
end
context 'for explication champ' do
let(:type_de_champ) { build(:type_de_champ_explication) }
let(:value) { nil }

View file

@ -150,25 +150,5 @@ describe ChampSerializer do
it { is_expected.to include(value: nil) }
end
end
context 'when type champ engagement' do
context 'on' do
let(:champ) { create(:champ_engagement, value: 'on') }
it { is_expected.to include(value: 'on') }
end
context 'off' do
let(:champ) { create(:champ_engagement, value: 'off') }
it { is_expected.to include(value: 'off') }
end
context 'nil' do
let(:champ) { create(:champ_engagement, value: nil) }
it { is_expected.to include(value: nil) }
end
end
end
end

View file

@ -70,7 +70,6 @@ describe ProcedureExportService do
"communes",
"communes (Code insee)",
"communes (Département)",
"engagement",
"dossier_link",
"piece_justificative",
"siret",
@ -162,7 +161,6 @@ describe ProcedureExportService do
"communes",
"communes (Code insee)",
"communes (Département)",
"engagement",
"dossier_link",
"piece_justificative",
"siret",
@ -249,7 +247,6 @@ describe ProcedureExportService do
"communes",
"communes (Code insee)",
"communes (Département)",
"engagement",
"dossier_link",
"piece_justificative",
"siret",

View file

@ -39,55 +39,37 @@ describe 'The user' do
select_combobox('communes', 'Ai', '02 - Aisne', check: false)
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
check('engagement')
fill_in('dossier_link', with: dossier_to_link.id)
fill_in('dossier_link', with: '123')
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
expect(page).to have_css('span', text: 'Votre brouillon est automatiquement enregistré', visible: true)
blur
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
# check data on the dossier from db
# Sometimes, `user_dossier.champs` are not yet all updated with the new values
# when we first load `user_dossier`, causing random errors.
# Strategy is to retry & reload them if necessary for a few seconds,
# and raise expectation error instead of timeout error.
last_expection_error = nil
begin
Timeout.timeout(Capybara.default_max_wait_time) do
expect(user_dossier).to be_brouillon
expect(champ_value_for('text')).to eq('super texte')
expect(champ_value_for('textarea')).to eq('super textarea')
expect(champ_value_for('date')).to eq('2012-12-12')
expect(champ_value_for('datetime')).to eq('06/01/2030 07:05')
expect(champ_value_for('number')).to eq('42')
expect(champ_value_for('decimal_number')).to eq('17')
expect(champ_value_for('integer_number')).to eq('12')
expect(champ_value_for('checkbox')).to eq('on')
expect(champ_value_for('civilite')).to eq('Mme')
expect(champ_value_for('email')).to eq('loulou@yopmail.com')
expect(champ_value_for('phone')).to eq('0123456789')
expect(champ_value_for('yes_no')).to eq('false')
expect(champ_value_for('simple_drop_down_list')).to eq('val2')
expect(champ_value_for('simple_choice_drop_down_list_long')).to eq('bravo')
expect(JSON.parse(champ_value_for('multiple_choice_drop_down_list_long'))).to match(['alpha', 'charly'])
expect(JSON.parse(champ_value_for('multiple_drop_down_list'))).to match(['val1', 'val3'])
expect(champ_value_for('pays')).to eq('Australie')
expect(champ_value_for('regions')).to eq('Martinique')
expect(champ_value_for('departements')).to eq('02 - Aisne')
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
expect(champ_value_for('engagement')).to eq('on')
expect(champ_value_for('dossier_link')).to eq(dossier_to_link.id.to_s)
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
rescue RSpec::Expectations::ExpectationNotMetError => e
Rails.logger.debug "Error #{e.message.tr("\n", " ")}, will retry"
last_expection_error = e
sleep(0.1)
retry
end
rescue Timeout::Error => e
raise last_expection_error || e
end
# check data on the dossier
expect(user_dossier.brouillon?).to be true
expect(champ_value_for('text')).to eq('super texte')
expect(champ_value_for('textarea')).to eq('super textarea')
expect(champ_value_for('date')).to eq('2012-12-12')
expect(champ_value_for('datetime')).to eq('06/01/2030 07:05')
expect(champ_value_for('number')).to eq('42')
expect(champ_value_for('decimal_number')).to eq('17')
expect(champ_value_for('integer_number')).to eq('12')
expect(champ_value_for('checkbox')).to eq('on')
expect(champ_value_for('civilite')).to eq('Mme')
expect(champ_value_for('email')).to eq('loulou@yopmail.com')
expect(champ_value_for('phone')).to eq('0123456789')
expect(champ_value_for('yes_no')).to eq('false')
expect(champ_value_for('simple_drop_down_list')).to eq('val2')
expect(champ_value_for('simple_choice_drop_down_list_long')).to eq('bravo')
expect(JSON.parse(champ_value_for('multiple_choice_drop_down_list_long'))).to match(['alpha', 'charly'])
expect(JSON.parse(champ_value_for('multiple_drop_down_list'))).to match(['val1', 'val3'])
expect(champ_value_for('pays')).to eq('Australie')
expect(champ_value_for('regions')).to eq('Martinique')
expect(champ_value_for('departements')).to eq('02 - Aisne')
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
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
## check data on the gui
@ -110,8 +92,7 @@ describe 'The user' do
check_selected_value('regions', with: 'Martinique')
check_selected_value('departements', with: '02 - Aisne')
check_selected_value('communes', with: 'Ambléon (01300)')
expect(page).to have_checked_field('engagement')
expect(page).to have_field('dossier_link', with: dossier_to_link.id.to_s)
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')
end