2024-04-29 00:17:15 +02:00
# frozen_string_literal: true
2020-08-05 18:40:47 +02:00
describe APIEntreprise :: RNAAdapter do
2022-10-05 12:31:34 +02:00
let ( :rna ) { 'W111111111' }
2020-04-27 16:31:41 +02:00
let ( :procedure ) { create ( :procedure ) }
let ( :procedure_id ) { procedure . id }
2022-10-05 12:31:34 +02:00
let ( :adapter ) { described_class . new ( rna , procedure_id ) }
2015-12-24 16:12:16 +01:00
2018-02-21 16:29:22 +01:00
subject { adapter . to_params }
2015-12-11 10:36:16 +01:00
before do
2023-05-30 11:32:59 +02:00
stub_request ( :get , / https: \/ \/ entreprise.api.gouv.fr \/ v4 \/ djepva \/ api-association \/ associations \/ open_data \/ #{ rna } / )
2018-01-15 19:34:08 +01:00
. to_return ( body : body , status : status )
2020-08-05 18:40:47 +02:00
allow_any_instance_of ( APIEntrepriseToken ) . to receive ( :expired? ) . and_return ( false )
2015-12-11 12:36:44 +01:00
end
2022-10-05 12:31:34 +02:00
context 'when rna is not valid' do
let ( :rna ) { '234567' }
2015-12-11 12:36:44 +01:00
let ( :body ) { '' }
2019-04-30 16:36:40 +02:00
let ( :status ) { 404 }
2015-12-24 16:12:16 +01:00
2018-03-19 14:47:56 +01:00
it { is_expected . to eq ( { } ) }
2015-12-11 10:36:16 +01:00
end
2022-09-22 17:13:53 +02:00
context " when responds with valid schema " do
let ( :body ) { File . read ( 'spec/fixtures/files/api_entreprise/associations.json' ) }
let ( :status ) { 200 }
2022-10-04 17:19:30 +02:00
it '#to_params return valid hash' do
2022-09-22 17:13:53 +02:00
expect ( subject ) . to be_an_instance_of ( Hash )
2023-05-30 11:32:59 +02:00
expect ( subject [ " association_rna " ] ) . to eq ( " W751080001 " )
expect ( subject [ " association_titre " ] ) . to eq ( " LA PRÉVENTION ROUTIERE " )
expect ( subject [ " association_objet " ] ) . to eq ( " L'association a pour objet de promouvoir la pratique du sport de haut niveau et de contribuer à la formation des jeunes sportifs. " )
2023-05-31 09:43:11 +02:00
expect ( subject [ " association_date_declaration " ] ) . to eq ( " 2019-01-01 " )
2023-05-30 11:32:59 +02:00
expect ( subject [ " association_date_publication " ] ) . to eq ( " 2018-01-01 " )
2024-02-05 18:47:40 +01:00
expect ( subject [ " adresse " ] ) . to eq ( {
complement : " " ,
numero_voie : " 33 " ,
type_voie : " rue " ,
libelle_voie : " de Modagor " ,
distribution : " dummy " ,
code_insee : " 75108 " ,
code_postal : " 75009 " ,
commune : " Paris "
} )
2022-10-04 19:59:39 +02:00
end
end
2015-12-11 10:36:16 +01:00
end