2022-10-21 06:00:48 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
|
|
|
describe('sale usesMana()', () => {
|
|
|
|
const ctx = {
|
|
|
|
req: {
|
|
|
|
accessToken: {userId: 18}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should return that the worker uses mana', async() => {
|
|
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2022-10-26 07:04:53 +00:00
|
|
|
const teamOne = 96;
|
2022-10-21 06:00:48 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
|
|
|
|
|
|
|
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
2022-10-26 07:04:53 +00:00
|
|
|
await business.updateAttribute('departmentFk', teamOne, options);
|
2022-10-21 06:00:48 +00:00
|
|
|
|
|
|
|
const usesMana = await models.Sale.usesMana(ctx, options);
|
|
|
|
|
|
|
|
expect(usesMana).toBe(true);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return that the worker not uses mana', async() => {
|
|
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const usesMana = await models.Sale.usesMana(ctx, options);
|
|
|
|
|
|
|
|
expect(usesMana).toBe(false);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|