salix/modules/client/back/methods/credit-classification/createWithInsurance.spec.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-07-08 13:53:30 +00:00
const models = require('vn-loopback/server/server').models;
2021-08-12 08:55:04 +00:00
const LoopBackContext = require('loopback-context');
describe('Client createWithInsurance', () => {
2021-08-12 08:55:04 +00:00
const activeCtx = {
accessToken: {userId: 19},
http: {
req: {
headers: {origin: 'http://localhost/'},
__: () => {}
}
}
};
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx,
});
});
2021-07-08 13:53:30 +00:00
it('should create a new client credit classification with insurance', async() => {
const tx = await models.Client.beginTransaction({});
2021-07-08 13:53:30 +00:00
try {
const options = {transaction: tx};
2023-01-16 14:18:24 +00:00
const data = {clientFk: 1101, started: Date.vnNow(), credit: 999, grade: 255};
2021-07-08 13:53:30 +00:00
const result = await models.CreditClassification.createWithInsurance(data, options);
2021-07-08 13:53:30 +00:00
expect(result.client).toEqual(1101);
2021-08-12 08:55:04 +00:00
const classifications = await models.CreditClassification.find(null, options);
const insurances = await models.CreditInsurance.find(null, options);
2021-07-08 13:53:30 +00:00
expect(classifications.length).toEqual(6);
expect(insurances.length).toEqual(4);
2021-07-08 13:53:30 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
2021-08-12 08:55:04 +00:00
throw e;
2021-07-08 13:53:30 +00:00
}
});
});