feat(api particulier): add DGFIP support to sources service

This commit is contained in:
François Vantomme 2021-11-10 14:24:50 +01:00 committed by simon lehericey
parent 8ca8bdb6c4
commit 97de7c197d
2 changed files with 76 additions and 4 deletions

View file

@ -10,7 +10,7 @@ module APIParticulier
.map { |provider_and_scope| raw_scopes[provider_and_scope] }
.compact
.map { |provider, scope| extract_sources(provider, scope) }
.reduce({}) { |acc, el| acc.deep_merge(el) }
.reduce({}) { |acc, el| acc.deep_merge(el) { |_, this_val, other_val| this_val + other_val } }
end
# Remove sources not available for the procedure
@ -38,7 +38,14 @@ module APIParticulier
end
def extract_sources(provider, scope)
{ provider => { scope => providers[provider][scope] } }
provider_scope_value = providers[provider][scope]
case provider_scope_value
when Hash
{ provider => provider_scope_value }
else
{ provider => { scope => Array(provider_scope_value) } }
end
end
def raw_scopes
@ -46,7 +53,31 @@ module APIParticulier
'cnaf_allocataires' => ['cnaf', 'allocataires'],
'cnaf_enfants' => ['cnaf', 'enfants'],
'cnaf_adresse' => ['cnaf', 'adresse'],
'cnaf_quotient_familial' => ['cnaf', 'quotient_familial']
'cnaf_quotient_familial' => ['cnaf', 'quotient_familial'],
'dgfip_declarant1_nom' => ['dgfip', 'declarant1_nom'],
'dgfip_declarant1_nom_naissance' => ['dgfip', 'declarant1_nom_naissance'],
'dgfip_declarant1_prenoms' => ['dgfip', 'declarant1_prenoms'],
'dgfip_declarant1_date_naissance' => ['dgfip', 'declarant1_date_naissance'],
'dgfip_declarant2_nom' => ['dgfip', 'declarant2_nom'],
'dgfip_declarant2_nom_naissance' => ['dgfip', 'declarant2_nom_naissance'],
'dgfip_declarant2_prenoms' => ['dgfip', 'declarant2_prenoms'],
'dgfip_declarant2_date_naissance' => ['dgfip', 'declarant2_date_naissance'],
'dgfip_date_recouvrement' => ['dgfip', 'date_recouvrement'],
'dgfip_date_etablissement' => ['dgfip', 'date_etablissement'],
'dgfip_adresse_fiscale_taxation' => ['dgfip', 'adresse_fiscale_taxation'],
'dgfip_adresse_fiscale_annee' => ['dgfip', 'adresse_fiscale_annee'],
'dgfip_nombre_parts' => ['dgfip', 'nombre_parts'],
'dgfip_nombre_personnes_a_charge' => ['dgfip', 'nombre_personnes_a_charge'],
'dgfip_situation_familiale' => ['dgfip', 'situation_familiale'],
'dgfip_revenu_brut_global' => ['dgfip', 'revenu_brut_global'],
'dgfip_revenu_imposable' => ['dgfip', 'revenu_imposable'],
'dgfip_impot_revenu_net_avant_corrections' => ['dgfip', 'impot_revenu_net_avant_corrections'],
'dgfip_montant_impot' => ['dgfip', 'montant_impot'],
'dgfip_revenu_fiscal_reference' => ['dgfip', 'revenu_fiscal_reference'],
'dgfip_annee_impot' => ['dgfip', 'annee_impot'],
'dgfip_annee_revenus' => ['dgfip', 'annee_revenus'],
'dgfip_erreur_correctif' => ['dgfip', 'erreur_correctif'],
'dgfip_situation_partielle' => ['dgfip', 'situation_partielle']
}
end
@ -57,6 +88,32 @@ module APIParticulier
'enfants' => ['nomPrenom', 'dateDeNaissance', 'sexe'],
'adresse' => ['identite', 'complementIdentite', 'complementIdentiteGeo', 'numeroRue', 'lieuDit', 'codePostalVille', 'pays'],
'quotient_familial' => ['quotientFamilial', 'annee', 'mois']
},
'dgfip' => {
'declarant1_nom' => { 'declarant1' => ['nom'] },
'declarant1_nom_naissance' => { 'declarant1' => ['nomNaissance'] },
'declarant1_prenoms' => { 'declarant1' => ['prenoms'] },
'declarant1_date_naissance' => { 'declarant1' => ['dateNaissance'] },
'declarant2_nom' => { 'declarant2' => ['nom'] },
'declarant2_nom_naissance' => { 'declarant2' => ['nomNaissance'] },
'declarant2_prenoms' => { 'declarant2' => ['prenoms'] },
'declarant2_date_naissance' => { 'declarant2' => ['dateNaissance'] },
'date_recouvrement' => { 'echeance_avis' => ['dateRecouvrement'] },
'date_etablissement' => { 'echeance_avis' => ['dateEtablissement'] },
'adresse_fiscale_taxation' => { 'foyer_fiscal' => ['adresse'] },
'adresse_fiscale_annee' => { 'foyer_fiscal' => ['annee'] },
'nombre_parts' => { 'foyer_fiscal' => ['nombreParts'] },
'nombre_personnes_a_charge' => { 'foyer_fiscal' => ['nombrePersonnesCharge'] },
'situation_familiale' => { 'foyer_fiscal' => ['situationFamille'] },
'revenu_brut_global' => { 'agregats_fiscaux' => ['revenuBrutGlobal'] },
'revenu_imposable' => { 'agregats_fiscaux' => ['revenuImposable'] },
'impot_revenu_net_avant_corrections' => { 'agregats_fiscaux' => ['impotRevenuNetAvantCorrections'] },
'montant_impot' => { 'agregats_fiscaux' => ['montantImpot'] },
'revenu_fiscal_reference' => { 'agregats_fiscaux' => ['revenuFiscalReference'] },
'annee_impot' => { 'agregats_fiscaux' => ['anneeImpots'] },
'annee_revenus' => { 'agregats_fiscaux' => ['anneeRevenus'] },
'erreur_correctif' => { 'complements' => ['erreurCorrectif'] },
'situation_partielle' => { 'complements' => ['situationPartielle'] }
}
}
end

View file

@ -17,7 +17,7 @@ describe APIParticulier::Services::SourcesService do
it { is_expected.to eq({}) }
end
context 'when a procedure has a cnaf_allocataires and a cnaf_adresse scopes' do
context 'when a procedure has a cnaf_allocataires and a cnaf_enfants scopes' do
let(:api_particulier_scopes) { ['cnaf_allocataires', 'cnaf_enfants'] }
let(:cnaf_allocataires_and_enfants) do
@ -32,6 +32,21 @@ describe APIParticulier::Services::SourcesService do
it { is_expected.to match(cnaf_allocataires_and_enfants) }
end
context 'when a procedure has a dgfip_declarant1_nom , prenom and a dgfip_adresse_fiscale_taxation scopes' do
let(:api_particulier_scopes) { ['dgfip_declarant1_nom', 'dgfip_declarant1_prenoms', 'dgfip_adresse_fiscale_taxation'] }
let(:dgfip_avis_imposition_et_adresse) do
{
'dgfip' => {
'declarant1' => ['nom', 'prenoms'],
'foyer_fiscal' => ['adresse']
}
}
end
it { is_expected.to match(dgfip_avis_imposition_et_adresse) }
end
context 'when a procedure has an unknown scope' do
let(:api_particulier_scopes) { ['unknown_scope'] }