63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('upsertFixedPrice()', () => {
|
|
const now = new Date();
|
|
const fixedPriceId = 1;
|
|
let originalFixedPrice;
|
|
let originalItem;
|
|
|
|
beforeAll(async() => {
|
|
originalFixedPrice = await app.models.FixedPrice.findById(fixedPriceId);
|
|
originalItem = await app.models.Item.findById(originalFixedPrice.itemFk);
|
|
});
|
|
|
|
afterAll(async() => {
|
|
await originalFixedPrice.save();
|
|
await originalItem.save();
|
|
});
|
|
|
|
it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => {
|
|
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 app.models.FixedPrice.upsertFixedPrice(ctx, ctx.args.id);
|
|
|
|
delete ctx.args.started;
|
|
delete ctx.args.ended;
|
|
ctx.args.hasMinPrice = true;
|
|
|
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
|
});
|
|
|
|
it(`should toggle the hasMinPrice boolean if there's no minPrice and update the rest of the data`, async() => {
|
|
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 app.models.FixedPrice.upsertFixedPrice(ctx, ctx.args.id);
|
|
|
|
delete ctx.args.started;
|
|
delete ctx.args.ended;
|
|
ctx.args.hasMinPrice = false;
|
|
|
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
|
});
|
|
});
|