create attestation_fiscale_adapter
This commit is contained in:
parent
15d8155f59
commit
38c68b16e3
5 changed files with 93 additions and 4 deletions
4
spec/fixtures/files/api_entreprise/attestation_fiscale.json
vendored
Normal file
4
spec/fixtures/files/api_entreprise/attestation_fiscale.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"url":
|
||||
"https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf"
|
||||
}
|
|
@ -185,4 +185,32 @@ describe ApiEntreprise::API do
|
|||
it { expect(subject).to eq(JSON.parse(body, symbolize_names: true)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.attestation_fiscale' do
|
||||
let(:procedure) { create(:procedure, api_entreprise_token: token) }
|
||||
let(:siren) { '418166096' }
|
||||
let(:user_id) { 1 }
|
||||
let(:status) { 200 }
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(roles)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}?.*token=#{token}&user_id=#{user_id}/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
||||
subject { described_class.attestation_fiscale(siren, procedure.id, user_id) }
|
||||
|
||||
context 'when token not authorized' do
|
||||
let(:roles) { ["entreprises"] }
|
||||
|
||||
it { expect(subject).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when token is authorized' do
|
||||
let(:roles) { ["attestations_fiscales"] }
|
||||
|
||||
it { expect(subject).to eq(JSON.parse(body, symbolize_names: true)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
26
spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb
Normal file
26
spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
describe ApiEntreprise::AttestationFiscaleAdapter do
|
||||
let(:siren) { '418166096' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:user_id) { 1 }
|
||||
let(:adapter) { described_class.new(siren, procedure.id, user_id) }
|
||||
subject { adapter.to_params }
|
||||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["attestations_fiscales"])
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
end
|
||||
|
||||
it "returns url of attestation_fiscale" do
|
||||
expect(subject[:entreprise_attestation_fiscale_url]).to eq("https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue