Skip to content

Commit

Permalink
Feature/#248 merge all the changes (#73)
Browse files Browse the repository at this point in the history
* Added Unhappy line test to improve code coverage

* transfer model integration done, fixed bug in the model, fixed the unit test accordingly

* extension coverage 100%

* Fulfil handler commit implementation

* TODO: FiveBellsCondition.fulfillmentToCondition comment changed

* Added destroyByName method's happy and Unhappy line Unit tests, Code coverage is now 100% on participant/model.js

* Unit tests for fulfil success

* Merge vgenev feature/#248

* Starting to add unhappy lines on transferstatechange read-model-test.js to increase code coverage

* Repair new Error and run /integration tests

* Added more unhappy line integration tests

* Restore sidecar-enabled and keychain-admin_secret

* Ja and some more still

* added final unhappy lines , code coverage 100% for read-model.test.js

* improvement of the coverage for ilp

* Integration tests for Fulfil Commit Success

* improvement of the coverage for transferState

* Added unhappy line integration test (get All method) on participant/index.test.js

* Final chnages code coverage 100% on integration tests for participant/index.test.js

* remove unnecessary ilp

* ilp cleaned and tested

* all test coverage 100%

* added license info

* removed some commented code and added license to the transfer-read-model also

* removed some commented code and added license to the transfer-read-model again

* removed commented out code and fixed some merge issues

* merged

* worked on Georgi remarks
  • Loading branch information
