2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-10-05 14:16:07 +02:00
|
|
|
describe APIParticulier::CnafAdapter do
|
2021-09-22 11:00:03 +02:00
|
|
|
let(:adapter) { described_class.new(api_particulier_token, numero_allocataire, code_postal, requested_sources) }
|
|
|
|
|
2021-09-28 15:11:58 +02:00
|
|
|
before { stub_const("API_PARTICULIER_URL", "https://particulier.api.gouv.fr/api") }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
|
|
|
describe '#to_params' do
|
2021-09-21 11:46:40 +02:00
|
|
|
let(:api_particulier_token) { '29eb50b65f64e8e00c0847a8bbcbd150e1f847' }
|
|
|
|
let(:numero_allocataire) { '5843972' }
|
|
|
|
let(:code_postal) { '92110' }
|
|
|
|
|
|
|
|
subject { VCR.use_cassette(cassette) { adapter.to_params } }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when the api answer is valid' do
|
|
|
|
let(:cassette) { "api_particulier/success/composition_familiale" }
|
|
|
|
|
|
|
|
context 'when the token has all the cnaf scopes' do
|
|
|
|
context 'and all the sources are requested' do
|
|
|
|
let(:requested_sources) do
|
|
|
|
{
|
|
|
|
'cnaf' => {
|
|
|
|
'allocataires' => ['nomPrenom', 'dateDeNaissance', 'sexe'],
|
|
|
|
'enfants' => ['nomPrenom', 'dateDeNaissance', 'sexe'],
|
|
|
|
'adresse' => ['identite', 'complementIdentite', 'complementIdentiteGeo', 'numeroRue', 'lieuDit', 'codePostalVille', 'pays'],
|
|
|
|
'quotient_familial' => ['quotientFamilial', 'annee', 'mois']
|
|
|
|
}
|
2021-09-22 11:00:03 +02:00
|
|
|
}
|
2021-09-21 11:46:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:result) { JSON.parse(File.read('spec/fixtures/files/api_particulier/composition_familiale.json')) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(result) }
|
2021-09-22 11:00:03 +02:00
|
|
|
end
|
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when no sources is requested' do
|
|
|
|
let(:requested_sources) { {} }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
it { is_expected.to eq({}) }
|
|
|
|
end
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when a scalar is requested' do
|
|
|
|
let(:requested_sources) { { 'cnaf' => { 'adresse' => ['pays'] } } }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
it { is_expected.to eq({ "adresse" => { "pays" => "FRANCE" } }) }
|
|
|
|
end
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when a quotient_familial is requested' do
|
|
|
|
let(:requested_sources) { { 'cnaf' => { 'quotient_familial' => ['annee'] } } }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
it { is_expected.to eq({ "quotient_familial" => { "annee" => 2021 } }) }
|
|
|
|
end
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when a vector is requested' do
|
|
|
|
let(:requested_sources) { { 'cnaf' => { 'allocataires' => ['nomPrenom'] } } }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
it { is_expected.to eq({ "allocataires" => [{ "nomPrenom" => "ERIC SNOW" }, { "nomPrenom" => "SANSA SNOW" }] }) }
|
|
|
|
end
|
2021-09-22 11:00:03 +02:00
|
|
|
end
|
2021-09-21 11:46:40 +02:00
|
|
|
end
|
|
|
|
|
2021-11-10 18:03:34 +01:00
|
|
|
context 'when the api answer is invalid' do
|
2021-09-21 11:46:40 +02:00
|
|
|
let(:cassette) { "api_particulier/success/composition_familiale_invalid" }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-09-21 11:46:40 +02:00
|
|
|
context 'when no sources is requested' do
|
|
|
|
let(:requested_sources) { {} }
|
2021-09-22 11:00:03 +02:00
|
|
|
|
2021-10-05 14:16:07 +02:00
|
|
|
it { expect { subject }.to raise_error(APIParticulier::CnafAdapter::InvalidSchemaError) }
|
2021-09-22 11:00:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|