Skip to content

Commit

Permalink
Bugfix/fix participant lookup to use currency (#228)
Browse files Browse the repository at this point in the history
* updated to newly released version of event-sdk

* updated dependencies and version

* fix for accept header and content-type header versions being hardcoded

* updated participant lookup to validate against the participant and participant currency table to validate that the participant is active as well as their currency account
  • Loading branch information
rmothilal authored Jul 2, 2020
1 parent c4945b0 commit 63b4a36
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 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": "10.5.2",
"version": "10.5.3",
"author": "ModusBox",
"contributors": [
"James Bush <james.bush@modusbox.com>",
Expand Down
19 changes: 12 additions & 7 deletions src/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,20 @@ class Database {
*
* @returns {promise} - id of the participant
*/
async getParticipant (participantName, participantType) {
async getParticipant (participantName, participantType, currencyId, ledgerAccountTypeId) {
try {
const rows = await this.queryBuilder('participant')
.where({
name: participantName,
isActive: 1
})
.select()

.where({ 'participant.name': participantName })
.andWhere({ 'pc.currencyId': currencyId })
.andWhere({ 'pc.ledgerAccountTypeId': ledgerAccountTypeId })
.andWhere({ 'pc.isActive': true })
.andWhere({ 'participant.isActive': true })
.innerJoin('participantCurrency AS pc', 'pc.participantId', 'participant.participantId')
.select(
'participant.*',
'pc.participantCurrencyId',
'pc.currencyId'
)
if ((!rows) || rows.length < 1) {
// active participant does not exist, this is an error
if (participantType && participantType === LOCAL_ENUM.PAYEE_DFSP) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class QuotesModel {
throw ErrorHandler.CreateInternalServerFSPIOPError('Missing quoteRequest', null, fspiopSource)
}

await this.db.getParticipant(fspiopSource, LOCAL_ENUM.PAYER_DFSP)
await this.db.getParticipant(fspiopDestination, LOCAL_ENUM.PAYEE_DFSP)
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)
}

/**
Expand Down
27 changes: 18 additions & 9 deletions test/unit/data/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jest.mock('knex')

const Knex = require('knex')
const crypto = require('crypto')
const ENUM = require('@mojaloop/central-services-shared').Enum

const Database = require('../../../src/data/database')
const Config = require('../../../src/lib/config')
Expand Down Expand Up @@ -786,34 +787,38 @@ describe('/database', () => {
// Arrange
const participantName = 'dfsp1'
const participantType = LibEnum.PAYEE_DFSP
const currency = 'USD'
const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION
const mockList = mockKnexBuilder(
mockKnex,
[{ participantId: 123 }],
['where', 'select']
['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select']
)

// Act
const result = await database.getParticipant(participantName, participantType)
const result = await database.getParticipant(participantName, participantType, currency, ledgerAccountType)

// Assert
expect(result).toBe(123)
expect(mockList[0]).toHaveBeenCalledWith('participant')
expect(mockList[1]).toHaveBeenCalledWith({ name: participantName, isActive: 1 })
expect(mockList[1]).toHaveBeenCalledWith({ 'participant.name': participantName })
expect(mockList[2]).toHaveBeenCalledTimes(1)
})

it('handles an undefined response with a participantType of PAYEE_DFSP', async () => {
// Arrange
const participantName = 'dfsp1'
const participantType = LibEnum.PAYEE_DFSP
const currency = 'USD'
const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION
mockKnexBuilder(
mockKnex,
undefined,
['where', 'select']
['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select']
)

// Act
const action = async () => database.getParticipant(participantName, participantType)
const action = async () => database.getParticipant(participantName, participantType, currency, ledgerAccountType)

// Assert
await expect(action()).rejects.toThrowError('Unsupported participant')
Expand All @@ -823,14 +828,16 @@ describe('/database', () => {
// Arrange
const participantName = 'dfsp1'
const participantType = LibEnum.PAYER_DFSP
const currency = 'USD'
const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION
mockKnexBuilder(
mockKnex,
undefined,
['where', 'select']
['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select']
)

// Act
const action = async () => database.getParticipant(participantName, participantType)
const action = async () => database.getParticipant(participantName, participantType, currency, ledgerAccountType)

// Assert
await expect(action()).rejects.toThrowError('Unsupported participant')
Expand All @@ -839,14 +846,16 @@ describe('/database', () => {
it('handles an empty response with no participantType', async () => {
// Arrange
const participantName = 'dfsp1'
const currency = 'USD'
const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION
mockKnexBuilder(
mockKnex,
[],
['where', 'select']
['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select']
)

// Act
const action = async () => database.getParticipant(participantName)
const action = async () => database.getParticipant(participantName, undefined, currency, ledgerAccountType)

// Assert
await expect(action()).rejects.toThrowError('Unsupported participant')
Expand Down

0 comments on commit 63b4a36

Please sign in to comment.