2020-12-14 15:09:17 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
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() => {
|
2020-12-14 15:09:17 +00:00
|
|
|
supplierOne = await app.models.Supplier.findById(1);
|
|
|
|
supplierTwo = await app.models.Supplier.findById(442);
|
|
|
|
});
|
|
|
|
|
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';
|
|
|
|
const supplier = await app.models.Supplier.findById(1);
|
|
|
|
|
|
|
|
await supplier.updateAttribute('payMethodFk', 4)
|
|
|
|
.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;
|
|
|
|
const supplier = await app.models.Supplier.findById(442);
|
|
|
|
await supplier.updateAttribute('payMethodFk', 4)
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|