This commit is contained in:
parent
e1f12bea02
commit
5a5a1ed20b
|
@ -0,0 +1,68 @@
|
|||
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 don't have the alias assigned and you can't assign it to another user`);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
|
@ -38,9 +38,7 @@ export default class Controller extends Section {
|
|||
};
|
||||
return this.$http.post(`VnUsers/${this.$params.id}/removeAlias`, params)
|
||||
.then(() => this.refresh())
|
||||
.then(() => this.vnApp.showSuccess(
|
||||
this.$t('Subscribed to alias!'))
|
||||
);
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,9 @@ describe('component vnUserAliases', () => {
|
|||
describe('onAddSave()', () => {
|
||||
it('should add the new row', () => {
|
||||
controller.addData = {account: 1};
|
||||
controller.$params = {id: 1};
|
||||
|
||||
$httpBackend.expectPOST('MailAliasAccounts').respond();
|
||||
$httpBackend.expectPOST('VnUsers/1/addAlias').respond();
|
||||
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
|
||||
controller.onAddSave();
|
||||
$httpBackend.flush();
|
||||
|
@ -41,12 +42,14 @@ describe('component vnUserAliases', () => {
|
|||
{id: 1, alias: 'foo'},
|
||||
{id: 2, alias: 'bar'}
|
||||
];
|
||||
controller.$params = {id: 1};
|
||||
|
||||
$httpBackend.expectDELETE('MailAliasAccounts/1').respond();
|
||||
$httpBackend.expectPOST('VnUsers/1/removeAlias').respond();
|
||||
$httpBackend.expectGET('MailAliasAccounts').respond(controller.$.data[1]);
|
||||
controller.onRemove(controller.$.data[0]);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]);
|
||||
expect(controller.$.data).toEqual({id: 2, alias: 'bar'});
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue