2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-04-23 12:50:06 +00:00
|
|
|
|
|
|
|
describe('Client createWithInsurance', () => {
|
|
|
|
let classificationId;
|
|
|
|
|
2019-03-01 10:50:26 +00:00
|
|
|
afterAll(async done => {
|
2018-04-23 12:50:06 +00:00
|
|
|
await app.models.CreditClassification.destroyById(classificationId);
|
2019-03-01 10:50:26 +00:00
|
|
|
|
|
|
|
done();
|
2018-04-23 12:50:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should verify the classifications and insurances are untainted', async() => {
|
|
|
|
let classifications = await app.models.CreditClassification.find();
|
|
|
|
let insurances = await app.models.CreditInsurance.find();
|
|
|
|
|
|
|
|
expect(classifications.length).toEqual(5);
|
|
|
|
expect(insurances.length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not create the insurance if couldnt create the classification', async() => {
|
|
|
|
let error;
|
|
|
|
let data = {clientFk: null, started: Date.now(), credit: 999, grade: 255};
|
|
|
|
let ctx = {req: {accessToken: {userId: 101}}};
|
|
|
|
await app.models.CreditClassification.createWithInsurance(data, ctx)
|
2019-03-01 10:50:26 +00:00
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
2018-04-23 12:50:06 +00:00
|
|
|
|
2019-03-01 10:50:26 +00:00
|
|
|
expect(error.toString()).toBe('Error: ER_BAD_NULL_ERROR: Column \'client\' cannot be null');
|
2018-04-23 12:50:06 +00:00
|
|
|
|
|
|
|
let classifications = await app.models.CreditClassification.find();
|
|
|
|
let insurances = await app.models.CreditInsurance.find();
|
|
|
|
|
|
|
|
expect(classifications.length).toEqual(5);
|
|
|
|
expect(insurances.length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a new client credit classification with insurance', async() => {
|
|
|
|
let data = {clientFk: 101, started: Date.now(), credit: 999, grade: 255};
|
|
|
|
let ctx = {req: {accessToken: {userId: 101}}};
|
|
|
|
let result = await app.models.CreditClassification.createWithInsurance(data, ctx);
|
|
|
|
|
|
|
|
classificationId = result.id;
|
|
|
|
|
|
|
|
expect(result.client).toEqual(101);
|
|
|
|
|
|
|
|
let classifications = await app.models.CreditClassification.find();
|
|
|
|
let insurances = await app.models.CreditInsurance.find();
|
|
|
|
|
|
|
|
expect(classifications.length).toEqual(6);
|
|
|
|
expect(insurances.length).toEqual(4);
|
|
|
|
});
|
|
|
|
});
|