demarches-normaliennes/spec/lib/api_education/annuaire_education_adapter_spec.rb

53 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2020-08-05 18:40:47 +02:00
describe APIEducation::AnnuaireEducationAdapter do
2021-01-13 18:58:59 +01:00
let(:search_term) { '0050009H' }
let(:adapter) { described_class.new(search_term) }
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/data.education.gouv.fr\/api\/records\/1.0/)
.to_return(body: body, status: status)
end
context "when responds with valid schema" do
let(:body) { File.read('spec/fixtures/files/api_education/annuaire_education.json') }
let(:status) { 200 }
2022-10-04 17:19:30 +02:00
it '#to_params return valid hash' do
2021-01-13 18:58:59 +01:00
expect(subject).to be_an_instance_of(Hash)
expect(subject['identifiant_de_l_etablissement']).to eq(search_term)
2021-06-01 15:14:42 +02:00
expect(subject['code_type_contrat_prive']).to eq(99)
end
end
context "when responds with code_type_contrat_prive as string" do
let(:body) { File.read('spec/fixtures/files/api_education/annuaire_education_bug.json') }
let(:status) { 200 }
2022-10-04 17:19:30 +02:00
it '#to_params return valid hash' do
2021-06-01 15:14:42 +02:00
expect(subject).to be_an_instance_of(Hash)
expect(subject['identifiant_de_l_etablissement']).to eq(search_term)
expect(subject['code_type_contrat_prive']).to eq(99)
2021-01-13 18:58:59 +01:00
end
end
context "when responds with invalid schema" do
let(:body) { File.read('spec/fixtures/files/api_education/annuaire_education_invalid.json') }
let(:status) { 200 }
it '#to_params raise exception' do
2020-08-05 18:40:47 +02:00
expect { subject }.to raise_exception(APIEducation::AnnuaireEducationAdapter::InvalidSchemaError)
2021-01-13 18:58:59 +01:00
end
end
2023-02-15 15:25:15 +01:00
context "when responds with empty schema" do
let(:body) { File.read('spec/fixtures/files/api_education/annuaire_education_empty.json') }
let(:status) { 200 }
it '#to_params returns nil' do
expect(subject).to eq(nil)
end
end
2021-01-13 18:58:59 +01:00
end