fix: refs #6276 assignColletion
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-02-08 14:20:05 +01:00
parent d1ea1aafff
commit 33cca9bfe8
2 changed files with 40 additions and 4 deletions

View File

@ -20,10 +20,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId], myOptions);
const [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk');
const {'@vCollectionFk': collectionFk} = assignedCollection;
const [info, okPacket, {collectionFk}] = await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk); SELECT @vCollectionFk collectionFk',
[userId], myOptions);
if (!collectionFk) throw new UserError('There are not picking tickets');
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);

View File

@ -0,0 +1,38 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('ticket assignCollection()', () => {
let ctx;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 1106},
headers: {origin: 'http://localhost'},
__: value => value
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should throw an error when there is not picking tickets', async() => {
try {
await models.Collection.assignCollection(ctx, options);
} catch (e) {
expect(e.message).toEqual('There are not picking tickets');
}
});
});