76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
|
const models = require('vn-loopback/server/server').models;
|
||
|
|
||
|
describe('expeditionState addExpeditionState()', () => {
|
||
|
it('should update the expedition states', async() => {
|
||
|
const tx = await models.ExpeditionState.beginTransaction({});
|
||
|
|
||
|
try {
|
||
|
const options = {transaction: tx};
|
||
|
const payload = [
|
||
|
{
|
||
|
expeditionFk: 5,
|
||
|
stateCode: 'ON DELIVERY'
|
||
|
},
|
||
|
];
|
||
|
|
||
|
await models.ExpeditionState.addExpeditionState(payload, options);
|
||
|
|
||
|
const expeditionState = await models.ExpeditionState.findOne({
|
||
|
where: {id: 5}
|
||
|
});
|
||
|
|
||
|
expect(expeditionState.typeFk).toEqual(1);
|
||
|
await tx.rollback();
|
||
|
} catch (e) {
|
||
|
await tx.rollback();
|
||
|
throw e;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
it('should throw an error an error when an stateCode does not exist', async() => {
|
||
|
const tx = await models.ExpeditionState.beginTransaction({});
|
||
|
let error;
|
||
|
|
||
|
try {
|
||
|
const options = {transaction: tx};
|
||
|
const payload = [
|
||
|
{
|
||
|
expeditionFk: 2,
|
||
|
stateCode: 'DUMMY'
|
||
|
}
|
||
|
];
|
||
|
await models.ExpeditionState.addExpeditionState(payload, options);
|
||
|
|
||
|
await tx.rollback();
|
||
|
} catch (e) {
|
||
|
error = e;
|
||
|
await tx.rollback();
|
||
|
}
|
||
|
|
||
|
expect(error.message).toContain('The state code: DUMMY does not exist.');
|
||
|
});
|
||
|
|
||
|
it('should throw an error when expeditionFk does not exist', async() => {
|
||
|
const tx = await models.ExpeditionState.beginTransaction({});
|
||
|
let error;
|
||
|
try {
|
||
|
const options = {transaction: tx};
|
||
|
const payload = [
|
||
|
{
|
||
|
expeditionFk: 50,
|
||
|
stateCode: 'LOST'
|
||
|
}
|
||
|
];
|
||
|
|
||
|
await models.ExpeditionState.addExpeditionState(payload, options);
|
||
|
|
||
|
await tx.rollback();
|
||
|
} catch (e) {
|
||
|
error = e;
|
||
|
await tx.rollback();
|
||
|
}
|
||
|
|
||
|
expect(error.message).toContain('The expedition with id: 50 does not exist.');
|
||
|
});
|
||
|
});
|