test(api_entreprise): add missing tests for API Entreprises privileges & adapter
This commit is contained in:
parent
b75cff2fc3
commit
f8cf8aaab7
3 changed files with 71 additions and 0 deletions
29
spec/fixtures/files/api_entreprise/privileges.json
vendored
Normal file
29
spec/fixtures/files/api_entreprise/privileges.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"privileges": [
|
||||||
|
"attestations_agefiph",
|
||||||
|
"attestations_fiscales",
|
||||||
|
"attestations_sociales",
|
||||||
|
"certificat_cnetp",
|
||||||
|
"associations",
|
||||||
|
"certificat_opqibi",
|
||||||
|
"documents_association",
|
||||||
|
"etablissements",
|
||||||
|
"entreprises",
|
||||||
|
"extrait_court_inpi",
|
||||||
|
"extraits_rcs",
|
||||||
|
"exercices",
|
||||||
|
"fntp_carte_pro",
|
||||||
|
"qualibat",
|
||||||
|
"probtp",
|
||||||
|
"msa_cotisations",
|
||||||
|
"bilans_entreprise_bdf",
|
||||||
|
"certificat_rge_ademe",
|
||||||
|
"conventions_collectives",
|
||||||
|
"actes_inpi",
|
||||||
|
"bilans_inpi",
|
||||||
|
"effectifs_acoss",
|
||||||
|
"entreprises_artisanales",
|
||||||
|
"eori_douanes",
|
||||||
|
"certificat_agence_bio"
|
||||||
|
]
|
||||||
|
}
|
|
@ -258,6 +258,24 @@ describe APIEntreprise::API do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.privileges' do
|
||||||
|
let(:api) { described_class.new }
|
||||||
|
let(:status) { 200 }
|
||||||
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/privileges.json') }
|
||||||
|
subject { api.privileges }
|
||||||
|
|
||||||
|
before do
|
||||||
|
api.token = token
|
||||||
|
|
||||||
|
stub_request(:get, "https://entreprise.api.gouv.fr/v2/privileges")
|
||||||
|
.to_return(body: body, status: status)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when token is authorized' do
|
||||||
|
it { expect(subject).to eq(JSON.parse(body, symbolize_names: true)) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'with expired token' do
|
describe 'with expired token' do
|
||||||
let(:siren) { '111111111' }
|
let(:siren) { '111111111' }
|
||||||
subject { described_class.new(procedure_id).entreprise(siren) }
|
subject { described_class.new(procedure_id).entreprise(siren) }
|
||||||
|
|
24
spec/lib/api_entreprise/privileges_adapter_spec.rb
Normal file
24
spec/lib/api_entreprise/privileges_adapter_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
describe APIEntreprise::PrivilegesAdapter do
|
||||||
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/privileges.json') }
|
||||||
|
let(:status) { 200 }
|
||||||
|
let(:token) { "secret-token" }
|
||||||
|
let(:adapter) { described_class.new(token) }
|
||||||
|
|
||||||
|
subject { adapter }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_request(:get, "https://entreprise.api.gouv.fr/v2/privileges")
|
||||||
|
.to_return(body: body, status: status)
|
||||||
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to be_valid }
|
||||||
|
|
||||||
|
context 'when token is not valid or missing' do
|
||||||
|
let(:token) { nil }
|
||||||
|
let(:status) { 403 }
|
||||||
|
let(:body) { '' }
|
||||||
|
|
||||||
|
it { is_expected.not_to be_valid }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue