70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('sale canEdit()', () => {
|
|
it('should return true if the role is production regardless of the saleTrackings', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const productionUserID = 49;
|
|
const ctx = {req: {accessToken: {userId: productionUserID}}};
|
|
|
|
const sales = [3];
|
|
|
|
const result = await models.Sale.canEdit(ctx, sales, options);
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return true if the role is not production and none of the sales has saleTracking', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const salesPersonUserID = 18;
|
|
const ctx = {req: {accessToken: {userId: salesPersonUserID}}};
|
|
|
|
const sales = [10];
|
|
|
|
const result = await models.Sale.canEdit(ctx, sales, options);
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return false if any of the sales has a saleTracking record', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const salesPersonUserID = 18;
|
|
const ctx = {req: {accessToken: {userId: salesPersonUserID}}};
|
|
|
|
const sales = [3];
|
|
|
|
const result = await models.Sale.canEdit(ctx, sales, options);
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|