an api_particulier_token change erases previous api_particulier_sources

This commit is contained in:
simon lehericey 2021-09-17 13:48:12 +02:00 committed by Pierre de La Morinerie
parent c87f3f7fb6
commit 1446660ca3
2 changed files with 3 additions and 2 deletions

View file

@ -18,8 +18,7 @@ module NewAdministrateur
flash.now.alert = t('.no_scopes_token') flash.now.alert = t('.no_scopes_token')
render :show render :show
else else
@procedure.api_particulier_scopes = scopes @procedure.update!(api_particulier_scopes: scopes, api_particulier_sources: {})
@procedure.save!
redirect_to admin_procedure_api_particulier_sources_path(procedure_id: @procedure.id), redirect_to admin_procedure_api_particulier_sources_path(procedure_id: @procedure.id),
notice: t('.token_ok') notice: t('.token_ok')

View file

@ -40,12 +40,14 @@ describe NewAdministrateur::JetonParticulierController, type: :controller do
context "and the api response is a success" do context "and the api response is a success" do
let(:cassette) { "api_particulier/success/introspect" } let(:cassette) { "api_particulier/success/introspect" }
let(:procedure) { create(:procedure, administrateur: admin, api_particulier_sources: { cnaf: { allocataires: ['noms_prenoms'] } }) }
it 'saves the jeton' do it 'saves the jeton' do
expect(flash.alert).to be_nil expect(flash.alert).to be_nil
expect(flash.notice).to eq("Le jeton a bien été mis à jour") expect(flash.notice).to eq("Le jeton a bien été mis à jour")
expect(procedure.reload.api_particulier_token).to eql(token) expect(procedure.reload.api_particulier_token).to eql(token)
expect(procedure.reload.api_particulier_scopes).to contain_exactly("dgfip_avis_imposition", "dgfip_adresse", "cnaf_allocataires", "cnaf_enfants", "cnaf_adresse", "cnaf_quotient_familial", "mesri_statut_etudiant") expect(procedure.reload.api_particulier_scopes).to contain_exactly("dgfip_avis_imposition", "dgfip_adresse", "cnaf_allocataires", "cnaf_enfants", "cnaf_adresse", "cnaf_quotient_familial", "mesri_statut_etudiant")
expect(procedure.reload.api_particulier_sources).to be_empty
end end
end end