From df5961a2a2bb196ca9e794c15fd73d80f5ce2973 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 4 Sep 2024 11:41:47 +0200 Subject: [PATCH] feat: refs #7663 wip test --- .../methods/ticket/specs/setWeight.spec.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 modules/ticket/back/methods/ticket/specs/setWeight.spec.js diff --git a/modules/ticket/back/methods/ticket/specs/setWeight.spec.js b/modules/ticket/back/methods/ticket/specs/setWeight.spec.js new file mode 100644 index 000000000..0d48d4adf --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/setWeight.spec.js @@ -0,0 +1,82 @@ +const {models} = require('vn-loopback/server/server'); + +fdescribe('ticket setWeight()', () => { + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); + let opts; + let tx; + const administrativeId = 5; + + beforeEach(async() => { + opts = {transaction: tx}; + tx = await models.Ticket.beginTransaction({}); + opts.transaction = tx; + }); + + afterEach(async() => await tx.rollback()); + + xit('should throw an error if the weight is already set', async() => { + try { + const ticketId = 1; + const weight = 10; + + await models.Ticket.setWeight(ctx, ticketId, weight, opts); + } catch (e) { + expect(e.message).toEqual('Weight already set'); + } + }); + + xit('should set the weight of a ticket', async() => { + const ticketId = 31; + const weight = 15; + + await models.Ticket.setWeight(ctx, ticketId, weight, opts); + + const ticket = await models.Ticket.findById(ticketId, null, opts); + + expect(ticket.weight).toEqual(weight); + }); + + it('should throw an error if the user does not have enough privileges', async() => { + ctx.req.accessToken.userId = administrativeId; + try { + const ticketId = 10; + const weight = 20; + + await models.Ticket.setWeight(ctx, ticketId, weight, opts); + } catch (e) { + expect(e.message).toEqual('You don\'t have enough privilegs'); + } + }); + + // it('should commit the transaction and return invoice ids if the ticket is invoiceable', async() => { + // const tx = await models.Ticket.beginTransaction({}); + + // try { + // const opts = {transaction: tx}; + + // const ticketId = 4; + // const weight = 25; + + // // Mock the necessary methods and data + // jest.spyOn(models.ACL, 'checkAccessAcl').mockResolvedValue(true); + // jest.spyOn(models.Client, 'findById').mockResolvedValue({ + // hasDailyInvoice: true, + // salesPersonUser: () => ({id: 1}) + // }); + // jest.spyOn(models.State, 'findOne').mockResolvedValue({alertLevel: 2}); + // jest.spyOn(models.TicketState, 'findOne').mockResolvedValue({alertLevel: 3}); + // jest.spyOn(models.Ticket, 'rawSql').mockResolvedValue([{taxArea: 'WORLD'}]); + // jest.spyOn(models.Ticket, 'invoiceTicketsAndPdf').mockResolvedValue([1001]); + + // const invoiceIds = await models.Ticket.setWeight(ctx, ticketId, weight, opts); + + // expect(invoiceIds).toEqual([1001]); + + // await tx.rollback(); + // } catch (e) { + // await tx.rollback(); + // throw e; + // } + // }); +});