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');
|
2018-04-23 12:50:06 +00:00
|
|
|
|
|
|
|
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({});
|
2018-04-23 12:50:06 +00:00
|
|
|
|
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};
|
2018-04-23 12:50:06 +00:00
|
|
|
|
2021-07-08 13:53:30 +00:00
|
|
|
const result = await models.CreditClassification.createWithInsurance(data, options);
|
2018-04-23 12:50:06 +00:00
|
|
|
|
2021-07-08 13:53:30 +00:00
|
|
|
expect(result.client).toEqual(1101);
|
2018-04-23 12:50:06 +00:00
|
|
|
|
2021-08-12 08:55:04 +00:00
|
|
|
const classifications = await models.CreditClassification.find(null, options);
|
|
|
|
const insurances = await models.CreditInsurance.find(null, options);
|
2018-04-23 12:50:06 +00:00
|
|
|
|
2021-07-08 13:53:30 +00:00
|
|
|
expect(classifications.length).toEqual(6);
|
|
|
|
expect(insurances.length).toEqual(4);
|
2018-04-23 12:50:06 +00:00
|
|
|
|
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
|
|
|
}
|
2018-04-23 12:50:06 +00:00
|
|
|
});
|
|
|
|
});
|