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 // Move checkbox to the top-left side of the label
&.editable-champ-checkbox, &.editable-champ-checkbox,
// TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
&.editable-champ-engagement { &.editable-champ-engagement {
p, p,
label { label {

View file

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

View file

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

View file

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

View file

@ -41,7 +41,6 @@ class TypeDeChamp < ApplicationRecord
regions: 'regions', regions: 'regions',
departements: 'departements', departements: 'departements',
communes: 'communes', communes: 'communes',
engagement: 'engagement',
header_section: 'header_section', header_section: 'header_section',
explication: 'explication', explication: 'explication',
dossier_link: 'dossier_link', 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 class TypesDeChamp::EngagementTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
end end

View file

@ -25,6 +25,7 @@ fr:
regions: 'Régions' regions: 'Régions'
departements: 'Départements' departements: 'Départements'
communes: 'Communes' communes: 'Communes'
# TODO: remove after 20220725075951_migrate_champs_engagement_to_checkbox passed
engagement: 'Engagement' engagement: 'Engagement'
header_section: 'Titre de section' header_section: 'Titre de section'
explication: 'Explication' 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' } value { 'Paris' }
end 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 factory :champ_header_section, class: 'Champs::HeaderSectionChamp' do
type_de_champ { association :type_de_champ_header_section, procedure: dossier.procedure } type_de_champ { association :type_de_champ_header_section, procedure: dossier.procedure }
value { 'une section' } value { 'une section' }

View file

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

View file

@ -14,9 +14,9 @@ describe '20220705164551_remove_unused_champs' do
describe 'remove_unused_champs' do describe 'remove_unused_champs' do
it "with bad 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) expect(Champ.where(dossier: dossier).count).to eq(38)
run_task
expect(Champ.where(dossier: dossier).count).to eq(37)
end end
end end
end end

View file

@ -273,23 +273,6 @@ describe Champ do
it { is_expected.to eq([value]) } it { is_expected.to eq([value]) }
end 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 context 'for explication champ' do
let(:type_de_champ) { build(:type_de_champ_explication) } let(:type_de_champ) { build(:type_de_champ_explication) }
let(:value) { nil } let(:value) { nil }

View file

@ -150,25 +150,5 @@ describe ChampSerializer do
it { is_expected.to include(value: nil) } it { is_expected.to include(value: nil) }
end end
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
end end

View file

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

View file

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