2021-11-10 14:11:42 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
const LoopBackContext = require('loopback-context');
|
2020-12-14 15:09:17 +00:00
|
|
|
|
2021-04-01 16:38:40 +00:00
|
|
|
describe('loopback model Supplier', () => {
|
2020-12-14 15:09:17 +00:00
|
|
|
let supplierOne;
|
|
|
|
let supplierTwo;
|
|
|
|
|
2021-10-15 12:45:41 +00:00
|
|
|
beforeAll(async() => {
|
2021-11-10 14:11:42 +00:00
|
|
|
supplierOne = await models.Supplier.findById(1);
|
|
|
|
supplierTwo = await models.Supplier.findById(442);
|
2021-12-14 07:23:11 +00:00
|
|
|
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
2020-12-14 15:09:17 +00:00
|
|
|
});
|
|
|
|
|
2021-10-15 12:45:41 +00:00
|
|
|
afterAll(async() => {
|
2020-12-14 15:09:17 +00:00
|
|
|
await supplierOne.updateAttribute('payMethodFk', supplierOne.payMethodFk);
|
|
|
|
await supplierTwo.updateAttribute('payMethodFk', supplierTwo.payMethodFk);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('payMethodFk', () => {
|
|
|
|
it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
|
|
|
|
let error;
|
|
|
|
const expectedError = 'You can not select this payment method without a registered bankery account';
|
2021-11-10 14:11:42 +00:00
|
|
|
const supplier = await models.Supplier.findById(1);
|
2020-12-14 15:09:17 +00:00
|
|
|
|
2021-11-10 07:46:09 +00:00
|
|
|
await supplier.updateAttribute('payMethodFk', 8)
|
2020-12-14 15:09:17 +00:00
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
|
|
|
|
expect(error.message).toContain(expectedError);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not throw if the payMethod id is valid', async() => {
|
|
|
|
let error;
|
2021-11-10 14:11:42 +00:00
|
|
|
const supplier = await models.Supplier.findById(442);
|
2020-12-14 15:09:17 +00:00
|
|
|
await supplier.updateAttribute('payMethodFk', 4)
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
|
|
|
|
2021-11-10 14:11:42 +00:00
|
|
|
expect(error).not.toBeDefined();
|
2020-12-14 15:09:17 +00:00
|
|
|
});
|
2021-12-14 07:23:11 +00:00
|
|
|
|
|
|
|
it('should have unchecked isPayMethodChecked', async() => {
|
|
|
|
const supplier = await models.Supplier.findById(442);
|
|
|
|
await supplier.updateAttribute('payMethodFk', 5);
|
|
|
|
|
|
|
|
const result = await models.Supplier.findById(442);
|
|
|
|
|
|
|
|
expect(result.isPayMethodChecked).toEqual(false);
|
|
|
|
});
|
2020-12-14 15:09:17 +00:00
|
|
|
});
|
|
|
|
});
|