-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25873 add internal throttle to importer
- Loading branch information
Showing
4 changed files
with
59 additions
and
6 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
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,33 @@ | ||
const axios = require('axios'); | ||
const FlotiqApi = require('./../src/flotiq-api'); | ||
|
||
jest.mock('axios'); | ||
|
||
describe('FlotiqApi', () => { | ||
const mockApiUrl = 'https://dummy-api.flotiq.com'; | ||
const mockApiKey = 'dummyApiKey'; | ||
|
||
it('method persistContentObjectBatch should retry when receiving a 429 status', async () => { | ||
// Mock first response from Axios as 429, seconds as 200 | ||
const postMock = jest.fn() | ||
.mockRejectedValueOnce({ response: { status: 429 } }) | ||
.mockResolvedValueOnce({ ok: true }); | ||
|
||
axios.create.mockReturnValue({ | ||
post: postMock, | ||
}); | ||
|
||
const flotiqApi = new FlotiqApi(`${mockApiUrl}/api/v1`, mockApiKey, { | ||
batchSize: 100, | ||
internalWPSLimit: 5, | ||
}); | ||
|
||
const obj = new Array(100).fill({}); | ||
await flotiqApi.persistContentObjectBatch('mockContentType', obj); | ||
|
||
// Expect first call to be 429, then after retry: success | ||
expect(postMock).toHaveBeenCalledTimes(2); | ||
expect(postMock).toHaveBeenCalledWith(expect.anything(), expect.arrayContaining([{}])); | ||
}); | ||
}); | ||
|