feat: refs #6276 test collection_addItem
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
8e5be5f5da
commit
6f35c62cd5
|
@ -34,6 +34,7 @@ module.exports = Self => {
|
|||
Self.addItem = async(ctx, code, quantity, ticketFk, warehouseFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
const $t = ctx.req.__;
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -47,7 +48,7 @@ module.exports = Self => {
|
|||
try {
|
||||
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk]);
|
||||
|
||||
if (!item.available) throw new UserError('We do not have availability for the selected item');
|
||||
if (!item?.available) throw new UserError($t('We do not have availability for the selected item'));
|
||||
|
||||
await models.Ticket.addSale(ctx, ticketFk, item.id, quantity, myOptions);
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
fdescribe('collection addItem()', () => {
|
||||
const quantity = 3;
|
||||
const ticketFk = 24;
|
||||
const warehouseFk = 1;
|
||||
beforeAll(async() => {
|
||||
activeCtx = {
|
||||
req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a new sale', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const code = '1111111111';
|
||||
|
||||
const salesBefore = await models.Sale.find(null, options);
|
||||
await models.Collection.addItem(activeCtx, code, quantity, ticketFk, warehouseFk, options);
|
||||
const salesAfter = await models.Sale.find(null, options);
|
||||
|
||||
expect(salesAfter.length).toEqual(salesBefore.length + 1);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when the item is not available', async() => {
|
||||
const code = '00000000000';
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.Collection.addItem(activeCtx, code, quantity, ticketFk, warehouseFk, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('We do not have availability for the selected item');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('itemBarcode delete()', () => {
|
||||
describe('itemBarcode delete()', () => {
|
||||
it('should delete a record by itemFk and code', async() => {
|
||||
const tx = await models.ItemBarcode.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
|
Loading…
Reference in New Issue