Skip to content

Commit 9497c2b

Browse files
committed
Merge commit 'c38904a44b167b912d031e2c7aedba17b8ca2515' into develop
* commit 'c38904a44b167b912d031e2c7aedba17b8ca2515': Added pre-commit hooks (mojaloop#37) Fixed bugs 474 & 480 (mojaloop#36) Fix for issues in building docker image (mojaloop#35) Incrementing version for central-settlement (mojaloop#34)
2 parents b0495db + c38904a commit 9497c2b

4 files changed

Lines changed: 93 additions & 13 deletions

File tree

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"swagmock": "~0.0.2",
3939
"tap-xunit": "1.4.0",
4040
"tape": "4.6.2",
41-
"tapes": "4.1.0"
41+
"tapes": "4.1.0",
42+
"pre-commit": "^1.2.2",
43+
"faucet": "0.0.1"
4244
},
4345
"scripts": {
4446
"start": "node src/server.js",

‎src/domain/settlementWindow/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
if (settlementWindows && settlementWindows.length > 0) {
5252
return settlementWindows
5353
} else {
54-
let err = new Error(`settlementWindow by filters: ${JSON.stringify(params.query)} not found`)
54+
let err = new Error(`settlementWindow by filters: ${JSON.stringify(params.query).replace(/"/g, '')} not found`)
5555
throw err
5656
}
5757
} catch (err) {

‎src/models/settlementWindow/facade.js‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ const Facade = {
7474
getByParams: async function ({ query }, enums = {}) {
7575
try {
7676
let { participantId, state, fromDateTime, toDateTime } = query
77-
state = state ? ` = "${state.toUpperCase()}"` : 'IS NOT NULL'
78-
fromDateTime = fromDateTime || new Date('01-01-1970').toISOString()
79-
toDateTime = toDateTime || new Date().toLocaleString()
8077
let result = await Db.settlementWindow.query(builder => {
8178
if (!participantId) {
82-
return builder
79+
let b = builder
8380
.leftJoin('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
8481
.select(
8582
'settlementWindow.settlementWindowId',
@@ -88,10 +85,13 @@ const Facade = {
8885
'settlementWindow.createdDate as createdDate',
8986
'swsc.createdDate as changedDate'
9087
)
91-
.whereRaw(`swsc.settlementWindowStateId ${state} AND settlementWindow.createdDate >= '${fromDateTime}' AND settlementWindow.createdDate <= '${toDateTime}'`)
92-
.orderBy('changedDate', 'desc')
88+
.orderBy('changedDate', 'desc').distinct()
89+
if (state) { b.where('swsc.settlementWindowStateId', state) }
90+
if (fromDateTime) { b.where('settlementWindow.createdDate', '>=', fromDateTime) }
91+
if (toDateTime) { b.where('settlementWindow.createdDate', '<=', toDateTime) }
92+
return b
9393
} else {
94-
return builder
94+
let b = builder
9595
.leftJoin('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
9696
.leftJoin('transferFulfilment AS tf', 'tf.settlementWindowId', 'settlementWindow.settlementWindowId')
9797
.leftJoin('transferParticipant AS tp', 'tp.transferId', 'tf.transferId')
@@ -103,8 +103,12 @@ const Facade = {
103103
'settlementWindow.createdDate as createdDate',
104104
'swsc.createdDate as changedDate'
105105
)
106-
.whereRaw(`pc.participantId = ${participantId} AND swsc.settlementWindowStateId ${state} AND settlementWindow.createdDate >= '${fromDateTime}' AND settlementWindow.createdDate <= '${toDateTime}'`)
107-
.orderBy('changedDate', 'desc')
106+
.orderBy('changedDate', 'desc').distinct()
107+
.where('pc.participantId', participantId)
108+
if (state) { b.where('swsc.settlementWindowStateId', state) }
109+
if (fromDateTime) { b.where('settlementWindow.createdDate', '>=', fromDateTime) }
110+
if (toDateTime) { b.where('settlementWindow.createdDate', '<=', toDateTime) }
111+
return b
108112
}
109113
})
110114
return result

‎test/unit/models/settlementWindow/facade.test.js‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Test('Settlement Window facade', async (settlementWindowFacadeTest) => {
4343
let whereStub
4444
let whereRawStub
4545
let orderByStub
46+
let distinctStub
4647
let selectStubResult
4748
let leftJoin2Stub
4849
let leftJoin3Stub
@@ -68,12 +69,22 @@ Test('Settlement Window facade', async (settlementWindowFacadeTest) => {
6869
whereStub = sandbox.stub()
6970
whereRawStub = sandbox.stub()
7071
orderByStub = sandbox.stub()
72+
distinctStub = sandbox.stub()
7173
selectStubResult = {
7274
first: firstStub.returns({
7375
where: whereStub
7476
}),
7577
whereRaw: whereRawStub.returns({
7678
orderBy: orderByStub
79+
}),
80+
orderBy: orderByStub.returns({
81+
distinct: distinctStub.returns({
82+
where: whereStub.returns({
83+
where: whereStub.returns({
84+
where: whereStub
85+
})
86+
})
87+
})
7788
})
7889
}
7990
leftJoin2Stub = sandbox.stub()
@@ -238,8 +249,68 @@ Test('Settlement Window facade', async (settlementWindowFacadeTest) => {
238249
'swsc.reason as reason',
239250
'settlementWindow.createdDate as createdDate',
240251
'swsc.createdDate as changedDate').calledOnce)
241-
test.ok(whereRawStub.calledOnce)
242252
test.ok(orderByStub.withArgs('changedDate', 'desc').calledOnce)
253+
test.ok(distinctStub.calledOnce)
254+
test.ok(whereStub.withArgs('pc.participantId', participantId).calledOnce)
255+
test.ok(whereStub.withArgs('swsc.settlementWindowStateId', state).calledOnce)
256+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '>=', fromDateTime).calledOnce)
257+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '<=', toDateTime).calledOnce)
258+
test.end()
259+
} catch (err) {
260+
Logger.error(`getByParams failed with error - ${err}`)
261+
test.fail()
262+
test.end()
263+
}
264+
})
265+
266+
await getByParamsTest.test('retrieve settlement windows by params', async test => {
267+
try {
268+
Db.settlementWindow.query.returns(Promise.resolve(settlementWindowResultStub))
269+
270+
query = { participantId }
271+
let result = await SettlementWindowFacade.getByParams({ query }, enums)
272+
test.ok(result, 'Result returned')
273+
test.ok(builderStub.leftJoin.withArgs('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId').calledOnce)
274+
test.ok(leftJoin2Stub.withArgs('transferFulfilment AS tf', 'tf.settlementWindowId', 'settlementWindow.settlementWindowId').calledOnce)
275+
test.ok(leftJoin3Stub.withArgs('transferParticipant AS tp', 'tp.transferId', 'tf.transferId').calledOnce)
276+
test.ok(leftJoin4Stub.withArgs('participantCurrency AS pc', 'pc.participantCurrencyId', 'tp.participantCurrencyId').calledOnce)
277+
test.ok(selectStub.withArgs('settlementWindow.settlementWindowId',
278+
'swsc.settlementWindowStateId as state',
279+
'swsc.reason as reason',
280+
'settlementWindow.createdDate as createdDate',
281+
'swsc.createdDate as changedDate').calledOnce)
282+
test.ok(orderByStub.withArgs('changedDate', 'desc').calledOnce)
283+
test.ok(distinctStub.calledOnce)
284+
test.ok(whereStub.withArgs('pc.participantId', participantId).calledOnce)
285+
test.ok(whereStub.withArgs('swsc.settlementWindowStateId', state).notCalled)
286+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '>=', fromDateTime).notCalled)
287+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '<=', toDateTime).notCalled)
288+
test.end()
289+
} catch (err) {
290+
Logger.error(`getByParams failed with error - ${err}`)
291+
test.fail()
292+
test.end()
293+
}
294+
})
295+
296+
await getByParamsTest.test('retrieve settlement windows by params', async test => {
297+
try {
298+
Db.settlementWindow.query.returns(Promise.resolve(settlementWindowResultStub))
299+
300+
query = { state, fromDateTime, toDateTime }
301+
let result = await SettlementWindowFacade.getByParams({ query }, enums)
302+
test.ok(result, 'Result returned')
303+
test.ok(builderStub.leftJoin.withArgs('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId').calledOnce)
304+
test.ok(selectStub.withArgs('settlementWindow.settlementWindowId',
305+
'swsc.settlementWindowStateId as state',
306+
'swsc.reason as reason',
307+
'settlementWindow.createdDate as createdDate',
308+
'swsc.createdDate as changedDate').calledOnce)
309+
test.ok(orderByStub.withArgs('changedDate', 'desc').calledOnce)
310+
test.ok(distinctStub.calledOnce)
311+
test.ok(whereStub.withArgs('swsc.settlementWindowStateId', state).calledOnce)
312+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '>=', fromDateTime).calledOnce)
313+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '<=', toDateTime).calledOnce)
243314
test.end()
244315
} catch (err) {
245316
Logger.error(`getByParams failed with error - ${err}`)
@@ -261,8 +332,11 @@ Test('Settlement Window facade', async (settlementWindowFacadeTest) => {
261332
'swsc.reason as reason',
262333
'settlementWindow.createdDate as createdDate',
263334
'swsc.createdDate as changedDate').calledOnce)
264-
test.ok(whereRawStub.calledOnce)
265335
test.ok(orderByStub.withArgs('changedDate', 'desc').calledOnce)
336+
test.ok(distinctStub.calledOnce)
337+
test.ok(whereStub.withArgs('swsc.settlementWindowStateId', state).notCalled)
338+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '>=', fromDateTime).notCalled)
339+
test.ok(whereStub.withArgs('settlementWindow.createdDate', '<=', toDateTime).notCalled)
266340
test.end()
267341
} catch (err) {
268342
Logger.error(`getByParams failed with error - ${err}`)

0 commit comments

Comments
 (0)