const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { const options = {transaction: tx}; const payload = [ { expeditionFk: 8, stateCode: 'ON DELIVERY' }, ]; await models.ExpeditionState.addExpeditionState(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' } ]; await models.ExpeditionState.addExpeditionState(payload, options); await tx.rollback(); } catch (e) { error = e; await tx.rollback(); } 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' } ]; await models.ExpeditionState.addExpeditionState(payload, options); await tx.rollback(); } catch (e) { error = e; await tx.rollback(); } expect(error.message).toContain('Invalid expedition id: 50.'); }); });