salix/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js

64 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-04-05 06:43:47 +00:00
const models = require('vn-loopback/server/server').models;
describe('Item editFixedPrice()', () => {
it('should change the value of a given column for the selected buys', async() => {
const tx = await models.FixedPrice.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
args: {
search: '1'
},
req: {accessToken: {userId: 1}}
};
const [original] = await models.FixedPrice.filter(ctx, null, options);
const field = 'rate2';
const newValue = 99;
const lines = [{itemFk: original.itemFk, id: original.id}];
await models.FixedPrice.editFixedPrice(ctx, field, newValue, lines, null, options);
const [result] = await models.FixedPrice.filter(ctx, null, options);
expect(result[field]).toEqual(newValue);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should change the value of a given column for filter', async() => {
const tx = await models.FixedPrice.beginTransaction({});
const options = {transaction: tx};
try {
2023-04-21 10:49:03 +00:00
const filter = {where: {'it.categoryFk': 1}};
2023-04-05 06:43:47 +00:00
const ctx = {
args: {
filter: filter
},
req: {accessToken: {userId: 1}}
};
const field = 'rate2';
const newValue = 88;
2023-04-21 10:49:03 +00:00
await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter.where, options);
2023-04-05 06:43:47 +00:00
2023-04-11 08:23:33 +00:00
const [result] = await models.FixedPrice.filter(ctx, filter, options);
2023-04-05 06:43:47 +00:00
expect(result[field]).toEqual(newValue);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});