2021-07-12 10:54:59 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2021-01-18 13:16:39 +00:00
|
|
|
|
|
|
|
describe('upsertFixedPrice()', () => {
|
|
|
|
const now = new Date();
|
|
|
|
const fixedPriceId = 1;
|
|
|
|
let originalFixedPrice;
|
|
|
|
|
|
|
|
beforeAll(async() => {
|
2021-07-12 10:54:59 +00:00
|
|
|
originalFixedPrice = await models.FixedPrice.findById(fixedPriceId);
|
2021-01-18 13:16:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => {
|
2021-07-12 10:54:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-01-18 13:16:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`should toggle the hasMinPrice boolean if there's no minPrice and update the rest of the data`, async() => {
|
2021-07-12 10:54:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-01-18 13:16:39 +00:00
|
|
|
});
|
|
|
|
});
|