115 lines
3.4 KiB
JavaScript
115 lines
3.4 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
describe('saleTracking setPicked()', () => {
|
|
const saleFk = 1;
|
|
const originalQuantity = 10;
|
|
const code = 'PREPARED';
|
|
const isChecked = true;
|
|
const buyFk = 1;
|
|
const isScanned = false;
|
|
const quantity = 1;
|
|
const itemShelvingFk = 1;
|
|
|
|
beforeAll(async() => {
|
|
ctx = {
|
|
req: {
|
|
accessToken: {userId: 104},
|
|
headers: {origin: 'http://localhost'},
|
|
__: value => value
|
|
}
|
|
};
|
|
});
|
|
|
|
it('should throw an error if the line was not able to be marked', async() => {
|
|
const tx = await models.SaleTracking.beginTransaction({});
|
|
const options = {transaction: tx};
|
|
const code = 'FAKESTATE';
|
|
try {
|
|
await models.SaleTracking.setPicked(
|
|
ctx,
|
|
saleFk,
|
|
originalQuantity,
|
|
code,
|
|
isChecked,
|
|
buyFk,
|
|
isScanned,
|
|
quantity,
|
|
itemShelvingFk,
|
|
options
|
|
);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
const error = e;
|
|
|
|
expect(error.message).toEqual('The line could not be marked');
|
|
await tx.rollback();
|
|
}
|
|
});
|
|
|
|
it('should throw an error if there are duplicate salebuys', async() => {
|
|
const tx = await models.SaleTracking.beginTransaction({});
|
|
const options = {transaction: tx};
|
|
try {
|
|
await models.SaleTracking.setPicked(
|
|
ctx,
|
|
saleFk,
|
|
originalQuantity,
|
|
code,
|
|
isChecked,
|
|
buyFk,
|
|
isScanned,
|
|
quantity,
|
|
itemShelvingFk,
|
|
options
|
|
);
|
|
|
|
await models.SaleTracking.setPicked(
|
|
ctx,
|
|
saleFk,
|
|
originalQuantity,
|
|
code,
|
|
isChecked,
|
|
buyFk,
|
|
isScanned,
|
|
quantity,
|
|
itemShelvingFk,
|
|
options
|
|
);
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
const error = e;
|
|
|
|
expect(error.message).toEqual('The line could not be marked');
|
|
await tx.rollback();
|
|
}
|
|
});
|
|
|
|
it('should add an itemShelvingSale and Modify a saleTracking', async() => {
|
|
const tx = await models.SaleTracking.beginTransaction({});
|
|
const options = {transaction: tx};
|
|
try {
|
|
const itemShelvingSaleBefore = await models.ItemShelvingSale.find({}, options);
|
|
await models.SaleTracking.setPicked(
|
|
ctx,
|
|
saleFk,
|
|
originalQuantity,
|
|
code,
|
|
isChecked,
|
|
buyFk,
|
|
isScanned,
|
|
quantity,
|
|
itemShelvingFk,
|
|
options
|
|
);
|
|
const itemShelvingSaleAfter = await models.ItemShelvingSale.find({}, options);
|
|
const saleTracking = await models.SaleTracking.findOne({where: {saleFk, isChecked: false}}, options);
|
|
|
|
expect(itemShelvingSaleAfter.length).toEqual(itemShelvingSaleBefore.length + 1);
|
|
expect(saleTracking.isChecked).toBeFalse();
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
}
|
|
});
|
|
});
|