add mail manager tests

This commit is contained in:
Girish Ramakrishnan
2022-02-15 10:09:57 -08:00
parent ac57e433b1
commit 125325721f

View File

@@ -11,7 +11,7 @@ const common = require('./common.js'),
users = require('../../users.js');
describe('Users API', function () {
const { setup, cleanup, serverUrl, owner, user } = common;
const { setup, cleanup, serverUrl, owner, user, dashboardDomain } = common;
const user2 = {
id: null,
@@ -21,6 +21,13 @@ describe('Users API', function () {
token: null
};
const user3 = {
id: null,
username: 'transientuser',
password: 'Foobar?1334',
email: 'transient@cloudron.LoCal',
};
const unnamedUser = {
id: null,
email: 'unnameduser@cloudron.local',
@@ -135,7 +142,7 @@ describe('Users API', function () {
it('create user with short name succeeds', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users`)
.query({ access_token: owner.token })
.send({ username: 'n', email: 'reserved@cloudron.local' });
.send({ username: 'n', email: 'singleletter@cloudron.local' });
expect(response.statusCode).to.equal(201);
});
@@ -410,7 +417,7 @@ describe('Users API', function () {
});
describe('role - user manager', function () {
it('can make second user a usermanager', async function () {
it('can make normal user a usermanager', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users/${user.id}`)
.query({ access_token: owner.token })
.send({ role: users.ROLE_USER_MANAGER });
@@ -470,12 +477,101 @@ describe('Users API', function () {
expect(response.statusCode).to.equal(403);
});
it('can remove normal user', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/users/${unnamedUser.id}`)
it('can create user as user manager', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users`)
.query({ access_token: user.token })
.send({ username: user3.username, email: user3.email });
expect(response.statusCode).to.equal(201);
user3.id = response.body.id;
});
it('can remove normal user as user manager', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/users/${user3.id}`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(204);
});
it('add mailbox fails', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
.send({ name: 'support', ownerId: owner.id, ownerType: 'user', active: true })
.query({ access_token: user.token })
.ok(() => true);
expect(response.statusCode).to.equal(403);
});
});
describe('role - mail manager', function () {
it('can make normal user a usermanager', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users/${user.id}`)
.query({ access_token: owner.token })
.send({ role: users.ROLE_MAIL_MANAGER });
expect(response.statusCode).to.equal(204);
});
it('can list users as mail manager', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/users`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(200);
expect(response.body.users).to.be.an(Array);
expect(response.body.users.length).to.be.greaterThan(3);
});
it('cannot change admin bit of self', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users/${user.id}`)
.query({ access_token: user.token })
.send({ role: users.ROLE_ADMIN })
.ok(() => true);
expect(response.statusCode).to.equal(409);
});
it('cannot remove admin', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/users/${owner.id}`)
.query({ access_token: user.token })
.ok(() => true);
expect(response.statusCode).to.equal(403);
});
it('can create user as mail manager', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/users`)
.query({ access_token: user.token })
.send({ username: user3.username, email: user3.email });
expect(response.statusCode).to.equal(201);
user3.id = response.body.id;
});
it('can remove normal user as mail manager', async function () {
const response = await superagent.del(`${serverUrl}/api/v1/users/${user3.id}`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(204);
});
it('add mailbox succeeds as mail manager', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
.send({ name: 'support', ownerId: owner.id, ownerType: 'user', active: true })
.query({ access_token: user.token });
expect(response.statusCode).to.equal(201);
});
it('list mailbox succeeds as mail manager', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`)
.query({ access_token: user.token });
expect(response.statusCode).to.equal(200);
expect(response.body.mailboxes.length).to.be(1);
expect(response.body.mailboxes[0].name).to.be('support');
});
});
describe('remove', function () {