const models = require('vn-loopback/server/server').models; describe('upsertFixedPrice()', () => { const now = new Date(); const fixedPriceId = 1; let originalFixedPrice; beforeAll(async() => { originalFixedPrice = await models.FixedPrice.findById(fixedPriceId); }); it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => { const tx = await models.FixedPrice.beginTransaction({}); try { const options = {transaction: tx}; const ctx = {args: { id: fixedPriceId, itemFk: originalFixedPrice.itemFk, warehouseFk: 1, rate2: 100, rate3: 300, started: now, ended: now, minPrice: 100, hasMinPrice: false }}; const result = await models.FixedPrice.upsertFixedPrice(ctx, options); delete ctx.args.started; delete ctx.args.ended; ctx.args.hasMinPrice = true; expect(result).toEqual(jasmine.objectContaining(ctx.args)); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); it(`should toggle the hasMinPrice boolean if there's no minPrice and update the rest of the data`, async() => { const tx = await models.FixedPrice.beginTransaction({}); try { const options = {transaction: tx}; const ctx = {args: { id: fixedPriceId, itemFk: originalFixedPrice.itemFk, warehouseFk: 1, rate2: 2.5, rate3: 2, started: now, ended: now, minPrice: 0, hasMinPrice: true }}; const result = await models.FixedPrice.upsertFixedPrice(ctx, options); delete ctx.args.started; delete ctx.args.ended; ctx.args.hasMinPrice = false; expect(result).toEqual(jasmine.objectContaining(ctx.args)); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); });