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/fix-presence-comma-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/meteor': patch
'@rocket.chat/rest-typings': patch
---

Fixes the `users.presence` endpoint returning an empty array when called with multiple comma-separated IDs, caused by `ajvQuery` coercing the string into a single-element array after the OpenAPI migration
42 changes: 42 additions & 0 deletions apps/meteor/tests/end-to-end/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,48 @@ describe('[Users]', () => {
.end(done);
});

it('should return presence for a single id', async () => {
const res = await request
.get(api('users.presence'))
.query({ ids: 'rocket.cat' })
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200);

expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('full', false);
expect(res.body).to.have.property('users').that.is.an('array').with.lengthOf(1);
expect(res.body.users[0]).to.have.property('_id', 'rocket.cat');
});

it('should correctly parse comma-separated ids and not return an empty result', async () => {
const res = await request
.get(api('users.presence'))
.query({ ids: `rocket.cat,${credentials['X-User-Id']}` })
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200);

expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('full', false);
// only rocket.cat is guaranteed to be online; admin may be offline
expect(res.body.users.map((u: IUser) => u._id)).to.include('rocket.cat');
});

it('should return presence for repeated ids params', async () => {
const res = await request
.get(api('users.presence'))
.query(`ids=rocket.cat&ids=${credentials['X-User-Id']}`)
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200);

expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('full', false);
// only rocket.cat is guaranteed to be online; admin may be offline
expect(res.body.users.map((u: IUser) => u._id)).to.include('rocket.cat');
});

it('should return full list of online users for more than 10 minutes in the past', (done) => {
const date = new Date();
date.setMinutes(date.getMinutes() - 11);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const UsersPresenceParamsGetSchema = {
properties: {
from: { type: 'string', nullable: true },
ids: {
anyOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' } }],
type: ['string', 'array'],
items: { type: 'string' },
},
},
additionalProperties: false,
Expand Down
Loading