Skip to content
Merged
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
59 changes: 59 additions & 0 deletions tests/end-to-end/api/25-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect } from 'chai';

import { getCredentials, api, request, credentials } from '../../data/api-data';
import { updatePermission } from '../../data/permissions.helper.js';
import { createUser, login } from '../../data/users.helper';
import { password } from '../../data/user';

describe('[Teams]', () => {
before((done) => getCredentials(done));
Expand Down Expand Up @@ -1099,6 +1101,7 @@ describe('[Teams]', () => {

describe('/teams.update', () => {
let testTeam;
let testTeam2;
before('Create test team', (done) => {
const teamName = `test-team-name${ Date.now() }`;
request.post(api('teams.create'))
Expand All @@ -1113,6 +1116,20 @@ describe('[Teams]', () => {
});
});

before('Create test team', (done) => {
const teamName2 = `test-team-name${ Date.now() }`;
request.post(api('teams.create'))
.set(credentials)
.send({
name: teamName2,
type: 0,
})
.end((err, res) => {
testTeam2 = res.body.team;
done();
});
});

it('should update team name', async () => {
const testTeamName = `test-team-name-changed${ Date.now() }`;
const updateResponse = await request.post(api('teams.update'))
Expand Down Expand Up @@ -1157,5 +1174,47 @@ describe('[Teams]', () => {
const { teamInfo } = infoResponse.body;
expect(teamInfo).to.have.property('type', 1);
});

it('should update team name and type at once', async () => {
const testTeamName = `test-team-name-changed${ Date.now() }`;
const updateResponse = await request.post(api('teams.update'))
.set(credentials)
.send({
teamId: testTeam2._id,
data: {
name: testTeamName,
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 unauthorizedUser = await createUser();
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);
});
});
});