2023-08-28 14:56:52 +02:00
describe Administrateurs :: ChorusController , type : :controller do
2023-10-20 16:57:20 +02:00
let ( :user ) { create ( :user ) }
let ( :admin ) { create ( :administrateur , user : create ( :user ) ) }
let ( :procedure ) { create ( :procedure , administrateurs : [ admin ] ) }
describe '#edit' do
2023-08-28 14:56:52 +02:00
subject { get :edit , params : { procedure_id : procedure . id } }
2023-10-20 16:57:20 +02:00
context 'when user is not signed in' do
2023-08-28 14:56:52 +02:00
it { is_expected . to redirect_to ( new_user_session_path ) }
end
2023-10-20 16:57:20 +02:00
context 'when user is signed in but not admin of procedure' do
2023-08-28 14:56:52 +02:00
before { sign_in ( user ) }
it { is_expected . to redirect_to ( new_user_session_path ) }
end
2023-10-20 16:57:20 +02:00
context 'when user is signed as admin' do
2023-08-28 14:56:52 +02:00
before { sign_in ( admin . user ) }
it { is_expected . to have_http_status ( 200 ) }
2023-08-29 09:22:58 +02:00
context 'rendered' do
render_views
it { is_expected . to have_http_status ( 200 ) }
end
end
end
2023-10-20 16:57:20 +02:00
describe '#update' do
2023-08-29 09:22:58 +02:00
let ( :chorus_configuration_params ) { { } }
subject do
put :update ,
params : {
procedure_id : procedure . id ,
chorus_configuration : chorus_configuration_params
}
end
2023-10-20 16:57:20 +02:00
context 'when user is not signed in' do
2023-08-29 09:22:58 +02:00
it { is_expected . to redirect_to ( new_user_session_path ) }
end
2023-10-20 16:57:20 +02:00
context 'when user is signed in but not admin of procedure' do
2023-08-29 09:22:58 +02:00
before { sign_in ( user ) }
it { is_expected . to redirect_to ( new_user_session_path ) }
end
2023-10-20 16:57:20 +02:00
context 'when user is signed as admin' do
2023-08-29 09:22:58 +02:00
before { sign_in ( admin . user ) }
2023-10-20 16:57:20 +02:00
let ( :domaine_fonctionnel ) { nil }
let ( :referentiel_de_programmation ) { nil }
2023-08-29 09:22:58 +02:00
2023-10-20 16:57:20 +02:00
context " partial valid payload " do
2023-11-09 09:59:04 +01:00
let ( :centre_de_cout ) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
2023-10-20 16:57:20 +02:00
let ( :chorus_configuration_params ) do
{
2023-11-09 09:59:04 +01:00
centre_de_cout : , domaine_fonctionnel : , referentiel_de_programmation :
2023-10-20 16:57:20 +02:00
}
end
it 'updates params and redirect back to complete all infos' do
expect ( subject ) . to redirect_to ( edit_admin_procedure_chorus_path ( procedure ) )
expect ( flash [ :notice ] ) . to eq ( " La configuration Chorus a été mise à jour. Veuillez renseigner le reste des informations pour faciliter le rapprochement des données. " )
procedure . reload
2023-11-09 09:59:04 +01:00
expect ( procedure . chorus_configuration . centre_de_cout ) . to eq ( JSON . parse ( centre_de_cout ) )
2023-10-20 16:57:20 +02:00
expect ( procedure . chorus_configuration . domaine_fonctionnel ) . to eq ( nil )
expect ( procedure . chorus_configuration . referentiel_de_programmation ) . to eq ( nil )
end
end
context " full valid payload " do
2023-11-09 09:59:04 +01:00
let ( :centre_de_cout ) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
2023-09-06 17:16:02 +02:00
let ( :domaine_fonctionnel ) { '{"code":"0105-05-01","label":"Formation+des+élites+et+cadres+de+sécurité+et+de+défense","description":null,"code_programme":"105"}' }
let ( :referentiel_de_programmation ) { '{"code":"010101010101","label":"DOTATIONS+CARPA+AJ+ET+AUTRES+INTERVENTIONS","description":null,"code_programme":"101"}' }
2023-08-29 09:22:58 +02:00
let ( :chorus_configuration_params ) do
{
2023-11-09 09:59:04 +01:00
centre_de_cout : , domaine_fonctionnel : , referentiel_de_programmation :
2023-08-29 09:22:58 +02:00
}
end
2023-10-20 16:57:20 +02:00
it 'updates params and redirects to add champs EngagementJuridique' do
expect ( subject ) . to redirect_to ( add_champ_engagement_juridique_admin_procedure_chorus_path ( procedure ) )
expect ( flash [ :notice ] ) . to eq ( " La configuration Chorus a été mise à jour. " )
2023-08-29 09:22:58 +02:00
procedure . reload
2023-10-20 16:57:20 +02:00
2023-11-09 09:59:04 +01:00
expect ( procedure . chorus_configuration . centre_de_cout ) . to eq ( JSON . parse ( centre_de_cout ) )
2023-09-06 17:16:02 +02:00
expect ( procedure . chorus_configuration . domaine_fonctionnel ) . to eq ( JSON . parse ( domaine_fonctionnel ) )
expect ( procedure . chorus_configuration . referentiel_de_programmation ) . to eq ( JSON . parse ( referentiel_de_programmation ) )
2023-08-29 09:22:58 +02:00
end
end
2023-08-28 14:56:52 +02:00
end
end
2023-10-20 16:57:20 +02:00
describe '#add_champ_engagement_juridique' do
render_views
subject { get :add_champ_engagement_juridique , params : { procedure_id : procedure . id } }
context 'when user is not signed in' do
it { is_expected . to redirect_to ( new_user_session_path ) }
end
context 'when user is signed in but not admin of procedure' do
before { sign_in ( user ) }
it { is_expected . to redirect_to ( new_user_session_path ) }
end
context 'when user is signed as admin' do
before { sign_in ( admin . user ) }
it 'have links to add annotation' do
expect ( subject ) . to have_http_status ( :success )
expect ( response . body ) . to have_link ( " Ajouter une annotation privée EJ " , href : annotations_admin_procedure_path ( procedure ) )
end
end
end
2023-08-28 14:56:52 +02:00
end