Skip to content

Commit

Permalink
Merge pull request #784 from davesag/feature/775/includeTotals-in-get…
Browse files Browse the repository at this point in the history
…Transactions

#775 add includeTotals param to getTransactions
  • Loading branch information
davesag authored Jun 4, 2024
2 parents c83f8bb + d36a406 commit b530a6e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 25 deletions.
10 changes: 7 additions & 3 deletions src/api/private/getTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const { defaultParams } = require('../../defaults')
const { validateFields } = require('../../validation')
const isPositiveNumber = require('../../validation/isPositiveNumber')
const isTime = require('../../validation/isTime')
const isOneOf = require('../../validation/isOneOf')

const validation = {
accountGuid: ['isRequired', 'isGuid'],
pageIndex: ['isPositiveNumber'],
pageSize: [isPositiveNumber(5000)]
pageSize: [isPositiveNumber(5000)],
includeTotals: [isOneOf(['true', 'false'])]
}

// https://www.independentreserve.com/products/api#GetTransactions
Expand All @@ -21,15 +23,17 @@ const getTransactions = (apiKey, apiSecret) => {
toTimestampUtc,
txTypes,
pageIndex = defaultParams.pageIndex,
pageSize = defaultParams.pageSize
pageSize = defaultParams.pageSize,
includeTotals = 'true'
}) => {
const payload = {
accountGuid,
fromTimestampUtc,
toTimestampUtc,
txTypes,
pageIndex,
pageSize
pageSize,
includeTotals
}
// eslint-disable-next-line fp/no-unused-expression
validateFields(payload, {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/fixKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const fixKeys = input =>
? Array.isArray(input)
? input.map(fixKeys)
: typeof input === 'object'
? Object.keys(input).reduce(
(acc, elem) => ({ ...acc, [downcase(elem)]: fixKeys(input[elem]) }),
{}
)
: input
? Object.keys(input).reduce(
(acc, elem) => ({ ...acc, [downcase(elem)]: fixKeys(input[elem]) }),
{}
)
: input
: input

module.exports = fixKeys
4 changes: 2 additions & 2 deletions src/utils/payloadBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const payloadBuilder =
elem === 'signature'
? acc
: Array.isArray(data[elem])
? [...acc, `${elem}=${data[elem].join(',')}`]
: [...acc, `${elem}=${data[elem]}`],
? [...acc, `${elem}=${data[elem].join(',')}`]
: [...acc, `${elem}=${data[elem]}`],
[url]
)
.join(',')
Expand Down
4 changes: 2 additions & 2 deletions src/validation/isArrayOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const isArrayOf =
(allowed.length === 0 || (allowed.length !== 0 && value.every(val => allowed.includes(val)))))
? null
: allowed.length === 0
? 'Expected an array'
: `Expected an array containing ${allowed.join(',')}`
? 'Expected an array'
: `Expected an array containing ${allowed.join(',')}`

module.exports = isArrayOf
4 changes: 2 additions & 2 deletions src/validation/isPositiveNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const isPositiveNumber = max => value =>
(typeof value === 'number' && (isNaN(value) || (value > 0 && (!max || (max && !(value > max))))))
? null
: max
? `Expected a positive number no greater than ${max}`
: 'Expected a positive number'
? `Expected a positive number no greater than ${max}`
: 'Expected a positive number'

module.exports = isPositiveNumber
8 changes: 4 additions & 4 deletions src/validation/isRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const checkRequired = value =>
typeof value === 'number'
? !isNaN(value)
: Array.isArray(value) || typeof value === 'string'
? value.length !== 0
: value === undefined || value === null
? false
: typeof value === 'object' && Object.keys(value).length !== 0
? value.length !== 0
: value === undefined || value === null
? false
: typeof value === 'object' && Object.keys(value).length !== 0

const isRequired = value => (checkRequired(value) ? null : 'Field is required')

Expand Down
4 changes: 2 additions & 2 deletions src/validation/isString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const isString = max => value =>
!value || (typeof value === 'string' && (!max || (max && !(value.length > max))))
? null
: max
? `Expected a string no longer than ${max} characters`
: 'Expected a string'
? `Expected a string no longer than ${max} characters`
: 'Expected a string'

module.exports = isString
4 changes: 2 additions & 2 deletions test/helpers/privateHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const doTest = ({ handler, params, useDefaults, validation }) => {
}
: params
: useDefaults
? defaultParams
: undefined
? defaultParams
: undefined

let result

Expand Down
18 changes: 15 additions & 3 deletions test/unit/api/private/getTransactions.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const doTest = require('../../../helpers/privateHandlerTest')
const isPositiveNumber = require('../../../../src/validation/isPositiveNumber')
const isTime = require('../../../../src/validation/isTime')
const isOneOf = require('../../../../src/validation/isOneOf')

const fromTimestampUtc = '2014-08-01T08:00:00Z'
const toTimestampUtc = '2016-08-01T08:00:00Z'

const config = {
const config1 = {
handler: 'getTransactions',
params: {
accountGuid: 'dd015a29-8f73-4469-a5fa-ea91544dfcda',
Expand All @@ -19,8 +20,19 @@ const config = {
fromTimestampUtc: ['isRequired', isTime({ before: toTimestampUtc })],
toTimestampUtc: ['isRequired', isTime({ after: fromTimestampUtc })],
pageIndex: ['isPositiveNumber'],
pageSize: [isPositiveNumber(5000)]
pageSize: [isPositiveNumber(5000)],
includeTotals: [isOneOf(['true', 'false'])]
}
}

doTest(config)
doTest(config1)

const config2 = {
...config1,
params: {
...config1.params,
includeTotals: 'false'
}
}

doTest(config2)

0 comments on commit b530a6e

Please sign in to comment.