2021-11-25 16:26:55 +01:00
|
|
|
describe Administrateurs::SourcesParticulierController, type: :controller do
|
2021-09-13 15:59:58 +02:00
|
|
|
let(:admin) { create(:administrateur) }
|
|
|
|
|
|
|
|
before { sign_in(admin.user) }
|
|
|
|
|
|
|
|
describe "#show" do
|
2021-09-21 11:01:04 +02:00
|
|
|
let(:procedure) { create(:procedure, administrateur: admin, api_particulier_scopes: ['cnaf_enfants'], api_particulier_sources: { cnaf: { enfants: ['nomPrenom'] } }) }
|
2021-09-13 15:59:58 +02:00
|
|
|
|
|
|
|
render_views
|
|
|
|
|
|
|
|
subject { get :show, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
|
|
it 'renders the sources form' do
|
2021-09-21 11:01:04 +02:00
|
|
|
expect(subject.body).to include(I18n.t('api_particulier.providers.cnaf.scopes.enfants.dateDeNaissance'))
|
|
|
|
expect(subject.body).to have_selector("input#api_particulier_sources_cnaf_enfants_[value=nomPrenom][checked=checked]")
|
2021-09-13 15:59:58 +02:00
|
|
|
|
2021-09-21 11:01:04 +02:00
|
|
|
expect(subject.body).to have_selector("input#api_particulier_sources_cnaf_enfants_[value=dateDeNaissance]")
|
|
|
|
expect(subject.body).not_to have_selector("input#api_particulier_sources_cnaf_enfants_[value=dateDeNaissance][checked=checked]")
|
2021-09-13 15:59:58 +02:00
|
|
|
end
|
|
|
|
end
|
2021-09-17 12:22:01 +02:00
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
let(:procedure) { create(:procedure, administrateur: admin, api_particulier_scopes: ['cnaf_enfants'], api_particulier_sources: {}) }
|
|
|
|
let(:params) { { procedure_id: procedure.id }.merge(requested_sources) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
patch :update, params: params
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no source is requested' do
|
|
|
|
let(:requested_sources) { {} }
|
|
|
|
|
|
|
|
it { expect(procedure.api_particulier_sources).to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a forbidden source is requested' do
|
|
|
|
let(:requested_sources) do
|
|
|
|
{
|
|
|
|
api_particulier_sources: { cnaf: { enfants: ['forbidden'] } }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure.api_particulier_sources).to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an authorized source is requested' do
|
|
|
|
let(:requested_sources) do
|
|
|
|
{
|
2021-09-21 11:01:04 +02:00
|
|
|
api_particulier_sources: { cnaf: { enfants: ['nomPrenom'] } }
|
2021-09-17 12:22:01 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves the source' do
|
2021-09-21 11:01:04 +02:00
|
|
|
expect(procedure.api_particulier_sources).to eq("cnaf" => { "enfants" => ["nomPrenom"] })
|
2021-11-25 16:26:55 +01:00
|
|
|
expect(flash.notice).to eq(I18n.t(".administrateurs.sources_particulier.update.sources_ok"))
|
2021-09-17 12:22:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-13 15:59:58 +02:00
|
|
|
end
|