const {models} = require('vn-loopback/server/server'); describe('ticketService model ', () => { const originalTicketFk = 1; const refundTicketFk = 11; let tx; let opts; let ticketService; beforeEach(async() => { tx = await models.Sale.beginTransaction({}); opts = {transaction: tx}; ticketService = await models.TicketService.create({ ticketFk: refundTicketFk, description: 'test', quantity: 1, price: 100, taxClassFk: 1, ticketServiceTypeFk: 1 }, opts); }); afterEach(async() => { await tx.rollback(); }); describe('TicketService', () => { it('should allow updating description and quantity for non-refund tickets', async() => { await ticketService.updateAttributes({ ticketServiceTypeFk: 2, quantity: 5 }, opts); const updated = await models.TicketService.findById(ticketService.id, null, opts); expect(updated.description).not.toBe('test'); expect(updated.quantity).toBe(5); }); it('should only allow updating description for refund tickets', async() => { await models.TicketRefund.create({ refundTicketFk, originalTicketFk }, opts); await ticketService.updateAttributes({ ticketServiceTypeFk: 2 }, opts); try { await ticketService.updateAttributes({ ticketServiceTypeFk: 3, quantity: 5 }, opts); fail('Should have thrown error'); } catch (e) { expect(e.message).toBe('Only description can be modified in refund tickets'); } }); }); });