2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-11-25 16:26:55 +01:00
|
|
|
|
describe Administrateurs::JetonParticulierController, type: :controller do
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:admin) { administrateurs(:default_admin) }
|
2021-09-15 11:10:28 +02:00
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin) }
|
|
|
|
|
|
|
|
|
|
before do
|
2021-09-15 10:53:09 +02:00
|
|
|
|
stub_const("API_PARTICULIER_URL", "https://particulier.api.gouv.fr/api")
|
|
|
|
|
|
2021-09-15 11:10:28 +02:00
|
|
|
|
sign_in(admin.user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET #api_particulier" do
|
|
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
subject { get :api_particulier, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
2021-09-17 13:43:23 +02:00
|
|
|
|
it do
|
|
|
|
|
is_expected.to have_http_status(:success)
|
|
|
|
|
expect(subject.body).to have_content('Jeton API particulier')
|
|
|
|
|
end
|
2021-09-15 11:10:28 +02:00
|
|
|
|
end
|
2021-09-15 10:53:09 +02:00
|
|
|
|
|
|
|
|
|
describe "GET #show" do
|
|
|
|
|
subject { get :show, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(:success) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "PATCH #update" do
|
|
|
|
|
let(:params) { { procedure_id: procedure.id, procedure: { api_particulier_token: token } } }
|
|
|
|
|
|
|
|
|
|
subject { patch :update, params: params }
|
|
|
|
|
|
|
|
|
|
context "when jeton has a valid shape" do
|
|
|
|
|
let(:token) { "d7e9c9f4c3ca00caadde31f50fd4521a" }
|
|
|
|
|
before do
|
|
|
|
|
VCR.use_cassette(cassette) do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "and the api response is a success" do
|
|
|
|
|
let(:cassette) { "api_particulier/success/introspect" }
|
2021-09-21 11:01:04 +02:00
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin, api_particulier_sources: { cnaf: { allocataires: ['nomPrenom'] } }) }
|
2021-09-15 10:53:09 +02:00
|
|
|
|
|
2021-09-17 13:43:23 +02:00
|
|
|
|
it 'saves the jeton' do
|
|
|
|
|
expect(flash.alert).to be_nil
|
|
|
|
|
expect(flash.notice).to eq("Le jeton a bien été mis à jour")
|
2021-11-24 17:30:35 +01:00
|
|
|
|
procedure.reload
|
|
|
|
|
expect(procedure.api_particulier_token).to eql(token)
|
|
|
|
|
expect(procedure.api_particulier_scopes).to contain_exactly(
|
|
|
|
|
'cnaf_adresse',
|
|
|
|
|
'cnaf_allocataires',
|
|
|
|
|
'cnaf_enfants',
|
|
|
|
|
'cnaf_quotient_familial',
|
|
|
|
|
'dgfip_adresse_fiscale_annee',
|
|
|
|
|
'dgfip_adresse_fiscale_taxation',
|
|
|
|
|
'dgfip_annee_impot',
|
|
|
|
|
'dgfip_annee_revenus',
|
|
|
|
|
'dgfip_date_etablissement',
|
|
|
|
|
'dgfip_date_recouvrement',
|
|
|
|
|
'dgfip_declarant1_date_naissance',
|
|
|
|
|
'dgfip_declarant1_nom',
|
|
|
|
|
'dgfip_declarant1_nom_naissance',
|
|
|
|
|
'dgfip_declarant1_prenoms',
|
|
|
|
|
'dgfip_declarant2_date_naissance',
|
|
|
|
|
'dgfip_declarant2_nom',
|
|
|
|
|
'dgfip_declarant2_nom_naissance',
|
|
|
|
|
'dgfip_declarant2_prenoms',
|
|
|
|
|
'dgfip_erreur_correctif',
|
|
|
|
|
'dgfip_impot_revenu_net_avant_corrections',
|
|
|
|
|
'dgfip_montant_impot',
|
|
|
|
|
'dgfip_nombre_parts',
|
|
|
|
|
'dgfip_nombre_personnes_a_charge',
|
|
|
|
|
'dgfip_revenu_brut_global',
|
|
|
|
|
'dgfip_revenu_fiscal_reference',
|
|
|
|
|
'dgfip_revenu_imposable',
|
|
|
|
|
'dgfip_situation_familiale',
|
2021-12-01 10:21:30 +01:00
|
|
|
|
'dgfip_situation_partielle',
|
|
|
|
|
'pole_emploi_identite',
|
|
|
|
|
'pole_emploi_adresse',
|
|
|
|
|
'pole_emploi_contact',
|
2021-12-15 15:25:02 +01:00
|
|
|
|
'pole_emploi_inscription',
|
|
|
|
|
'mesri_identifiant',
|
|
|
|
|
'mesri_identite',
|
|
|
|
|
'mesri_inscription_etudiant',
|
|
|
|
|
'mesri_inscription_autre',
|
|
|
|
|
'mesri_admission',
|
|
|
|
|
'mesri_etablissements'
|
2021-11-24 17:30:35 +01:00
|
|
|
|
)
|
|
|
|
|
expect(procedure.api_particulier_sources).to be_empty
|
2021-09-17 13:43:23 +02:00
|
|
|
|
end
|
2021-09-15 10:53:09 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-09-16 09:09:26 +02:00
|
|
|
|
context "and the api response is a success but with an empty scopes" do
|
|
|
|
|
let(:cassette) { "api_particulier/success/introspect_empty_scopes" }
|
|
|
|
|
|
2021-09-17 13:43:23 +02:00
|
|
|
|
it 'rejects the jeton' do
|
2022-12-01 13:41:12 +01:00
|
|
|
|
expect(flash.alert).to include("le jeton n’a pas acces aux données")
|
2021-09-17 13:43:23 +02:00
|
|
|
|
expect(flash.notice).to be_nil
|
|
|
|
|
expect(procedure.reload.api_particulier_token).not_to eql(token)
|
|
|
|
|
end
|
2021-09-16 09:09:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
2021-09-15 10:53:09 +02:00
|
|
|
|
context "and the api response is not unauthorized" do
|
|
|
|
|
let(:cassette) { "api_particulier/unauthorized/introspect" }
|
|
|
|
|
|
2021-09-17 13:43:23 +02:00
|
|
|
|
it 'rejects the jeton' do
|
2023-06-08 10:03:34 +02:00
|
|
|
|
expect(flash.alert).to include("Mise à jour impossible : le jeton n’a pas été trouvé ou n’est pas actif")
|
2021-09-17 13:43:23 +02:00
|
|
|
|
expect(flash.notice).to be_nil
|
|
|
|
|
expect(procedure.reload.api_particulier_token).not_to eql(token)
|
|
|
|
|
end
|
2021-09-15 10:53:09 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-09-16 09:09:26 +02:00
|
|
|
|
context "when jeton is invalid and no network call is made" do
|
2021-09-15 10:53:09 +02:00
|
|
|
|
let(:token) { "jet0n 1nvalide" }
|
|
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
2021-09-17 13:43:23 +02:00
|
|
|
|
it 'rejects the jeton' do
|
|
|
|
|
expect(flash.alert.first).to include("pas le bon format")
|
|
|
|
|
expect(flash.notice).to be_nil
|
|
|
|
|
expect(procedure.reload.api_particulier_token).not_to eql(token)
|
|
|
|
|
end
|
2021-09-15 10:53:09 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-09-15 11:10:28 +02:00
|
|
|
|
end
|