From 2d2b83dd61eb8efbc38b6c8af32e4112159075b2 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Wed, 9 Mar 2022 10:53:22 -0300 Subject: [PATCH 1/6] fixed subscriptions w/o notifications pref --- server/sdk/types/ITeamService.ts | 1 + server/services/team/service.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/server/sdk/types/ITeamService.ts b/server/sdk/types/ITeamService.ts index c94baedefb734..e4938e0385e04 100644 --- a/server/sdk/types/ITeamService.ts +++ b/server/sdk/types/ITeamService.ts @@ -26,6 +26,7 @@ export interface IUserInfo { username?: string | null; name: string; status: string; + settings?: Record; } export interface ITeamMemberInfo { diff --git a/server/services/team/service.ts b/server/services/team/service.ts index ef963152d9872..6f0673d434fdb 100644 --- a/server/services/team/service.ts +++ b/server/services/team/service.ts @@ -658,6 +658,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService { username: user.username, name: user.name, status: user.status, + settings: user.settings, }, roles: record.roles, createdBy: { From 3c99c7320f2f396cfdd1ebd062d8f1d65070e29a Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Wed, 9 Mar 2022 12:16:32 -0300 Subject: [PATCH 2/6] added tests --- tests/end-to-end/api/25-teams.js | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/end-to-end/api/25-teams.js b/tests/end-to-end/api/25-teams.js index 50ad66ae64047..f1ddb9bdd9851 100644 --- a/tests/end-to-end/api/25-teams.js +++ b/tests/end-to-end/api/25-teams.js @@ -1461,6 +1461,8 @@ describe('[Teams]', () => { describe('/teams.update', () => { let testTeam; let testTeam2; + let testTeam3; + before('Create test team', (done) => { const teamName = `test-team-name${Date.now()}`; request @@ -1491,6 +1493,21 @@ describe('[Teams]', () => { }); }); + before('Create test team', (done) => { + const teamName3 = `test-team-name${Date.now()}`; + request + .post(api('teams.create')) + .set(credentials) + .send({ + name: teamName3, + type: 0, + }) + .end((err, res) => { + testTeam3 = res.body.team; + done(); + }); + }); + it('should update team name', async () => { const testTeamName = `test-team-name-changed${Date.now()}`; const updateResponse = await request @@ -1534,6 +1551,77 @@ describe('[Teams]', () => { expect(teamInfo).to.have.property('type', 1); }); + describe('should update team room to default and invite users with the right notification preferences', () => { + let userWithPrefs; + let userCredentials; + + before(async () => { + userWithPrefs = await createUser(); + userCredentials = await login(userWithPrefs.username, password); + }); + + it('should update user prefs', async () => { + await request + .post(methodCall('saveUserPreferences')) + .set(userCredentials) + .send({ + message: JSON.stringify({ + method: 'saveUserPreferences', + params: [{ emailNotificationMode: 'nothing' }], + }), + }) + .expect(200) + .done(); + }); + + it('should add user with prefs to team', async (done) => { + await request + .post(api('teams.addMembers')) + .set(credentials) + .send({ + teamName: testTeam3.name, + members: [ + { + userId: userWithPrefs._id, + roles: ['member'], + }, + ], + }) + .end(done); + }); + + it('should update team to auto-join', async () => { + const response = await request + .post(api('teams.update')) + .set(credentials) + .send({ + teamId: testTeam3._id, + data: { + isDefault: true, + }, + }); + + expect(response.body).to.have.property('success', true); + }); + + it('should return the user subscription with the right notification preferences', async (done) => { + await request + .get(api('subscriptions.getOne')) + .set(credentials) + .query({ + roomId: testTeam3._id, + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('subscription').and.to.be.an('object'); + expect(res.body).to.have.nested.property('subscription.emailNotifications').and.to.be.equal('nothing'); + }) + .end(done); + }); + }); + it('should update team name and type at once', async () => { const testTeamName = `test-team-name-changed${Date.now()}`; const updateResponse = await request From 6814a9f4655eb8d8828f5a1c86942cbfe72b90c5 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Wed, 9 Mar 2022 12:25:16 -0300 Subject: [PATCH 3/6] typo --- tests/end-to-end/api/25-teams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/end-to-end/api/25-teams.js b/tests/end-to-end/api/25-teams.js index f1ddb9bdd9851..fe6c0cb3fb4bd 100644 --- a/tests/end-to-end/api/25-teams.js +++ b/tests/end-to-end/api/25-teams.js @@ -1607,7 +1607,7 @@ describe('[Teams]', () => { it('should return the user subscription with the right notification preferences', async (done) => { await request .get(api('subscriptions.getOne')) - .set(credentials) + .set(userCredentials) .query({ roomId: testTeam3._id, }) From 003df13bfb37e2af35cf18e724a3abd7ea2df178 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Wed, 9 Mar 2022 14:34:59 -0300 Subject: [PATCH 4/6] removed unwantend method call --- tests/end-to-end/api/25-teams.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/end-to-end/api/25-teams.js b/tests/end-to-end/api/25-teams.js index fe6c0cb3fb4bd..67d584d6851a9 100644 --- a/tests/end-to-end/api/25-teams.js +++ b/tests/end-to-end/api/25-teams.js @@ -1570,8 +1570,7 @@ describe('[Teams]', () => { params: [{ emailNotificationMode: 'nothing' }], }), }) - .expect(200) - .done(); + .expect(200); }); it('should add user with prefs to team', async (done) => { From 4515dcbc15c870d89e25018cec1e07bb972a4301 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Mon, 14 Mar 2022 10:31:35 -0300 Subject: [PATCH 5/6] moved some tests to sync methods --- tests/end-to-end/api/25-teams.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/end-to-end/api/25-teams.js b/tests/end-to-end/api/25-teams.js index 67d584d6851a9..e97ff547283b8 100644 --- a/tests/end-to-end/api/25-teams.js +++ b/tests/end-to-end/api/25-teams.js @@ -1573,8 +1573,8 @@ describe('[Teams]', () => { .expect(200); }); - it('should add user with prefs to team', async (done) => { - await request + it('should add user with prefs to team', (done) => { + request .post(api('teams.addMembers')) .set(credentials) .send({ @@ -1603,8 +1603,8 @@ describe('[Teams]', () => { expect(response.body).to.have.property('success', true); }); - it('should return the user subscription with the right notification preferences', async (done) => { - await request + it('should return the user subscription with the right notification preferences', (done) => { + request .get(api('subscriptions.getOne')) .set(userCredentials) .query({ From ebdf4ebb19cfe9d83a895934b10e2ee11b0a2c97 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Mon, 14 Mar 2022 12:02:29 -0300 Subject: [PATCH 6/6] finally fixed tests --- tests/end-to-end/api/25-teams.js | 34 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/end-to-end/api/25-teams.js b/tests/end-to-end/api/25-teams.js index e97ff547283b8..83129073c1851 100644 --- a/tests/end-to-end/api/25-teams.js +++ b/tests/end-to-end/api/25-teams.js @@ -1554,10 +1554,26 @@ describe('[Teams]', () => { describe('should update team room to default and invite users with the right notification preferences', () => { let userWithPrefs; let userCredentials; + let createdRoom; before(async () => { userWithPrefs = await createUser(); userCredentials = await login(userWithPrefs.username, password); + + createdRoom = await request + .post(api('channels.create')) + .set(credentials) + .send({ + name: `${Date.now()}-testTeam3`, + }); + + await request + .post(api('teams.addRooms')) + .set(credentials) + .send({ + rooms: [createdRoom.body.channel._id], + teamId: testTeam3._id, + }); }); it('should update user prefs', async () => { @@ -1589,17 +1605,11 @@ describe('[Teams]', () => { .end(done); }); - it('should update team to auto-join', async () => { - const response = await request - .post(api('teams.update')) - .set(credentials) - .send({ - teamId: testTeam3._id, - data: { - isDefault: true, - }, - }); - + it('should update team channel to auto-join', async () => { + const response = await request.post(api('teams.updateRoom')).set(credentials).send({ + roomId: createdRoom.body.channel._id, + isDefault: true, + }); expect(response.body).to.have.property('success', true); }); @@ -1608,7 +1618,7 @@ describe('[Teams]', () => { .get(api('subscriptions.getOne')) .set(userCredentials) .query({ - roomId: testTeam3._id, + roomId: createdRoom.body.channel._id, }) .expect('Content-Type', 'application/json') .expect(200)