Merge pull request #9102 from demarches-simplifiees/8472-migrate-rna

API Entreprise: migration RNA (associations)
This commit is contained in:
mfo 2023-06-01 11:37:57 +00:00 committed by GitHub
commit 1a6dc10548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 205 additions and 149 deletions

View file

@ -147,7 +147,7 @@ describe APIEntreprise::API do
describe '.rna' do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v4\/djepva\/api-association\/associations\/open_data\/#{siren}/)
.to_return(status: status, body: body)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end

View file

@ -7,7 +7,7 @@ describe APIEntreprise::RNAAdapter do
subject { adapter.to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v4\/djepva\/api-association\/associations\/open_data\/#{rna}/)
.to_return(body: body, status: status)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
@ -26,29 +26,11 @@ describe APIEntreprise::RNAAdapter do
it '#to_params return valid hash' do
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')
end
end
context "when responds with invalid schema" do
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations_invalid.json') }
let(:status) { 200 }
it '#to_params raise exception' do
expect { subject }.to raise_exception(APIEntreprise::RNAAdapter::InvalidSchemaError)
end
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"])
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.")
expect(subject["association_date_declaration"]).to eq("2019-01-01")
expect(subject["association_date_publication"]).to eq("2018-01-01")
end
end
end