salix/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js

77 lines
2.2 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
describe('expeditionState addExpeditionState()', () => {
2024-06-14 06:39:57 +00:00
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 = [
{
2023-08-24 10:47:10 +00:00
expeditionFk: 8,
stateCode: 'ON DELIVERY'
},
];
2023-10-24 09:47:54 +00:00
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'
}
];
2023-10-24 09:47:54 +00:00
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
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.');
});
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);
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.');
});
});