const {models} = require('vn-loopback/server/server'); describe('locker model ', () => { const productionBossId = 50; const hrBuyerId = 124; const hrId = 37; const jessicaJonesId = 1110; const bruceBannerId = 1109; const lockerMaleId = 3; const lockerFemaleId = 5; const lockerNewFemaleId = 6; 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); const locker = await models.Locker.findById(lockerNewFemaleId, null, options); await locker.updateAttributes({workerFk: jessicaJonesId}, options); const oldNowLocker = await models.Locker.findById(lockerFemaleId, null, options); expect(oldLocker.workerFk).toEqual(jessicaJonesId); expect(locker.workerFk).toEqual(jessicaJonesId); expect(oldNowLocker.workerFk).toEqual(null); }); });