const app = require(`${servicesDir}/item/server/server`); describe('regularize()', () => { const itemFk = 1; const warehouseFk = 1; const trashAddress = 11; let trashTicket; afterAll(async () => { await app.models.Ticket.destroyById(trashTicket.id); }); it('should create a new ticket and add a line', async () => { let ctx = {req: {accessToken: {userId: 18}}}; let query = `CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; let options = [itemFk, warehouseFk, true]; let [res] = await app.models.Item.rawSql(query, options); let visible = res[0].visible; let saleQuantity = visible - 11; let ticketFk = await app.models.Item.regularize(ctx, itemFk, 11, warehouseFk); let sale = await app.models.Sale.findOne({where: {ticketFk: ticketFk}}); trashTicket = await app.models.Ticket.findById(ticketFk); expect(sale.quantity).toEqual(saleQuantity); expect(sale.discount).toEqual(100); expect(trashTicket.addressFk).toEqual(trashAddress); }); });