2022-10-21 06:00:48 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2024-02-19 13:15:44 +00:00
|
|
|
describe('sale usesMana()', () => {
|
2024-02-19 13:13:36 +00:00
|
|
|
const ctx = {req: { accessToken: {userId: 18}}};
|
2022-10-21 06:00:48 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2024-02-19 13:13:36 +00:00
|
|
|
|
|
|
|
it('should return that the worker does not use mana because it is excluded', async() => {
|
|
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
const buyerId = 35;
|
|
|
|
const franceDepartmentId = 133;
|
|
|
|
const buyerCtx = {req: {accessToken: {userId: buyerId}}};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx}
|
|
|
|
|
|
|
|
await models.WorkerManaExcluded.create({workerFk: buyerId}, options);
|
|
|
|
await models.Business.updateAll({workerFk: buyerId}, {departmentFk: franceDepartmentId}, options);
|
|
|
|
|
|
|
|
const usesMana = await models.Sale.usesMana(buyerCtx, options);
|
|
|
|
|
|
|
|
expect(usesMana).toBe(false);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
2022-10-21 06:00:48 +00:00
|
|
|
});
|