vgenev authored Jun 5, 2018
1 parent fbdbe82 commit 39c8a2f
Show file tree
Hide file tree
Showing 34 changed files with 920 additions and 774 deletions.
1 change: 1 addition & 0 deletions src/domain/participant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ module.exports = {
getAll,
getById,
getByName,
participantExists,
update
// verify,
// updatePartyCredentials,
Expand Down
69 changes: 0 additions & 69 deletions src/domain/transfer/models/ilp-model.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
* Miguel de Barros <miguel.debarros@modusbox.com>
* Georgi Georgiev <georgi.georgiev@modusbox.com>e
--------------
******/

'use strict'

const Moment = require('moment')
const Db = require('../../../db')
const TransferState = require('../state')
const extensionModel = require('../../../models/extensions')
const Logger = require('@mojaloop/central-services-shared').Logger

const findExpired = (expiresAt) => {
const expirationDate = (expiresAt || Moment.utc()).toISOString()
return Db.transfer.find({ state: TransferState.PREPARED, 'expirationDate <': expirationDate })
}

const saveTransfer = async (record) => {
Logger.debug('save transfer' + record.toString())
try {
Expand Down Expand Up @@ -113,7 +132,6 @@ const getById = async (id) => {
}

module.exports = {
findExpired,
saveTransfer,
getAll,
updateTransfer,
Expand Down
11 changes: 5 additions & 6 deletions src/domain/transfer/models/transferStateChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

'use strict'

// const Moment = require('moment')
const Db = require('../../../db')
// const TransferState = require('../state')
const Logger = require('@mojaloop/central-services-shared').Logger

const saveTransferStateChange = async (stateChange) => {
Expand All @@ -41,11 +39,12 @@ const saveTransferStateChange = async (stateChange) => {

const getByTransferId = async (id) => {
try {
// let transferStateChanges = await Db.transferStateChange.find({ transferId: id }, { order: 'changedDate desc' })
// return transferStateChanges[0]
return await Db.transferStateChange.query(async (builder) => {
let result = builder.where({'transferStateChange.transferId': id}).select('transferStateChange.*').orderBy('transferStateChangeId', 'desc').first()
if (!result) throw new Error('no such transfer')
let result = builder
.where({'transferStateChange.transferId': id})
.select('transferStateChange.*')
.orderBy('changedDate', 'desc')
.first()
return result
})
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/transfer/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require('lodash')
const ParticipantService = require('../../domain/participant')
const TransferState = require('./state')
const TransfersModel = require('./models/transfers-read-model')
const TransfersModel = require('./models/transfer-read-model')
const ilpModel = require('../../models/ilp')
const extensionModel = require('../../models/extensions')
const transferStateChangeModel = require('./models/transferStateChanges')
Expand Down
2 changes: 1 addition & 1 deletion src/domain/transfer/queries.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const TransfersReadModel = require('./models/transfers-read-model')
const TransfersReadModel = require('./models/transfer-read-model')
// const TransferStateChange = require('./models/transferStateChanges')

const getAll = () => {
Expand Down
90 changes: 38 additions & 52 deletions src/models/ilp.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,49 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
* Miguel de Barros <miguel.debarros@modusbox.com>
--------------
******/
/*
- License
- --------------
- Copyright © 2017 Bill & Melinda Gates Foundation
- The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Contributors
- --------------
- This is the official list of the Mojaloop project contributors for this file.
- Names of the original copyright holders (individuals or organizations)
- should be listed with a '*' in the first column. People who have
- contributed from an organization can be listed under the organization
- that actually holds the copyright for their contributions (see the
- Gates Foundation organization for an example). Those individuals should have
- their names indented and be marked with a '-'. Email address can be added
- optionally within square brackets <email>.
- * Gates Foundation
- - Name Surname <name.surname@gatesfoundation.com>
- * Valentin Genev <valentin.genev@modusbox.com>
- * Rajiv Mothilal <rajiv.mothilal@modusbox.com>
- * Miguel de Barros <miguel.debarros@modusbox.com>
- --------------
- ******/

'use strict'

const Db = require('../db/index')
// const Moment = require('moment')
const Db = require('../db')
const Util = require('../lib/util')
// const Time = require('../lib/time')

exports.saveIlp = async (ilp) => {
exports.saveIlp = async (transfer) => {
try {
return await Db.ilp.insert({
transferId: ilp.transferId,
packet: ilp.packet,
condition: ilp.condition,
fulfilment: ilp.fulfilment
transferId: transfer.transferId,
packet: transfer.packet,
condition: transfer.condition,
fulfilment: transfer.fulfilment
})
} catch (err) {
throw new Error(err.message)
}
}

// exports.getById = async (id) => {
// try {
// return await Db.ilp.findOne({ ilpId: id })
// } catch (err) {
// throw new Error(err.message)
// }
// }

exports.getByTransferId = async (transferId) => {
try {
return await Db.ilp.findOne({ transferId: transferId })
// .innerJoin('transfer', 'transfer.transferId', 'ilp.transferId')
// .where('expirationDate', '>', `${Time.getCurrentUTCTimeInMilliseconds()}`) // or maybe ${Moment.utc().toISOString()}
} catch (err) {
throw new Error(err.message)
}
}

exports.getByIlpId = async (ilpId) => {
try {
return await Db.ilp.findOne({ ilpId: ilpId })
// .innerJoin('transfer', 'transfer.transferId', 'ilp.transferId')
// .where('expirationDate', '>', `${Time.getCurrentUTCTimeInMilliseconds()}`) // or maybe ${Moment.utc().toISOString()}
} catch (err) {
throw new Error(err.message)
}
Expand All @@ -84,3 +62,11 @@ exports.update = async (ilp) => {
throw new Error(err.message)
}
}

exports.destroyByTransferId = async (ilp) => {
try {
return await Db.ilp.destroy({transferId: ilp.transferId})
} catch (err) {
throw new Error(err.message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Test = require('tape')
const Moment = require('moment')
const Db = require(`${src}/db`)
const Participant = require(`${src}/domain/participant`)
const ReadModel = require(`${src}/domain/transfer/models/transfers-read-model`)
const ReadModel = require(`${src}/domain/transfer/models/transfer-read-model`)
const Fixtures = require('../../../../fixtures')
const TransferState = require('../../../../../src/domain/transfer/state')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Uuid = require('uuid4')
const ExecutedTransfersModel = require(`${src}/models/executed-transfers`)
const SettledTransfersModel = require(`${src}/models/settled-transfers`)
const Participant = require(`${src}/domain/participant`)
const TransfersReadModel = require(`${src}/domain/transfer/models/transfers-read-model`)
const TransfersReadModel = require(`${src}/domain/transfer/models/transfer-read-model`)
const ReadModel = require(`${src}/models/settleable-transfers-read-model`)
const Fixtures = require('../../fixtures')
const TransferState = require(`${src}/domain/transfer/state`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Moment = require('moment')
const Uuid = require('uuid4')
const Db = require(`${src}/db`)
const UrlParser = require(`${src}/lib/urlparser`)
const TransfersReadModel = require(`${src}/domain/transfer/models/transfers-read-model`)
const TransfersReadModel = require(`${src}/domain/transfer/models/transfer-read-model`)
const TransferState = require(`${src}/domain/transfer/state`)

Test('transfer model', modelTest => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/domain/transfer/projection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const UrlParser = require('../../../../src/lib/urlparser')
const ParticipantService = require('../../../../src/domain/participant')
const TransferState = require('../../../../src/domain/transfer/state')
const TransferRejectionType = require('../../../../src/domain/transfer/rejection-type')
const TransfersReadModel = require('../../../../src/domain/transfer/models/transfers-read-model')
const TransfersReadModel = require('../../../../src/domain/transfer/models/transfer-read-model')
const TransfersProjection = require('../../../../src/domain/transfer/projection')

const hostname = 'http://some-host'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/domain/transfer/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Test = require('tapes')(require('tape'))
const Sinon = require('sinon')
const P = require('bluebird')
const Uuid = require('uuid4')
const TransferReadModel = require('../../../../src/domain/transfer/models/transfers-read-model')
const TransferReadModel = require('../../../../src/domain/transfer/models/transfer-read-model')
const TransferQueries = require('../../../../src/domain/transfer/queries')

Test('Transfer Queries tests', queriesTest => {
Expand Down
9 changes: 2 additions & 7 deletions testPI2/integration/domain/transfer/ilp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@
--------------
******/

/*
'use strict'

const Test = require('tape')
const Sinon = require('sinon')
const Db = require('../../../../src/db/index')
const Logger = require('@mojaloop/central-services-shared').Logger
const Config = require('../../../../src/lib/config')
// const Model = require('../../../../src/domain/transfer/models/ilp-model')
const Service = require('../../../../src/domain/transfer/ilp')
// const TransferModel = require('../../../../src/domain/transfer/index')
const Service = require('../../../../src/models/ilp')
const HelperModule = require('../../helpers/index')

Test('Ilp service tests', async (ilpTest) => {
Expand Down Expand Up @@ -101,7 +98,6 @@ Test('Ilp service tests', async (ilpTest) => {
assert.end()
}
})
// assert.end()
} catch (err) {
Logger.error(`create all ilp objects failed with error - ${err}`)
assert.fail(`Create all ilp objects failed - ${err}`)
Expand Down Expand Up @@ -187,7 +183,7 @@ Test('Ilp service tests', async (ilpTest) => {
await ilpTest.test('update', async (assert) => {
try {
for (let ilp of ilpMap.values()) {
let result = await Service.update(ilp.transferId, {packet: 'new test packet'})
let result = await Service.update({ ilpId: ilp.ilpId, packet: 'new test packet' })
let ilpDb = await Service.getByTransferId(ilp.transferId)
assert.equal(result, 1, ' ilp is updated')
assert.equal(ilp.ilpId, ilpDb.ilpId, ' ids match')
Expand Down Expand Up @@ -221,4 +217,3 @@ Test('Ilp service tests', async (ilpTest) => {
}
})
})
*/
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ Test('Extension model test', async (extensionTest) => {
assert.end()
}
})
// assert.end()
} catch (err) {
Logger.error(`create all extension objects failed with error - ${err}`)
assert.fail(`Create all extension objects failed - ${err}`)
Expand Down
Loading

0 comments on commit 39c8a2f

Please sign in to comment.