2023-08-24 08:01:07 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
|
|
|
describe('expeditionState addExpeditionState()', () => {
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
2024-10-25 11:48:27 +00:00
|
|
|
beforeAll.mockLoopBackContext();
|
2023-08-24 08:01:07 +00:00
|
|
|
it('should update the expedition states', async() => {
|
|
|
|
const tx = await models.ExpeditionState.beginTransaction({});
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
const payload = [
|
|
|
|
{
|
2023-08-24 10:47:10 +00:00
|
|
|
expeditionFk: 8,
|
2023-08-24 08:01:07 +00:00
|
|
|
stateCode: 'ON DELIVERY'
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-10-24 09:47:54 +00:00
|
|
|
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
|
2023-08-24 08:01:07 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
];
|
2023-10-24 09:47:54 +00:00
|
|
|
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
|
2023-08-24 08:01:07 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
|
2023-08-24 10:47:10 +00:00
|
|
|
expect(error.message).toContain('Invalid state code: DUMMY.');
|
2023-08-24 08:01:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-10-24 09:47:54 +00:00
|
|
|
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
|
2023-08-24 08:01:07 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
|
2023-08-24 10:47:10 +00:00
|
|
|
expect(error.message).toContain('Invalid expedition id: 50.');
|
2023-08-24 08:01:07 +00:00
|
|
|
});
|
|
|
|
});
|