diff --git a/modules/ticket/back/methods/ticket/itemLack.js b/modules/ticket/back/methods/ticket/itemLack.js index b38408400..932d50b52 100644 --- a/modules/ticket/back/methods/ticket/itemLack.js +++ b/modules/ticket/back/methods/ticket/itemLack.js @@ -72,7 +72,8 @@ module.exports = Self => { Object.assign(myOptions, options); const conn = Self.dataSource.connector; let where = {}; - where = buildFilter(ctx.args, (param, value) => { + filter = Object.assign(ctx.args ?? {}, filter); + where = buildFilter(filter, (param, value) => { switch (param) { case 'id': return {'i.id': value}; @@ -85,9 +86,9 @@ module.exports = Self => { case 'size': return {'i.size': value}; case 'origen': - return {'w.name': value}; + return {'w.id': value}; case 'lack': - return {'lack': value}; + return {'sub.amount': value}; } }) ?? {}; diff --git a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js index 49651abb8..5bf1e422a 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js @@ -1,30 +1,153 @@ const models = require('vn-loopback/server/server').models; -describe('Item Lack', () => { +fdescribe('Item Lack', () => { + beforeAll(async() => { + ctx = { + req: { + accessToken: {}, + headers: {origin: 'http://localhost'}, + } + }; + }); + it('should return data with NO filters', async() => { const tx = await models.Ticket.beginTransaction({}); + const options = {transaction: tx}; + const filter = {}; try { - const options = {transaction: tx}; + const result = await models.Ticket.itemLack(ctx, filter, options); - const result = await models.Ticket.itemLack(3, options); - - expect(result).toBeFalsy(); + expect(result.length).toEqual(4); + await tx.rollback(); } catch (e) { + await tx.rollback(); throw e; } }); - it('should return data with filters', async() => { + it('should return data with filter.id', async() => { const tx = await models.Ticket.beginTransaction({}); + const options = {transaction: tx}; + const filter = { + id: 1 + }; try { - const options = {transaction: tx}; + const result = await models.Ticket.itemLack(ctx, filter, options); - const result = await models.Ticket.isEmpty(8, options); - - expect(result).toBeFalsy(); + expect(result.length).toEqual(1); + await tx.rollback(); } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return data with filter.longname', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + longname: 'Ranged weapon longbow 200cm' + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + xit('should return data with filter.name', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + name: 1 + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return data with filter.color', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + color: 'BRW' + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return data with filter.origen', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + origen: 2 + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(3); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return data with filter.size', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + size: '200' + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return data with filter.lack', async() => { + const tx = await models.Ticket.beginTransaction({}); + + const options = {transaction: tx}; + const filter = { + lack: '-100' + }; + try { + const result = await models.Ticket.itemLack(ctx, filter, options); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); throw e; } });