salix/modules/worker/back/models/specs/locker.spec.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-05-13 11:19:28 +00:00
const {models} = require('vn-loopback/server/server');
2024-05-13 12:00:19 +00:00
describe('locker model ', () => {
2024-05-13 11:19:28 +00:00
const productionBossId = 50;
const hrBuyerId = 124;
const hrId = 37;
const jessicaJonesId = 1110;
const bruceBannerId = 1109;
2024-05-28 10:05:09 +00:00
const lockerMaleId = 3;
const lockerFemaleId = 5;
const lockerNewFemaleId = 6;
2024-05-13 11:19:28 +00:00
let ctx;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: hrId},
headers: {origin: 'http://localhost'}
},
};
options = {transaction: tx};
tx = await models.Locker.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should allocate a locker', async() => {
ctx.req.accessToken.userId = productionBossId;
const locker = await models.Locker.findById(lockerMaleId, null, options);
await locker.updateAttributes({workerFk: bruceBannerId}, options);
expect(locker.workerFk).toEqual(bruceBannerId);
});
it('should take away a locker', async() => {
ctx.req.accessToken.userId = hrBuyerId;
const locker = await models.Locker.findById(lockerFemaleId, null, options);
await locker.updateAttributes({workerFk: null}, options);
expect(locker.workerFk).toEqual(null);
});
it('should change a locker', async() => {
const oldLocker = await models.Locker.findById(lockerFemaleId, null, options);
2024-05-28 10:05:09 +00:00
const locker = await models.Locker.findById(lockerNewFemaleId, null, options);
await locker.updateAttributes({workerFk: jessicaJonesId}, options);
const oldNowLocker = await models.Locker.findById(lockerFemaleId, null, options);
2024-05-13 11:19:28 +00:00
2024-05-28 10:05:09 +00:00
expect(oldLocker.workerFk).toEqual(jessicaJonesId);
2024-05-13 11:19:28 +00:00
expect(locker.workerFk).toEqual(jessicaJonesId);
2024-05-28 10:05:09 +00:00
expect(oldNowLocker.workerFk).toEqual(null);
2024-05-13 11:19:28 +00:00
});
});