salix/modules/client/back/models/specs/clientCredit.spec.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
describe('Client Credit', () => {
const instance = {id: 1101, name: 'Bruce Banner'};
describe('after save', () => {
it('should delete old rows of clientCredit', async() => {
const tx = await models.ClientCredit.beginTransaction({});
const clientConfig = await models.ClientConfig.findOne({
where: {id: 1}
});
let rowsAfter;
try {
const options = {transaction: tx};
2022-05-03 13:17:34 +00:00
const ctx = {options};
const salesAssistant = await models.Account.findOne({
where: {name: 'salesAssistant'}
2022-05-04 05:46:47 +00:00
}, ctx.options);
2022-05-03 13:17:34 +00:00
await models.ClientCredit.create({
amount: 355,
clientFk: instance.id,
workerFk: salesAssistant.id
}, ctx.options);
rowsAfter = await models.ClientCredit.find({
2022-05-04 05:46:47 +00:00
where: {clientFk: instance.id},
}, ctx.options);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(rowsAfter.length).toEqual(clientConfig.maxCreditRows);
});
});
});