demarches-normaliennes/spec/lib/api_entreprise/rna_adapter_spec.rb

56 lines
2.1 KiB
Ruby
Raw Normal View History

2020-08-05 18:40:47 +02:00
describe APIEntreprise::RNAAdapter do
let(:rna) { 'W111111111' }
2020-04-27 16:31:41 +02:00
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
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
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.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)
end
context 'when rna is not valid' do
let(:rna) { '234567' }
let(:body) { '' }
2019-04-30 16:36:40 +02:00
let(:status) { 404 }
2015-12-24 16:12:16 +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)
expect(subject["association_rna"]).to eq('W595001988')
expect(subject["association_titre"]).to eq('UN SUR QUATRE')
expect(subject["association_objet"]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement")
expect(subject["association_date_declaration"]).to eq('2014-01-24')
expect(subject["association_date_publication"]).to eq('2014-02-08')
end
end
2015-12-11 10:36:16 +01:00
2022-09-22 17:13:53 +02:00
context "when responds with invalid schema" do
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations_invalid.json') }
let(:status) { 200 }
2015-12-11 10:36:16 +01:00
2022-09-22 17:13:53 +02:00
it '#to_params raise exception' do
expect { subject }.to raise_exception(APIEntreprise::RNAAdapter::InvalidSchemaError)
end
2015-12-11 10:36:16 +01:00
end
context "when depreciated adapter is used" do
let(:adapter) { described_class.new(rna, procedure_id, true) }
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
let(:status) { 200 }
it '#to_params filter the keys' do
expect(subject.keys).to eq(["association_titre", "association_objet", "association_date_creation", "association_date_declaration", "association_date_publication", "association_rna"])
end
end
2015-12-11 10:36:16 +01:00
end