demarches-normaliennes/spec/lib/api_particulier/services/sources_service_spec.rb

60 lines
1.8 KiB
Ruby
Raw Normal View History

2021-09-17 11:44:22 +02:00
describe APIParticulier::Services::SourcesService do
2021-09-17 12:21:38 +02:00
let(:service) { described_class.new(procedure) }
let(:procedure) { create(:procedure) }
let(:api_particulier_scopes) { [] }
let(:api_particulier_sources) { {} }
2021-09-17 11:44:22 +02:00
2021-09-17 12:21:38 +02:00
before do
procedure.update(api_particulier_scopes: api_particulier_scopes)
procedure.update(api_particulier_sources: api_particulier_sources)
end
describe "#available_sources" do
2021-09-17 11:44:22 +02:00
subject { service.available_sources }
context 'when the procedure doesnt have any available scopes' do
it { is_expected.to eq({}) }
end
context 'when a procedure has a cnaf_allocataires and a cnaf_adresse scopes' do
let(:api_particulier_scopes) { ['cnaf_allocataires', 'cnaf_enfants'] }
let(:cnaf_allocataires_and_enfants) do
{
'cnaf' => {
2021-09-21 11:01:04 +02:00
'allocataires' => ['nomPrenom', 'dateDeNaissance', 'sexe'],
'enfants' => ['nomPrenom', 'dateDeNaissance', 'sexe']
2021-09-17 11:44:22 +02:00
}
}
end
it { is_expected.to match(cnaf_allocataires_and_enfants) }
end
2021-09-28 15:12:10 +02:00
context 'when a procedure has an unknown scope' do
let(:api_particulier_scopes) { ['unknown_scope'] }
it { is_expected.to match({}) }
end
2021-09-17 11:44:22 +02:00
end
2021-09-17 12:21:38 +02:00
describe '#sanitize' do
subject { service.sanitize(requested_sources) }
let(:api_particulier_scopes) { ['cnaf_allocataires', 'cnaf_adresse'] }
let(:requested_sources) do
{
'cnaf' => {
2021-09-21 11:01:04 +02:00
'allocataires' => ['nomPrenom', 'forbidden_sources', { 'weird_object' => 1 }],
2021-09-17 12:21:38 +02:00
'forbidden_scope' => ['any_source'],
'adresse' => { 'weird_object' => 1 }
},
'forbidden_provider' => { 'anything_scope' => ['any_source'] }
}
end
2021-09-21 11:01:04 +02:00
it { is_expected.to eq({ 'cnaf' => { 'allocataires' => ['nomPrenom'] } }) }
2021-09-17 12:21:38 +02:00
end
2021-09-17 11:44:22 +02:00
end