salix/modules/ticket/back/methods/sale-tracking/specs/updateTracking.spec.js

105 lines
3.1 KiB
JavaScript

const {models} = require('vn-loopback/server/server');
describe('saleTracking updateTracking()', () => {
const saleFk = 1;
const originalQuantity = 10;
const code = 'PREPARED';
const isChecked = true;
const buyFk = 1;
const isScanned = false;
beforeAll(async() => {
ctx = {
req: {
accessToken: {userId: 104},
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should throw an error if the state does not exist', async() => {
const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx};
const code = 'FAKESTATE';
try {
await models.SaleTracking.updateTracking(
ctx,
saleFk,
originalQuantity,
code,
isChecked,
buyFk,
isScanned,
options
);
await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toEqual('this state does not exist');
await tx.rollback();
}
});
it('should add a new saleTracking and saleBuy', async() => {
const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx};
try {
const saleTrackingBefore = await models.SaleTracking.find(null, options);
const saleBuyBefore = await models.SaleBuy.find(null, options);
await models.SaleTracking.updateTracking(
ctx,
saleFk,
originalQuantity,
code,
isChecked,
buyFk,
isScanned,
options
);
const saleTrackingAfter = await models.SaleTracking.find(null, options);
const saleBuyAfter = await models.SaleBuy.find(null, options);
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
expect(saleBuyAfter.length).toEqual(saleBuyBefore.length + 1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should only update a saleTracking', async() => {
const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx};
const saleFk = 2;
try {
const saleTrackingBefore = await models.SaleTracking.find(null, options);
await models.SaleTracking.updateTracking(
ctx,
saleFk,
originalQuantity,
code,
isChecked,
buyFk,
isScanned,
options
);
const saleTrackingAfter = await models.SaleTracking.find(null, options);
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});