-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add retry logic to 429 cases. (#119)
* feat: add retry logic. * chore: update jsonwebtoken lib * fix: only retry in 429. * tests: add basic test for 429 case.
- Loading branch information
1 parent
f063748
commit edc69db
Showing
9 changed files
with
15,617 additions
and
8,177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CLIENT_ID=your_client_id | ||
CLIENT_SECRET=your_client_secret | ||
PLUGGY_API_URL=https://test.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}], | ||
}, | ||
setupFiles: ['<rootDir>/tests/setupTests.ts'], | ||
testMatch: ['<rootDir>/tests/**/*.test.ts'], | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as nock from 'nock' | ||
import { setupAuth } from './utils' | ||
import { PluggyClient } from '../src/client' | ||
|
||
describe('Auth', () => { | ||
beforeEach(() => { | ||
nock.cleanAll() // Clear previous mocks first | ||
setupAuth() | ||
}) | ||
|
||
it('creates a connect token', async () => { | ||
const mockConnectTokenRequest = nock(process.env.PLUGGY_API_URL!) | ||
.post('/connect_token') | ||
.reply(200, { accessToken: '123' }) | ||
|
||
const client = new PluggyClient({ | ||
clientId: '123', | ||
clientSecret: '456', | ||
}) | ||
|
||
const token = await client.createConnectToken() | ||
|
||
expect(token.accessToken).toEqual('123') | ||
|
||
expect(mockConnectTokenRequest.isDone()).toBeTruthy() | ||
}) | ||
|
||
it('with 429 status code, retries the request', async () => { | ||
const mockConnectTokenRequest = nock(process.env.PLUGGY_API_URL!) | ||
.post('/connect_token') | ||
.reply(429, 'Rate limit exceeded', { | ||
'Retry-After': '1', | ||
}) | ||
.post('/connect_token') | ||
.reply(200, { accessToken: '123' }) | ||
|
||
const client = new PluggyClient({ | ||
clientId: '123', | ||
clientSecret: '456', | ||
}) | ||
|
||
const token = await client.createConnectToken() | ||
|
||
expect(token.accessToken).toEqual('123') | ||
|
||
expect(mockConnectTokenRequest.isDone()).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as dotenv from 'dotenv' | ||
|
||
dotenv.config({ path: '.env.test' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as nock from 'nock' | ||
|
||
export function setupAuth(): void { | ||
nock(process.env.PLUGGY_API_URL!) | ||
.post('/auth') | ||
.reply(200, { apiKey: '123' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters