From e0af392668a62c7a82118b314c3a1cc78232ea45 Mon Sep 17 00:00:00 2001 From: Noach Magedman <noach@seekingalpha.com> Date: Fri, 14 Apr 2023 14:41:03 +0300 Subject: [PATCH] fix: Revert breaking change to groups.list API: 404 vs. empty list (#27587) Co-authored-by: Debdut Chakraborty <76006232+debdutdeb@users.noreply.github.com> --- apps/meteor/app/api/server/v1/channels.ts | 7 ++++++- apps/meteor/app/api/server/v1/groups.ts | 7 ++++++- apps/meteor/tests/end-to-end/api/02-channels.js | 16 ++++++++++++++++ apps/meteor/tests/end-to-end/api/03-groups.js | 16 ++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/api/server/v1/channels.ts b/apps/meteor/app/api/server/v1/channels.ts index 914785d7603..f83ff8f7964 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -955,7 +955,12 @@ API.v1.addRoute( const rids = subs.map(({ rid }) => rid).filter(Boolean); if (rids.length === 0) { - return API.v1.notFound(); + return API.v1.success({ + channels: [], + offset, + count: 0, + total: 0, + }); } const { cursor, totalCount } = await Rooms.findPaginatedByTypeAndIds('c', rids, { diff --git a/apps/meteor/app/api/server/v1/groups.ts b/apps/meteor/app/api/server/v1/groups.ts index dd8db9256bf..195008b6e91 100644 --- a/apps/meteor/app/api/server/v1/groups.ts +++ b/apps/meteor/app/api/server/v1/groups.ts @@ -619,7 +619,12 @@ API.v1.addRoute( const rids = subs.map(({ rid }) => rid).filter(Boolean); if (rids.length === 0) { - return API.v1.notFound(); + return API.v1.success({ + groups: [], + offset, + count: 0, + total: 0, + }); } const { cursor, totalCount } = await Rooms.findPaginatedByTypeAndIds('p', rids, { diff --git a/apps/meteor/tests/end-to-end/api/02-channels.js b/apps/meteor/tests/end-to-end/api/02-channels.js index b36c1031e76..15f80ebbbde 100644 --- a/apps/meteor/tests/end-to-end/api/02-channels.js +++ b/apps/meteor/tests/end-to-end/api/02-channels.js @@ -2093,5 +2093,21 @@ describe('[Channels]', function () { }) .end(done); }); + + it('/channels.list.join should return empty list when member of no group', async () => { + const user = await createUser({ joinDefaultChannels: false }); + const newCreds = await login(user.username, password); + await request + .get(api('channels.list.joined')) + .set(newCreds) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count').that.is.equal(0); + expect(res.body).to.have.property('total').that.is.equal(0); + expect(res.body).to.have.property('channels').and.to.be.an('array').and.that.has.lengthOf(0); + }); + }); }); }); diff --git a/apps/meteor/tests/end-to-end/api/03-groups.js b/apps/meteor/tests/end-to-end/api/03-groups.js index a10eec964fb..86ec13fa213 100644 --- a/apps/meteor/tests/end-to-end/api/03-groups.js +++ b/apps/meteor/tests/end-to-end/api/03-groups.js @@ -652,6 +652,22 @@ describe('[Groups]', function () { .end(done); }); + it('/groups.list should return a list of zero length if not a member of any group', async () => { + const user = await createUser(); + const newCreds = await login(user.username, password); + request + .get(api('groups.list')) + .set(newCreds) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count').and.to.equal(0); + expect(res.body).to.have.property('total').and.to.equal(0); + expect(res.body).to.have.property('groups').and.to.be.an('array').and.that.has.lengthOf(0); + }); + }); + describe('[/groups.online]', () => { const createUserAndChannel = async (setAsOnline = true) => { const testUser = await createUser(); -- GitLab