Skip to content

Commit

Permalink
Fixed issue when closing unexisting window (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrg authored Feb 8, 2019
1 parent 7890c2d commit 789810b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/models/settlement/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const settlementTransfersReserve = async function (settlementId, transactionTime
value: dfspPositionValue + dfspAmount,
changedDate: new Date().toISOString()
}
const message = getNotificationMessage(action, destination, payload)
const message = Facade.getNotificationMessage(action, destination, payload)
await Utility.produceGeneralMessage(Utility.ENUMS.NOTIFICATION, Utility.ENUMS.EVENT, message, Utility.ENUMS.STATE.SUCCESS)

// Select hubPosition FOR UPDATE
Expand Down
4 changes: 3 additions & 1 deletion src/models/settlementWindow/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const Facade = {
try {
const knex = await Db.getKnex()
let settlementWindowCurrentState = await Facade.getById({ settlementWindowId })
if (settlementWindowCurrentState && settlementWindowCurrentState.state !== enums.OPEN) {
if (!settlementWindowCurrentState) {
throw new Error(`2001: Window ${settlementWindowId} does NOT EXIST'`)
} if (settlementWindowCurrentState && settlementWindowCurrentState.state !== enums.OPEN) {
let err = new Error(`2001: Window ${settlementWindowId} is not OPEN'`)
throw err
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/models/settlementWindow/facade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,18 @@ Test('Settlement Window facade', async (settlementWindowFacadeTest) => {
}
})

await closeTest.test('throw error if the requested window does not exist', async test => {
try {
SettlementWindowFacade.getById = sandbox.stub().returns(undefined)
await SettlementWindowFacade.close(params)
test.fail('Error not thrown!')
} catch (err) {
Logger.error(`close failed with error - ${err}`)
test.ok(err instanceof Error, `Error "${err.message}" thrown as expected`)
test.end()
}
})

await closeTest.end()
} catch (err) {
Logger.error(`settlementFacadeTest failed with error - ${err}`)
Expand Down

0 comments on commit 789810b

Please sign in to comment.