77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('expeditionState addExpeditionState()', () => {
|
|
const ctx = beforeAll.getCtx();
|
|
beforeAll.mockLoopBackContext();
|
|
it('should update the expedition states', async() => {
|
|
const tx = await models.ExpeditionState.beginTransaction({});
|
|
try {
|
|
const options = {transaction: tx};
|
|
const payload = [
|
|
{
|
|
expeditionFk: 8,
|
|
stateCode: 'ON DELIVERY'
|
|
},
|
|
];
|
|
|
|
await models.ExpeditionState.addExpeditionState(ctx, 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(ctx, payload, options);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
error = e;
|
|
await tx.rollback();
|
|
}
|
|
|
|
expect(error.message).toContain('Invalid state code: DUMMY.');
|
|
});
|
|
|
|
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(ctx, payload, options);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
error = e;
|
|
await tx.rollback();
|
|
}
|
|
|
|
expect(error.message).toContain('Invalid expedition id: 50.');
|
|
});
|
|
});
|