Skip to content

Commit 845c385

Browse files
committed
test(confluence): add separate test for retries
1 parent 2af2365 commit 845c385

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

workspaces/confluence/plugins/search-confluence-backend/src/search/ConfluenceCollatorFactory/ConfluenceCollaterFactory.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,29 +263,38 @@ describe('Testing ConfluenceCollatorFactory', () => {
263263
});
264264

265265
it('should throw an error for a non-ok response', async () => {
266-
const retryMock = jest.fn();
267-
const errorStatus = 404;
268-
const errorMessage = 'Not Found';
269-
const error = new Error(
270-
`Request failed with ${errorStatus} ${errorMessage}`,
266+
const confluenceCollatorFactory = ConfluenceCollatorFactory.fromConfig(
267+
createConfig,
268+
{ logger },
271269
);
270+
271+
fetch.mockResponseOnce('Not Found', { status: 404 });
272+
273+
await expect(
274+
confluenceCollatorFactory.get('https://example.com'),
275+
).rejects.toThrow('Not Found');
276+
});
277+
278+
it('should retry for a rate limit error response', async () => {
279+
const retryMock = jest.fn();
272280
jest.spyOn(retry, 'operation').mockReturnValue({
273281
...retry.operation(),
274282
attempt: fn => fn(1),
275283
retry: retryMock,
276-
mainError: () => error,
277284
});
278285

279286
const confluenceCollatorFactory = ConfluenceCollatorFactory.fromConfig(
280287
createConfig,
281288
{ logger },
282289
);
283290

284-
fetch.mockResponseOnce(errorMessage, { status: errorStatus });
291+
fetch.mockResponseOnce('Too Many Requests', { status: 429 });
285292

286293
await expect(
287294
confluenceCollatorFactory.get('https://example.com'),
288-
).rejects.toThrow(errorMessage);
295+
).rejects.toThrow('Too Many Requests');
296+
297+
expect(retryMock).toHaveBeenCalled();
289298
});
290299

291300
it('should return Bearer token if token is present', () => {

0 commit comments

Comments
 (0)