57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
|
const {models} = require('vn-loopback/server/server');
|
||
|
|
||
|
fdescribe('locker model ', () => {
|
||
|
const productionBossId = 50;
|
||
|
const hrBuyerId = 124;
|
||
|
const hrId = 37;
|
||
|
const jessicaJonesId = 1110;
|
||
|
const bruceBannerId = 1109;
|
||
|
const lockerMaleId = 1;
|
||
|
const lockerFemaleId = 147;
|
||
|
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 locker = await models.Locker.findById(148, null, options);
|
||
|
await locker.updateAttributes({workerFk: jessicaJonesId}, options);
|
||
|
const oldLocker = await models.Locker.findById(lockerFemaleId, null, options);
|
||
|
|
||
|
expect(locker.workerFk).toEqual(jessicaJonesId);
|
||
|
expect(oldLocker.workerFk).toEqual(null);
|
||
|
});
|
||
|
});
|