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

65 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
2020-01-23 12:31:07 +00:00
const LoopBackContext = require('loopback-context');
describe('Client createWithInsurance', () => {
2020-01-23 12:31:07 +00:00
const activeCtx = {
accessToken: {userId: 1101},
2020-01-23 12:31:07 +00:00
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
const ctx = {req: activeCtx};
activeCtx.http.req.__ = value => {
return value;
};
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};
2020-01-23 12:31:07 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
await app.models.CreditClassification.createWithInsurance(data, ctx)
.catch(e => {
error = e;
});
expect(error.toString()).toBe('Error: ER_BAD_NULL_ERROR: Column \'client\' cannot be null');
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: 1101, started: Date.now(), credit: 999, grade: 255};
2020-01-23 12:31:07 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
let result = await app.models.CreditClassification.createWithInsurance(data, ctx);
expect(result.client).toEqual(1101);
let classifications = await app.models.CreditClassification.find();
let insurances = await app.models.CreditInsurance.find();
expect(classifications.length).toEqual(6);
expect(insurances.length).toEqual(4);
2020-10-06 08:15:27 +00:00
// restore
await app.models.CreditClassification.destroyById(result.id);
});
});