54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
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 rowsBefore;
|
|
let rowsAfter;
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
const salesAssistant = await models.VnUser.findOne({
|
|
where: {name: 'salesAssistant'}
|
|
}, options);
|
|
|
|
rowsBefore = await models.ClientCredit.find({
|
|
where: {clientFk: instance.id},
|
|
order: 'created DESC',
|
|
}, options);
|
|
|
|
await models.ClientCredit.create({
|
|
amount: 355,
|
|
clientFk: instance.id,
|
|
workerFk: salesAssistant.id
|
|
}, options);
|
|
|
|
rowsAfter = await models.ClientCredit.find({
|
|
where: {clientFk: instance.id},
|
|
order: 'created DESC',
|
|
}, options);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
|
|
const FirstRowsBefore = rowsBefore[0];
|
|
const FirstRowsAfter = rowsAfter[0];
|
|
|
|
expect(FirstRowsAfter.id).toBeGreaterThan(FirstRowsBefore.id);
|
|
|
|
expect(rowsBefore.length).toBeGreaterThanOrEqual(clientConfig.maxCreditRows);
|
|
expect(rowsAfter.length).toEqual(clientConfig.maxCreditRows);
|
|
});
|
|
});
|
|
});
|