From 33cca9bfe8816c1650f73ac8ea074605020beb03 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 8 Feb 2024 14:20:05 +0100 Subject: [PATCH] fix: refs #6276 assignColletion --- back/methods/collection/assignCollection.js | 6 +-- .../collection/spec/assignCollection.spec.js | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 back/methods/collection/spec/assignCollection.spec.js diff --git a/back/methods/collection/assignCollection.js b/back/methods/collection/assignCollection.js index 67a10df51..575649de8 100644 --- a/back/methods/collection/assignCollection.js +++ b/back/methods/collection/assignCollection.js @@ -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); diff --git a/back/methods/collection/spec/assignCollection.spec.js b/back/methods/collection/spec/assignCollection.spec.js new file mode 100644 index 000000000..e8f3882a3 --- /dev/null +++ b/back/methods/collection/spec/assignCollection.spec.js @@ -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'); + } + }); +});