refactor(admin): attestation v2 fully enabled, remove useless extra query

This commit is contained in:
Colin Darie 2024-11-27 12:47:37 +01:00
parent 4eeaba5e60
commit 55c7eb422f
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 28 additions and 47 deletions

View file

@ -8,11 +8,7 @@ class Procedure::Card::AttestationComponent < ApplicationComponent
private
def edit_attestation_path
if @procedure.attestation_templates_v2.any? || @procedure.feature_enabled?(:attestation_v2)
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
else
helpers.edit_admin_procedure_attestation_template_path(@procedure)
end
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
end
def error_messages

View file

@ -6,21 +6,17 @@ describe 'As an administrateur, I want to manage the procedures attestation',
include ProcedureSpecHelper
let(:administrateur) { administrateurs(:default_admin) }
let(:procedure) do
create(:procedure, :with_service, :with_instructeur, :with_zone,
aasm_state: :brouillon,
administrateurs: [administrateur],
libelle: 'libellé de la procédure',
path: 'libelle-de-la-procedure')
before do
login_as(administrateur.user, scope: :user)
Flipper.enable(:attestation_v2) # fully enabled on prod, pending removal in code
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
end
before { login_as(administrateur.user, scope: :user) }
def find_attestation_card(with_nested_selector: nil)
attestation_path = if procedure.attestation_template&.version == 2 || procedure.feature_enabled?(:attestation_v2)
edit_admin_procedure_attestation_template_v2_path(procedure)
else
edit_admin_procedure_attestation_template_path(procedure)
end
attestation_path = edit_admin_procedure_attestation_template_v2_path(procedure)
full_selector = [
"a[href=\"#{attestation_path}\"]",
@ -29,46 +25,42 @@ describe 'As an administrateur, I want to manage the procedures attestation',
page.find(full_selector)
end
context 'Enable, publish, Disable' do
context 'Update or disable v1' do
let(:procedure) do
create(:procedure, :published,
administrateurs: [administrateur],
attestation_template: build(:attestation_template))
end
scenario do
visit admin_procedure_path(procedure)
# start with no attestation
expect(page).to have_content('Désactivée')
find_attestation_card(with_nested_selector: ".fr-badge")
expect(page).not_to have_content("Nouvel éditeur dattestation")
within find_attestation_card do
expect(page).to have_content('Activée')
click
end
within('.fr-alert--info') do
expect(page).to have_content("Nouvel éditeur dattestation")
click_on 'cliquez ici'
end
# now process to enable attestation
find_attestation_card.click
fill_in "Titre de lattestation", with: 'BOOM'
fill_in "Contenu de lattestation", with: 'BOOM'
find('.toggle-switch-control').click
click_on 'Enregistrer'
page.find(".alert-success", text: "Le modèle de lattestation a bien été enregistré")
# check attestation
visit admin_procedure_path(procedure)
expect(page).to have_content('Activée')
find_attestation_card(with_nested_selector: ".fr-badge--success")
# publish procedure
# click CTA for publication screen
click_on("Publier")
# validate publication
within('form') { click_on 'Publier' }
click_on("Revenir à la page de la démarche")
page.find(".alert-success", text: "Le modèle de lattestation a bien été modifié")
# now process to disable attestation
find_attestation_card.click
find('.toggle-switch-control').click
click_on 'Enregistrer'
page.find(".alert-success", text: "Le modèle de lattestation a bien été modifié")
# check attestation is now disabled
visit admin_procedure_path(procedure)
expect(page).to have_content('Désactivée')
find_attestation_card(with_nested_selector: ".fr-badge")
expect(page).to have_content('Désactivée')
end
end
@ -80,13 +72,6 @@ describe 'As an administrateur, I want to manage the procedures attestation',
path: 'libelle-de-la-procedure')
end
before do
Flipper.enable(:attestation_v2)
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
end
scenario do
visit admin_procedure_path(procedure)
find_attestation_card(with_nested_selector: ".fr-badge")