Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/odd-colts-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': patch
'@rocket.chat/meteor': patch
---

Fixes the `sort` parameter validation on `/api/v1/audit.settings` endpoint to accept string format.
40 changes: 40 additions & 0 deletions apps/meteor/tests/end-to-end/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,5 +535,45 @@ describe('[Settings]', () => {
});
});
});

describe('Sorting', () => {
const isSortedAscending = (events: IServerEvents['settings.changed'][]) =>
events.every((event, i) => i === 0 || new Date(event.ts).getTime() >= new Date(events[i - 1].ts).getTime());

const isSortedDescending = (events: IServerEvents['settings.changed'][]) =>
events.every((event, i) => i === 0 || new Date(event.ts).getTime() <= new Date(events[i - 1].ts).getTime());

it('should sort by timestamp ascending', async () => {
const response = await request
.get(api('audit.settings'))
.query({ sort: JSON.stringify({ ts: 1 }), start: formatDate(startDate), end: formatDate(endDate) })
.set(credentials)
.expect(200);

expect(response.body).to.have.property('success', true);
expect(response.body.events).to.have.length.greaterThanOrEqual(2);
expect(isSortedAscending(response.body.events)).to.be.true;
});

it('should sort by timestamp descending', async () => {
const response = await request
.get(api('audit.settings'))
.query({ sort: JSON.stringify({ ts: -1 }), start: formatDate(startDate), end: formatDate(endDate) })
.set(credentials)
.expect(200);

expect(response.body).to.have.property('success', true);
expect(response.body.events).to.have.length.greaterThanOrEqual(2);
expect(isSortedDescending(response.body.events)).to.be.true;
});

it('should sort by timestamp descending by default', async () => {
const response = await request.get(api('audit.settings')).set(credentials).expect(200);

expect(response.body).to.have.property('success', true);
expect(response.body.events).to.have.length.greaterThanOrEqual(2);
expect(isSortedDescending(response.body.events)).to.be.true;
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ const ServerEventsAuditSettingsParamsGetSchema = {
type: 'object',
properties: {
sort: {
type: 'object',
type: 'string',
nullable: true,
properties: {
ts: {
type: 'number',
nullable: true,
},
},
},
count: {
type: 'number',
Expand Down
Loading