Skip to content

Commit

Permalink
feat: add test for limit (#1117)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
VebjornG authored Jun 26, 2024
1 parent 0e37326 commit 582891e
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions packages/beta/src/__tests__/api/alertsApi.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 582891e

Please sign in to comment.