const app = require(`${servicesDir}/ticket/server/server`); describe('ticket listSaleTracking()', () => { it('should throw an error if the ticket is not editable and the user isnt production', async() => { let ctx = {req: {accessToken: {userId: 110}}}; let params = {ticketFk: 2, stateFk: 3}; let error; try { await app.models.TicketTracking.changeState(ctx, params); } catch (e) { error = e; } expect(error).toEqual(new Error(`You don't have enough privileges to change the state of this ticket`)); }); it('should be able to create a ticket tracking line for a not editable ticket if the user has te production role', async() => { let ctx = {req: {accessToken: {userId: 50}}}; let params = {ticketFk: 20, stateFk: 3}; let res = await app.models.TicketTracking.changeState(ctx, params); expect(res.__data.ticketFk).toBe(params.ticketFk); expect(res.__data.stateFk).toBe(params.stateFk); expect(res.__data.workerFk).toBe(50); expect(res.__data.id).toBeDefined(); }); it('return an array with the created ticket tracking line', async() => { let ctx = {req: {accessToken: {userId: 108}}}; let params = {ticketFk: 1, stateFk: 3}; let res = await app.models.TicketTracking.changeState(ctx, params); expect(res.__data.ticketFk).toBe(params.ticketFk); expect(res.__data.stateFk).toBe(params.stateFk); expect(res.__data.workerFk).toBe(110); expect(res.__data.id).toBeDefined(); }); });