Skip to content

Commit

Permalink
[FIX] auto-join team channels not honoring user preferences (#24779)
Browse files Browse the repository at this point in the history
* fixed subscriptions w/o notifications pref

* added tests

* typo

* removed unwantend method call

* moved some tests to sync methods

* finally fixed tests
  • Loading branch information
ostjen authored Mar 18, 2022
1 parent 1be8923 commit ca0aeb8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/sdk/types/ITeamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IUserInfo {
username?: string;
name: string;
status: string;
settings?: Record<string, any>;
}

export interface ITeamMemberInfo {
Expand Down
1 change: 1 addition & 0 deletions server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
username: user.username,
name: user.name,
status: user.status,
settings: user.settings,
},
roles: record.roles,
createdBy: {
Expand Down
97 changes: 97 additions & 0 deletions tests/end-to-end/api/25-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1534,6 +1551,86 @@ 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;
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 () => {
await request
.post(methodCall('saveUserPreferences'))
.set(userCredentials)
.send({
message: JSON.stringify({
method: 'saveUserPreferences',
params: [{ emailNotificationMode: 'nothing' }],
}),
})
.expect(200);
});

it('should add user with prefs to team', (done) => {
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.body.channel._id,
isDefault: true,
});
expect(response.body).to.have.property('success', true);
});

it('should return the user subscription with the right notification preferences', (done) => {
request
.get(api('subscriptions.getOne'))
.set(userCredentials)
.query({
roomId: createdRoom.body.channel._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
Expand Down

0 comments on commit ca0aeb8

Please sign in to comment.