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

Fixed the arguments passed to createQuoteExtensions. #213

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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",
"version": "10.2.1",
"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
3 changes: 1 addition & 2 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const fs = require('fs')
class Config {
getFileContent (path) {
if (!fs.existsSync(path)) {
console.log(`File ${path} doesn't exist, can't enable JWS signing`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this line? I asked for this to be added so we do not depend on the consumer of this class to log this error condition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason is because I thought it is redundant since the error bellow logs the same thing, but also the reason that I noticed it is because console.log breaks linting rules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bushjames I can revert that if you want and suppress the eslint error for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, as a general rule I prefer to write a log entry before throwing an exception as a mitigation against the exception error message being obscured by the catcher. there is no logger in context here so console is only option.

throw new Error('File doesn\'t exist')
throw new Error(`File ${path} doesn't exist, can't enable JWS signing`)
}
return fs.readFileSync(path)
}
Expand Down
5 changes: 3 additions & 2 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,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 @@ -538,7 +538,8 @@ 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
2 changes: 1 addition & 1 deletion test/unit/lib/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Config', () => {
expect(result).toBeUndefined()
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty('message', 'File doesn\'t exist')
expect(error).toHaveProperty('message', 'File /fake/path doesn\'t exist, can\'t enable JWS signing')
}
})
})
Loading