refs #5887 feat: addback test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-07-11 13:22:54 +02:00
parent e1f12bea02
commit 5a5a1ed20b
3 changed files with 75 additions and 6 deletions

View File

@ -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);
});
});

View File

@ -38,9 +38,7 @@ export default class Controller extends Section {
}; };
return this.$http.post(`VnUsers/${this.$params.id}/removeAlias`, params) return this.$http.post(`VnUsers/${this.$params.id}/removeAlias`, params)
.then(() => this.refresh()) .then(() => this.refresh())
.then(() => this.vnApp.showSuccess( .then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
this.$t('Subscribed to alias!'))
);
} }
} }

View File

@ -25,8 +25,9 @@ describe('component vnUserAliases', () => {
describe('onAddSave()', () => { describe('onAddSave()', () => {
it('should add the new row', () => { it('should add the new row', () => {
controller.addData = {account: 1}; controller.addData = {account: 1};
controller.$params = {id: 1};
$httpBackend.expectPOST('MailAliasAccounts').respond(); $httpBackend.expectPOST('VnUsers/1/addAlias').respond();
$httpBackend.expectGET('MailAliasAccounts').respond('foo'); $httpBackend.expectGET('MailAliasAccounts').respond('foo');
controller.onAddSave(); controller.onAddSave();
$httpBackend.flush(); $httpBackend.flush();
@ -41,12 +42,14 @@ describe('component vnUserAliases', () => {
{id: 1, alias: 'foo'}, {id: 1, alias: 'foo'},
{id: 2, alias: 'bar'} {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]); controller.onRemove(controller.$.data[0]);
$httpBackend.flush(); $httpBackend.flush();
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]); expect(controller.$.data).toEqual({id: 2, alias: 'bar'});
expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.vnApp.showSuccess).toHaveBeenCalled();
}); });
}); });