Skip to content

Commit

Permalink
validate dfsps in payload for simple routing mode (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi165 authored Nov 19, 2020
1 parent d37de6b commit 0ffc8ed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "quoting-service",
"description": "Quoting Service hosted by a scheme",
"license": "Apache-2.0",
"version": "11.1.5",
"version": "11.2.0",
"author": "ModusBox",
"contributors": [
"James Bush <james.bush@modusbox.com>",
Expand Down
7 changes: 7 additions & 0 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class QuotesModel {
* @returns {promise} - promise will reject if request is not valid
*/
async validateQuoteRequest (fspiopSource, fspiopDestination, quoteRequest) {
const envConfig = new Config()
// note that the framework should validate the form of the request
// here we can do some hard-coded rule validations to ensure requests
// do not lead to unsupported scenarios or use-cases.
Expand All @@ -165,6 +166,12 @@ class QuotesModel {

await this.db.getParticipant(fspiopSource, LOCAL_ENUM.PAYER_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION)
await this.db.getParticipant(fspiopDestination, LOCAL_ENUM.PAYEE_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION)

// Following is the validation to make sure valid fsp's are used in the payload for simple routing mode
if (envConfig.simpleRoutingMode) {
await this.db.getParticipant(quoteRequest.payer.partyIdInfo.fspId, LOCAL_ENUM.PAYER_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION)
await this.db.getParticipant(quoteRequest.payee.partyIdInfo.fspId, LOCAL_ENUM.PAYEE_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION)
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ describe('QuotesModel', () => {
await quotesModel.validateQuoteRequest(fspiopSource, fspiopDestination, mockData.quoteRequest)

expect(quotesModel.db).toBeTruthy() // Constructor should have been called
expect(quotesModel.db.getParticipant).toHaveBeenCalledTimes(2)
if (mockConfig.simpleRoutingMode) {
expect(quotesModel.db.getParticipant).toHaveBeenCalledTimes(4)
} else {
expect(quotesModel.db.getParticipant).toHaveBeenCalledTimes(2)
}
expect(quotesModel.db.getParticipant.mock.calls[0][0]).toBe(fspiopSource)
expect(quotesModel.db.getParticipant.mock.calls[1][0]).toBe(fspiopDestination)
})
Expand Down

0 comments on commit 0ffc8ed

Please sign in to comment.