refs #5468 feat: add testBack
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-05-23 13:08:10 +02:00
parent db55c3e81b
commit b7e3e9fa71
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,26 @@
const {models} = require('vn-loopback/server/server');
describe('Account addMailAlias()', () => {
it('should throw an error when the user is not a superior', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const employeeId = 1;
let error;
try {
await models.Account.addMailAlias(ctx, employeeId, 1);
} catch (e) {
error = e.message;
}
expect(error).toEqual(`You don't have enough privileges`);
});
it('should add a mail alias', async() => {
const ctx = {req: {accessToken: {userId: 9}}};
const employeeId = 1;
const result = await models.Account.addMailAlias(ctx, employeeId, 2);
expect(result).toBeDefined();
});
});

View File

@ -0,0 +1,35 @@
const {models} = require('vn-loopback/server/server');
describe('Account changeMailForwarding()', () => {
it('should throw an error when the user is not himself or a superior', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const developerId = 9;
let error;
try {
await models.Account.changeMailForwarding(ctx, developerId, 'alias@test.test');
} catch (e) {
error = e.message;
}
expect(error).toEqual(`You don't have enough privileges`);
});
it('should change a mail forwarding when the user is himself', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const employeeId = 1;
const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test');
expect(result).toBeDefined();
});
it('should change a mail forwarding when the user is a superior', async() => {
const ctx = {req: {accessToken: {userId: 9}}};
const employeeId = 1;
const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test');
expect(result).toBeDefined();
});
});

View File

@ -0,0 +1,24 @@
const {models} = require('vn-loopback/server/server');
describe('Account deleteMailAlias()', () => {
it('should throw an error when the user is not a superior', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
let error;
try {
await models.Account.deleteMailAlias(ctx, 1);
} catch (e) {
error = e.message;
}
expect(error).toEqual(`You don't have enough privileges`);
});
it('should delete a mail alias', async() => {
const ctx = {req: {accessToken: {userId: 9}}};
const result = await models.Account.deleteMailAlias(ctx, 1);
expect(result).toBeDefined();
});
});