a
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
392dc5060a
commit
c91db1b429
|
@ -1,68 +0,0 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('VnUser addAlias()', () => {
|
||||
const employeeId = 1;
|
||||
const sysadminId = 66;
|
||||
const developerId = 9;
|
||||
const customerId = 2;
|
||||
const mailAlias = 1;
|
||||
it('should throw an error when user not has privileges', async() => {
|
||||
const ctx = {req: {accessToken: {userId: employeeId}}};
|
||||
const tx = await models.VnUser.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.VnUser.addAlias(ctx, employeeId, mailAlias, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain(`You don't have grant privilege`);
|
||||
});
|
||||
|
||||
it('should throw an error when user has privileges but not has the role from user', async() => {
|
||||
const ctx = {req: {accessToken: {userId: sysadminId}}};
|
||||
const tx = await models.VnUser.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.VnUser.addAlias(ctx, employeeId, mailAlias, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain(`You cannot assign an alias that you are not assigned to`);
|
||||
});
|
||||
|
||||
it('should add an alias', async() => {
|
||||
const ctx = {req: {accessToken: {userId: developerId}}};
|
||||
const tx = await models.VnUser.beginTransaction({});
|
||||
|
||||
let result;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const user = await models.VnUser.findById(developerId, null, options);
|
||||
await user.updateAttribute('hasGrant', true, options);
|
||||
|
||||
result = await models.VnUser.addAlias(ctx, customerId, mailAlias, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(result.mailAlias).toBe(mailAlias);
|
||||
expect(result.account).toBe(customerId);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue