Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settlement v2 deon #237

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7260d6f
Completed the unit test for register handlers code.
Jan 15, 2020
4f39f4d
Domain settlement windows close , added unit test
Jan 16, 2020
d0441bd
Added more unit testing code to the settlement windows models facade
Jan 16, 2020
6146ca2
Added unit tests and fixed existing ones to cover unhappy lines in p…
Jan 17, 2020
21502be
Added unit tests to shared/setup to cope with the service types
Jan 20, 2020
1f34eed
Added unit test for shared setup : handler service type - and run han…
Jan 20, 2020
e35ce34
Added unit test for settlement window with a handler list
Jan 20, 2020
7fd53ee
Added unit test to increase code coverage for settlement window facade
Jan 20, 2020
2b83dee
Add unit test testing the settlement window state "not Processing"
Jan 20, 2020
5cbc561
Added unit test to roll back settlement window facade when error occurs
Jan 20, 2020
ed6310d
Added unit test on process to cover rollback on critical error and up…
Jan 21, 2020
ed17044
Added unit testcode to close window
Jan 21, 2020
cd12c05
Fixed the knex raw and .join isn't a function errors
Jan 22, 2020
4eb4b49
Changes:
Jan 22, 2020
72630b3
Added last unit test on the facade. the tests are being ran in isolat…
Jan 22, 2020
d9421ac
Added last knex builder stubs to facade unit tests
Jan 23, 2020
2a18b37
Merge pull request #1 from lazolalucas/settlement-V2-laz
Jan 23, 2020
84762c1
Combined the Stubs for the facade
Jan 23, 2020
f82cdcb
Merge branch 'settlement-v2-deon' of https://github.com/bothadeon/cen…
Jan 24, 2020
4cc18fc
Worked on branches to increase covereage
Jan 24, 2020
95e8560
Merge branch 'settlement-v2' of https://github.com/mojaloop/central-s…
Jan 24, 2020
e3bcb54
Merge branch 'settlement-v2' of https://github.com/ggrg/central-settl…
Jan 27, 2020
0726434
Merge branch 'settlement-v2' of https://github.com/mojaloop/central-s…
Jan 27, 2020
55b1b0c
Merge branch 'settlement-v2' of https://github.com/mojaloop/central-s…
Jan 28, 2020
ee05efe
Add modified code to get settlement windows by id.
Jan 28, 2020
5428c53
Added code changes for story #1180 and updated the unit tests
Jan 31, 2020
c36e19a
Added last unit test to up the code coverage
Feb 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/domain/settlementWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,25 @@ const hasFilters = require('./../../utils/truthyProperty')
const Producer = require('@mojaloop/central-services-stream').Util.Producer
const KafkaUtil = require('@mojaloop/central-services-shared').Util.Kafka
const SettlementWindowModel = require('../../models/settlementWindow')
const SettlementWindowContentModel = require('../../models/settlementWindowContent')
const StreamingProtocol = require('@mojaloop/central-services-shared').Util.StreamingProtocol
const Uuid = require('uuid4')

module.exports = {
getById: async function (params, enums) {
const settlementWindow = await SettlementWindowModel.getById(params, enums)
const settlementWindow = await SettlementWindowModel.getById(params) // check if params is correct

if (settlementWindow) return settlementWindow
else {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `settlementWindowId: ${params.settlementWindowId} not found`)
if (settlementWindow) {
const settlementWindowContent = await SettlementWindowContentModel.getBySettlementId(settlementWindow.settlementWindowId)

if (settlementWindowContent) {
settlementWindow.content = settlementWindowContent
return settlementWindow
} else {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, `No records for settlementWidowContentId : ${params.settlementWindowId} found`)
}
} else {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, `No record for settlementWindowId: ${params.settlementWindowId} found`)
}
},

Expand Down
4 changes: 2 additions & 2 deletions src/models/settlementWindowContent/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const Facade = {
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
.join('ledgerAccountType AS lat', 'lat.ledgerAccountTypeId', 'swc.ledgerAccountTypeId')
.where('swc.settlementId', id)
.select('swc.settlementWindowContentId AS id', 'swc.settlementWindowId', 'swcsc.settlementWindowStateId AS state',
'lat.name AS ledgerAccountType', 'swc.currencyId', 'swc.createdDate', 'swcsc.createdDate AS changedDate')
.select('swc.settlementWindowContentId AS id', 'swcsc.settlementWindowStateId AS state',
'lat.name AS ledgerAccountType', 'swc.currencyId', 'swc.createdDate', 'swcsc.createdDate AS changedDate', 'swc.settlementId AS settlementId')
}
}

