spec/concerns/authentication_spec.rb in mrkt-0.9.0 vs spec/concerns/authentication_spec.rb in mrkt-0.10.0
- old
+ new
@@ -30,20 +30,32 @@
end
context 'when the token has expired and @retry_authentication = true' do
before { remove_request_stub(@authentication_request_stub) }
+ let(:retry_count) { 3 }
+
let(:expired_authentication_stub) do
{ access_token: SecureRandom.uuid, token_type: 'bearer', expires_in: 0, scope: 'RestClient' }
end
let(:valid_authentication_stub) do
{ access_token: SecureRandom.uuid, token_type: 'bearer', expires_in: 1234, scope: 'RestClient' }
end
- subject(:client) { Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret, retry_authentication: true) }
+ let(:client_options) do
+ {
+ host: host,
+ client_id: client_id,
+ client_secret: client_secret,
+ retry_authentication: true,
+ retry_authentication_count: retry_count
+ }
+ end
+ subject(:client) { Mrkt::Client.new(client_options) }
+
before do
stub_request(:get, "https://#{host}/identity/oauth/token")
.with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' })
.to_return(json_stub(expired_authentication_stub)).times(3).then
.to_return(json_stub(valid_authentication_stub))
@@ -53,15 +65,17 @@
expect(client.authenticated?).to_not be true
client.authenticate!
expect(client.authenticated?).to be true
end
- it 'should stop retrying after @retry_authentication_count tries and then raise an error' do
- client = Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret, retry_authentication: true, retry_authentication_count: 2)
+ context 'when retry_authentication_count is low' do
+ let(:retry_count) { 2 }
- expect(client.authenticated?).to_not be true
+ it 'should stop retrying after @retry_authentication_count tries and then raise an error' do
+ expect(client.authenticated?).to_not be true
- expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated')
+ expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated')
+ end
end
end
end
describe '#authenticated?' do