Skip to content

Commit

Permalink
fixed the bug with createQuoteExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashi committed May 20, 2020
1 parent de7996b commit 464b4da
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 32 deletions.
204 changes: 181 additions & 23 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions 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.2.0-m-snapshot",
"version": "10.2.1-m-snapshot",
"author": "ModusBox",
"contributors": [
"James Bush <james.bush@modusbox.com>",
Expand Down Expand Up @@ -60,9 +60,9 @@
"dependencies": {
"@hapi/good": "9.0.0",
"@hapi/hapi": "18.4.1",
"@mojaloop/central-services-error-handling": "10.2.0",
"@mojaloop/central-services-error-handling": "10.2.1",
"@mojaloop/central-services-logger": "9.5.1",
"@mojaloop/central-services-shared": "10.1.2",
"@mojaloop/central-services-shared": "10.2.0",
"@mojaloop/event-sdk": "9.5.2",
"@mojaloop/ml-number": "8.2.0",
"@mojaloop/sdk-standard-components": "10.2.3",
Expand Down
3 changes: 2 additions & 1 deletion src/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,11 +981,12 @@ class Database {
* @returns {object}
* @param {Array[{object}]} extensions - array of extension objects with quoteId, key and value properties
*/
async createQuoteExtensions (txn, extensions, quoteId, quoteResponseId = undefined) {
async createQuoteExtensions (txn, extensions, quoteId, transactionId, quoteResponseId = undefined) {
try {
const newExtensions = extensions.map(({ key, value }) => ({
quoteId,
quoteResponseId,
transactionId,
key,
value
}))
Expand Down
4 changes: 2 additions & 2 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class QuotesModel {
if (quoteRequest.extensionList &&
Array.isArray(quoteRequest.extensionList.extension)) {
refs.extensions = await this.db.createQuoteExtensions(
txn, quoteRequest.extensionList.extension, quoteRequest.quoteId)
txn, quoteRequest.extensionList.extension, quoteRequest.quoteId, quoteRequest.transactionId)
}

// did we get a geoCode for the initiator?
Expand Down Expand Up @@ -569,7 +569,7 @@ class QuotesModel {
if (quoteUpdateRequest.extensionList &&
Array.isArray(quoteUpdateRequest.extensionList.extension)) {
refs.extensions = await this.db.createQuoteExtensions(
txn, quoteUpdateRequest.extensionList.extension, quoteId, refs.quoteResponseId)
txn, quoteUpdateRequest.extensionList.extension, quoteId, quoteUpdateRequest.transactionId, refs.quoteResponseId)
}

// todo: create any additional quoteParties e.g. for fees, comission etc...
Expand Down
5 changes: 3 additions & 2 deletions test/unit/data/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2231,19 +2231,20 @@ describe('/database', () => {
value: 'value2'
}]
const quoteId = '123'
const transactionId = '789'
const quoteResponseId = 456

const mockList = mockKnexBuilder(mockKnex, ['12345'], ['transacting', 'insert'])

// Act
const result = await database.createQuoteExtensions(txn, extensions, quoteId, quoteResponseId)
const result = await database.createQuoteExtensions(txn, extensions, quoteId, transactionId, quoteResponseId)

// Assert
expect(result).toStrictEqual(['12345'])
expect(mockList[0]).toHaveBeenCalledWith('quoteExtension')
expect(mockList[1]).toHaveBeenCalledWith(txn)
expect(mockList[2]).toHaveBeenCalledWith(extensions.map(({ key, value }) => ({
key, value, quoteId, quoteResponseId
key, value, quoteId, transactionId, quoteResponseId
})))
expect(mockList[2]).toHaveBeenCalledTimes(1)
})
Expand Down
4 changes: 3 additions & 1 deletion test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,8 @@ describe('QuotesModel', () => {
mockData.quoteRequest.amount.currency]
const mockCreateQuoteExtensionsArgs = [mockTransaction,
mockData.quoteRequest.extensionList.extension,
mockData.quoteRequest.quoteId
mockData.quoteRequest.quoteId,
mockData.quoteRequest.transactionId
]
const mockCreateGeoCodeArgs = [mockTransaction, {
quotePartyId: mockData.quoteRequest.payer.partyIdInfo.fspId,
Expand Down Expand Up @@ -1461,6 +1462,7 @@ describe('QuotesModel', () => {
mockTransaction,
mockData.quoteUpdate.extensionList.extension,
mockData.quoteId,
mockData.transactionId,
mockQuoteResponseId
)

Expand Down

0 comments on commit 464b4da

Please sign in to comment.