Expand Down
75 changes: 72 additions & 3 deletions test/unit/domain/settlementWindow/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Sinon = require('sinon')
const Logger = require('@mojaloop/central-services-logger')
const SettlementWindowService = require('../../../../src/domain/settlementWindow')
const SettlementWindowModel = require('../../../../src/models/settlementWindow')
const SettlementWindowContentModel = require('../../../../src/models/settlementWindowContent')
const Producer = require('@mojaloop/central-services-stream').Util.Producer

Test('SettlementWindowService', async (settlementWindowServiceTest) => {
Expand All @@ -50,22 +51,90 @@ Test('SettlementWindowService', async (settlementWindowServiceTest) => {
const params = { settlementWindowId: 1 }
const enums = {}
const options = { logger: Logger }
const settlementWindowMock = { settlementWindowId: 1 }
const settlementWindowMock = { settlementWindowId: 1, content: { id: 11 } }
const settlementWindowContentMock = { id: 11 }

await getByIdTest.test('return settlement window', async test => {
try {
SettlementWindowContentModel.getBySettlementId = sandbox.stub().returns(settlementWindowContentMock)
SettlementWindowModel.getById = sandbox.stub().returns(settlementWindowMock)

const result = await SettlementWindowService.getById(params, enums, options)
test.ok(result, 'Result returned')
test.ok(SettlementWindowModel.getById.withArgs(params, enums).calledOnce, 'SettlementWindowModel.getById with args ... called once')
// test.ok(SettlementWindowModel.getById.withArgs(params, enums).calledOnce, 'SettlementWindowModel.getById with args ... called once')

SettlementWindowModel.getById = sandbox.stub().returns()
try {
await SettlementWindowService.getById(params, enums)
test.fail('Error expected, but not thrown!')
} catch (err) {
test.ok(err instanceof Error, `Error ${err.message} thrown`)
test.ok(SettlementWindowModel.getById.withArgs(params, enums).calledOnce, 'SettlementWindowModel.getById with args ... called once')
// test.ok(SettlementWindowModel.getById.withArgs(params, enums).calledOnce, 'SettlementWindowModel.getById with args ... called once')
}
test.end()
} catch (err) {
Logger.error(`getByIdTest failed with error - ${err}`)
test.fail()
test.end()
}
})

await getByIdTest.end()
} catch (err) {
Logger.error(`settlementWindowServiceTest failed with error - ${err}`)
getByIdTest.fail()
getByIdTest.end()
}
})

await settlementWindowServiceTest.test('getById should throw an error if no settlement window content is undefined', async getByIdTest => {
try {
const params = { settlementWindowId: 1 }
const enums = {}
const settlementWindowMock = { settlementWindowId: 1, content: { id: 11 } }

await getByIdTest.test('Throw an error when settlement window content is undefined', async test => {
try {
SettlementWindowContentModel.getBySettlementId = sandbox.stub().returns(undefined)
SettlementWindowModel.getById = sandbox.stub().returns(settlementWindowMock)
try {
await SettlementWindowService.getById(params, enums)
test.fail('Error expected, but not thrown!')
} catch (err) {
test.equal(err.message, 'No records for settlementWidowContentId : 1 found')
}
test.end()
} catch (err) {
Logger.error(`getByIdTest failed with error - ${err}`)
test.fail()
test.end()
}
})

await getByIdTest.end()
} catch (err) {
Logger.error(`settlementWindowServiceTest failed with error - ${err}`)
getByIdTest.fail()
getByIdTest.end()
}
})

await settlementWindowServiceTest.test('getById should throw an error if no settlement window content is found', async getByIdTest => {
try {
const params = { settlementWindowId: 1 }
const enums = {}
const settlementWindowMock = { settlementWindowId: 1, content: { } }
const settlementWindowContentMock = []

await getByIdTest.test('Throw an error when settlement window content is undefined', async test => {
try {
SettlementWindowContentModel.getBySettlementId = sandbox.stub().returns(settlementWindowContentMock)
SettlementWindowModel.getById = sandbox.stub().returns(settlementWindowMock)
try {
await SettlementWindowService.getById(params, enums)
test.pass('Error expected, but not thrown!')
} catch (err) {
test.equal(err.message, 'Cannot read property \'length\' of undefined')
}
test.end()
} catch (err) {
Expand Down