diff --git a/apps/meteor/tests/end-to-end/api/teams.ts b/apps/meteor/tests/end-to-end/api/teams.ts index 90444ae7e913c..5aa455ac985b3 100644 --- a/apps/meteor/tests/end-to-end/api/teams.ts +++ b/apps/meteor/tests/end-to-end/api/teams.ts @@ -2616,440 +2616,3 @@ describe('/teams.update', () => { }); }); }); - -describe('/teams.updateRoom', () => { - let publicRoom: IRoom; - let publicTeam: ITeam; - const name = `teamName-update-room-${Date.now()}`; - - before(async () => { - publicRoom = (await createRoom({ type: 'c', name: `public-update-room-${Date.now()}` })).body.channel; - publicTeam = await createTeam(credentials, name, TEAM_TYPE.PUBLIC); - await request - .post(api('teams.addRooms')) - .set(credentials) - .send({ - rooms: [publicRoom._id], - teamId: publicTeam._id, - }); - }); - - after(async () => { - await deleteTeam(credentials, name); - await Promise.all([ - updatePermission('edit-team-channel', ['admin', 'owner', 'moderator']), - deleteRoom({ type: 'c', roomId: publicRoom._id }), - ]); - }); - - it('should throw an error if no permission', (done) => { - void updatePermission('edit-team-channel', []).then(() => { - void request - .post(api('teams.updateRoom')) - .set(credentials) - .send({ - roomId: publicRoom._id, - isDefault: true, - }) - .expect('Content-Type', 'application/json') - .expect(403) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body).to.have.property('error'); - expect(res.body.error).to.be.equal('unauthorized'); - }) - .end(done); - }); - }); - - it('should set room to team default', (done) => { - void updatePermission('edit-team-channel', ['admin']).then(() => { - void request - .post(api('teams.updateRoom')) - .set(credentials) - .send({ - roomId: publicRoom._id, - isDefault: true, - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('room'); - expect(res.body.room).to.have.property('teamId', publicTeam._id); - expect(res.body.room).to.have.property('teamDefault', true); - }) - .end(done); - }); - }); - - describe('team auto-join', () => { - let testTeam: ITeam; - let createdRoom: IRoom; - let testUser1: TestUser; - let testUser2: TestUser; - - before(async () => { - const [testUser1Result, testUser2Result] = await Promise.all([createUser(), createUser()]); - - testUser1 = testUser1Result; - testUser2 = testUser2Result; - }); - - beforeEach(async () => { - const createTeamPromise = createTeam(credentials, `test-team-name${Date.now()}`, 0); - const createRoomPromise = createRoom({ name: `test-room-name${Date.now()}`, type: 'c' }); - const [testTeamCreationResult, testRoomCreationResult] = await Promise.all([createTeamPromise, createRoomPromise]); - - testTeam = testTeamCreationResult; - createdRoom = testRoomCreationResult.body.channel; - - await request - .post(api('teams.addRooms')) - .set(credentials) - .expect(200) - .send({ - rooms: [createdRoom._id], - teamName: testTeam.name, - }); - }); - - afterEach(() => Promise.all([deleteTeam(credentials, testTeam.name), deleteRoom({ roomId: createdRoom._id, type: 'c' })])); - - after(() => Promise.all([updateSetting('API_User_Limit', 500), deleteUser(testUser1), deleteUser(testUser2)])); - - it('should add members when the members count is less than or equal to the API_User_Limit setting', async () => { - await updateSetting('API_User_Limit', 2); - - await addMembers(credentials, testTeam.name, [testUser1._id, testUser2._id]); - await request - .post(api('teams.updateRoom')) - .set(credentials) - .send({ - roomId: createdRoom._id, - isDefault: true, - }) - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.nested.property('room.usersCount').and.to.be.equal(3); - }); - }); - - it('should not add all members when we update a team channel to be auto-join and the members count is greater than the API_User_Limit setting', async () => { - await updateSetting('API_User_Limit', 1); - - await addMembers(credentials, testTeam.name, [testUser1._id, testUser2._id]); - await request - .post(api('teams.updateRoom')) - .set(credentials) - .send({ - roomId: createdRoom._id, - isDefault: true, - }) - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.nested.property('room.usersCount').and.to.be.equal(2); - }); - }); - }); -}); - -describe('/teams.removeRoom', () => { - let publicRoom: IRoom; - let publicTeam: ITeam; - const name = `teamName-remove-room-${Date.now()}`; - - before(async () => { - publicRoom = (await createRoom({ type: 'c', name: `public-remove-room-${Date.now()}` })).body.channel; - publicTeam = await createTeam(credentials, name, TEAM_TYPE.PUBLIC); - await request - .post(api('teams.addRooms')) - .set(credentials) - .send({ - rooms: [publicRoom._id], - teamId: publicTeam._id, - }); - }); - - after(async () => { - await deleteTeam(credentials, name); - await Promise.all([ - updatePermission('edit-team-channel', ['admin', 'owner', 'moderator']), - deleteRoom({ type: 'c', roomId: publicRoom._id }), - ]); - }); - - after(() => - Promise.all([ - updatePermission('remove-team-channel', ['admin', 'owner', 'moderator']), - deleteRoom({ type: 'c', roomId: publicRoom._id }), - deleteTeam(credentials, name), - ]), - ); - - it('should throw an error if no permission', (done) => { - void updatePermission('remove-team-channel', []).then(() => { - void request - .post(api('teams.removeRoom')) - .set(credentials) - .send({ - roomId: publicRoom._id, - teamId: publicTeam._id, - }) - .expect('Content-Type', 'application/json') - .expect(403) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body).to.have.property('error'); - expect(res.body.error).to.be.equal('unauthorized'); - }) - .end(done); - }); - }); - - it('should remove room from team', (done) => { - void updatePermission('remove-team-channel', ['admin']).then(() => { - void request - .post(api('teams.removeRoom')) - .set(credentials) - .send({ - roomId: publicRoom._id, - teamId: publicTeam._id, - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('room'); - expect(res.body.room).to.not.have.property('teamId'); - expect(res.body.room).to.not.have.property('teamDefault'); - }) - .end(done); - }); - }); -}); - -describe('/teams.update', () => { - let testTeam: ITeam; - let testTeam2: ITeam; - let testTeam3: ITeam; - const teamName = `test-team-name1${Date.now()}`; - const teamName2 = `test-team-name2${Date.now()}`; - const teamName3 = `test-team-name3${Date.now()}`; - const testTeamName = `test-team-name-changed${Date.now()}-1`; - const testTeamName2 = `test-team-name-changed${Date.now()}-2`; - let unauthorizedUser: TestUser; - - before('Create test team', (done) => { - void request - .post(api('teams.create')) - .set(credentials) - .send({ - name: teamName, - type: 0, - }) - .end((_err, res) => { - testTeam = res.body.team; - done(); - }); - }); - - before('Create test team', (done) => { - void request - .post(api('teams.create')) - .set(credentials) - .send({ - name: teamName2, - type: 0, - }) - .end((_err, res) => { - testTeam2 = res.body.team; - done(); - }); - }); - - before('Create test team', (done) => { - void request - .post(api('teams.create')) - .set(credentials) - .send({ - name: teamName3, - type: 0, - }) - .end((_err, res) => { - testTeam3 = res.body.team; - done(); - }); - }); - - before(async () => { - unauthorizedUser = await createUser(); - }); - - after(() => - Promise.all([...[testTeamName, testTeamName2, teamName3].map((name) => deleteTeam(credentials, name)), deleteUser(unauthorizedUser)]), - ); - - it('should update team name', async () => { - const updateResponse = await request - .post(api('teams.update')) - .set(credentials) - .send({ - teamId: testTeam._id, - data: { - name: testTeamName, - }, - }); - - expect(updateResponse.body).to.have.property('success', true); - - const infoResponse = await request.get(api('teams.info')).set(credentials).query({ teamId: testTeam._id }); - - expect(infoResponse.body).to.have.property('success', true); - - const { teamInfo } = infoResponse.body; - expect(teamInfo).to.have.property('name', testTeamName); - }); - - it('should update team type', async () => { - const updateResponse = await request - .post(api('teams.update')) - .set(credentials) - .send({ - teamId: testTeam._id, - data: { - type: 1, - }, - }); - - expect(updateResponse.body).to.have.property('success', true); - - const infoResponse = await request.get(api('teams.info')).set(credentials).query({ teamId: testTeam._id }); - - expect(infoResponse.body).to.have.property('success', true); - - const { teamInfo } = infoResponse.body; - expect(teamInfo).to.have.property('type', 1); - }); - - it('should update team name and type at once', async () => { - const updateResponse = await request - .post(api('teams.update')) - .set(credentials) - .send({ - teamId: testTeam2._id, - data: { - name: testTeamName2, - type: 1, - }, - }); - - expect(updateResponse.body).to.have.property('success', true); - - const infoResponse = await request.get(api('teams.info')).set(credentials).query({ teamId: testTeam2._id }); - - expect(infoResponse.body).to.have.property('success', true); - - const { teamInfo } = infoResponse.body; - expect(teamInfo).to.have.property('type', 1); - }); - - it('should not update team if permissions are not met', async () => { - const unauthorizedUserCredentials = await login(unauthorizedUser.username, password); - - const res = await request - .post(api('teams.update')) - .set(unauthorizedUserCredentials) - .send({ - teamId: testTeam._id, - data: { - name: 'anyname', - }, - }) - .expect('Content-Type', 'application/json') - .expect(403); - - expect(res.body).to.have.property('success', false); - }); - - describe('should update team room to default and invite users with the right notification preferences', () => { - let userWithPrefs: TestUser; - let userCredentials: Credentials; - let createdRoom: IRoom; - - before(async () => { - userWithPrefs = await createUser(); - userCredentials = await login(userWithPrefs.username, password); - - createdRoom = (await createRoom({ type: 'c', name: `${Date.now()}-testTeam3` })).body.channel; - - await request - .post(api('teams.addRooms')) - .set(credentials) - .send({ - rooms: [createdRoom._id], - teamId: testTeam3._id, - }); - }); - - after(() => Promise.all([deleteUser(userWithPrefs), deleteRoom({ type: 'c', roomId: createdRoom._id })])); - - it('should update user prefs', async () => { - await request - .post(methodCall('saveUserPreferences')) - .set(userCredentials) - .send({ - message: JSON.stringify({ - method: 'saveUserPreferences', - params: [{ emailNotificationMode: 'nothing' }], - id: 'id', - msg: 'method', - }), - }) - .expect(200); - }); - - it('should add user with prefs to team', (done) => { - void request - .post(api('teams.addMembers')) - .set(credentials) - .send({ - teamName: testTeam3.name, - members: [ - { - userId: userWithPrefs._id, - roles: ['member'], - }, - ], - }) - .end(done); - }); - - it('should update team channel to auto-join', async () => { - const response = await request.post(api('teams.updateRoom')).set(credentials).send({ - roomId: createdRoom._id, - isDefault: true, - }); - expect(response.body).to.have.property('success', true); - }); - - it('should return the user subscription with the right notification preferences', (done) => { - void request - .get(api('subscriptions.getOne')) - .set(userCredentials) - .query({ - roomId: createdRoom._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); - }); - }); -});