extract class ApiEntrepriseToken
and check if token is expired
This commit is contained in:
parent
132cfcb6c3
commit
f587e6600a
4 changed files with 58 additions and 8 deletions
|
@ -166,7 +166,7 @@ describe ApiEntreprise::API do
|
|||
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(roles)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
@ -194,7 +194,7 @@ describe ApiEntreprise::API do
|
|||
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)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(: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
|
||||
|
@ -221,7 +221,7 @@ describe ApiEntreprise::API do
|
|||
let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(roles)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=#{token}/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
|
|
@ -334,6 +334,31 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'api_entreprise_token_expired?' do
|
||||
let(:token) { "mon-token" }
|
||||
let(:procedure) { create(:procedure, api_entreprise_token: token) }
|
||||
let(:payload) {
|
||||
[
|
||||
{ "exp" => expiration_time }
|
||||
]
|
||||
}
|
||||
let(:subject) { procedure.api_entreprise_token_expired? }
|
||||
|
||||
before do
|
||||
allow(JWT).to receive(:decode).with(token, nil, false).and_return(payload)
|
||||
end
|
||||
|
||||
context "with token expired" do
|
||||
let(:expiration_time) { (Time.zone.now - 1.day).to_i }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context "with token not expired" do
|
||||
let(:expiration_time) { (Time.zone.now + 1.day).to_i }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'clone' do
|
||||
let!(:service) { create(:service) }
|
||||
let(:procedure) { create(:procedure, received_mail: received_mail, service: service) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue