From 582891ef7ce034425c500036af08d91964200a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vebj=C3=B8rn=20Gilberg?= Date: Wed, 26 Jun 2024 10:11:38 +0200 Subject: [PATCH] feat: add test for limit (#1117) * add test for limit * move tests inside describe() * delete space for linting * create 10 alerts and set limit to 10 * linting * use another externalId * create test channel * use correct externalId * use unique external ids --- .../src/__tests__/api/alertsApi.int.spec.ts | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/beta/src/__tests__/api/alertsApi.int.spec.ts b/packages/beta/src/__tests__/api/alertsApi.int.spec.ts index e4f847f1fbc..303406fa6cb 100644 --- a/packages/beta/src/__tests__/api/alertsApi.int.spec.ts +++ b/packages/beta/src/__tests__/api/alertsApi.int.spec.ts @@ -189,15 +189,41 @@ describe('alerts api', () => { ]); expect(response).toEqual({}); }); -}); -test('sort alerts', async () => { - const client: CogniteClient = setupLoggedInClient(); - const response = await client.alerts.list({ - sort: { - property: 'createdTime', - order: 'desc', - }, + test('sort alerts', async () => { + const response = await client.alerts.list({ + sort: { + property: 'createdTime', + order: 'desc', + }, + }); + expect(response.items.length).toBeGreaterThan(0); + }); + + test('test limit', async () => { + // create channel for the next test + const channelsToCreate = [ + { + externalId: channelExternalId, + name: 'Test Channel', + }, + ]; + await client.alerts.createChannels(channelsToCreate); + + // create 10 alerts + const alerts = Array.from({ length: 10 }).map((_, i) => ({ + source: 'smth', + channelExternalId, + externalId: `test_limit_extId_${i}`, + })); + await client.alerts.create(alerts); + + const response = await client.alerts.list({ + limit: 10, + }); + expect(response.items.length).toBe(10); + + // delete the channel + await client.alerts.deleteChannels([{ externalId: channelExternalId }]); }); - expect(response.items.length).toBeGreaterThan(0); });