Skip to content
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
43 changes: 12 additions & 31 deletions 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
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/ml-api-adapter",
"version": "7.1.4",
"version": "7.2.0",
"description": "Convert from ML API to/from internal Central Services messaging format",
"license": "Apache-2.0",
"private": true,
Expand Down
5 changes: 5 additions & 0 deletions src/domain/transfer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const GET = 'get'
*
* @param {object} headers - the http header from the request
* @param {object} message - the transfer prepare message
* @param {object} dataUri - base64 encoded string
*
* @returns {boolean} Returns true on successful publishing of message to kafka, throws error on falires
*/
Expand All @@ -59,6 +60,10 @@ const prepare = async (headers, message, dataUri) => {
from: message.payerFsp,
type: 'application/json',
content: {
// TODO: will message.transferId always exist?
Copy link
Contributor

Choose a reason for hiding this comment

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

On a prepare you should always have a message.transferId as it is required by Joi validation

uriParams: {
id: message.transferId
},
headers: headers,
payload: dataUri
},
Expand Down
2 changes: 1 addition & 1 deletion src/domain/transfer/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const transformHeaders = (headers, config) => {
// Check to see if we find a regex match the source header containing the switch name.
// If so we remove the signature added by default.
delete normalizedHeaders[ENUM.headers.FSPIOP.SIGNATURE]
// Aslo remove FSPIOP-URI and make FSPIOP-HTTP-Method ALL-CAPS #737
// Also remove FSPIOP-URI and make FSPIOP-HTTP-Method ALL-CAPS #737
delete normalizedHeaders[ENUM.headers.FSPIOP.URI]
}

Expand Down
126 changes: 126 additions & 0 deletions test/unit/domain/transfer/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,131 @@ Test('Transfer Service tests', serviceTest => {
})
transferErrorTest.end()
})

serviceTest.test('message format tests', formatTest => {
/* Test Data */
const transferId = 'b51ec534-ee48-4575-b6a9-ead2955b8069'
const message = {
transferId,
payeeFsp: '1234',
payerFsp: '5678',
amount: {
currency: 'USD',
amount: 123.45
},
ilpPacket: 'AYIBgQAAAAAAAASwNGxldmVsb25lLmRmc3AxLm1lci45T2RTOF81MDdqUUZERmZlakgyOVc4bXFmNEpLMHlGTFGCAUBQU0svMS4wCk5vbmNlOiB1SXlweUYzY3pYSXBFdzVVc05TYWh3CkVuY3J5cHRpb246IG5vbmUKUGF5bWVudC1JZDogMTMyMzZhM2ItOGZhOC00MTYzLTg0NDctNGMzZWQzZGE5OGE3CgpDb250ZW50LUxlbmd0aDogMTM1CkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbgpTZW5kZXItSWRlbnRpZmllcjogOTI4MDYzOTEKCiJ7XCJmZWVcIjowLFwidHJhbnNmZXJDb2RlXCI6XCJpbnZvaWNlXCIsXCJkZWJpdE5hbWVcIjpcImFsaWNlIGNvb3BlclwiLFwiY3JlZGl0TmFtZVwiOlwibWVyIGNoYW50XCIsXCJkZWJpdElkZW50aWZpZXJcIjpcIjkyODA2MzkxXCJ9IgA',
condition: 'f5sqb7tBTWPd5Y8BDFdMm9BJR_MNI4isf8p8n4D5pHA',
expiration: '2016-05-24T08:38:08.699-04:00',
extensionList:
{
extension:
[
{
key: 'errorDescription',
value: 'This is a more detailed error description'
},
{
key: 'errorDescription',
value: 'This is a more detailed error description'
}
]
}
}
const headers = {}
const dataUri = ''

formatTest.test('prepare should call `produceMessage` with the correct messageProtocol format', async test => {
// Arrange
let resultMessageProtocol = {}
// stub and unwrap the message sent to `Kafka.Producer.produceMessage`
Kafka.Producer.produceMessage = (messageProtocol, topicConfig, kafkaConfig) => {
resultMessageProtocol = messageProtocol
}

const expectedMessageProtocol = {
to: message.payeeFsp,
from: message.payerFsp,
type: 'application/json',
content: {
uriParams: {
id: message.transferId
},
headers,
payload: dataUri
},
metadata: {
event: {
type: 'prepare',
action: 'prepare',
state: {
status: 'success',
code: 0
}
}
}
}

// Act
await Service.prepare(headers, message, dataUri)

// Delete non-deterministic fields
delete resultMessageProtocol.id
delete resultMessageProtocol.metadata.event.id
delete resultMessageProtocol.metadata.event.createdAt

// Assert
test.deepEqual(resultMessageProtocol, expectedMessageProtocol, 'messageProtocols should match')
test.end()
})

// TODO: I'm not sure this is a valid case
formatTest.test('prepare should not fail if message.transferId is undefined', async test => {
// Arrange
let resultMessageProtocol = {}
delete message.transferId
// stub and unwrap the message sent to `Kafka.Producer.produceMessage`
Kafka.Producer.produceMessage = (messageProtocol, topicConfig, kafkaConfig) => {
resultMessageProtocol = messageProtocol
}

const expectedMessageProtocol = {
to: message.payeeFsp,
from: message.payerFsp,
type: 'application/json',
content: {
uriParams: {
id: undefined
},
headers,
payload: dataUri
},
metadata: {
event: {
type: 'prepare',
action: 'prepare',
state: {
status: 'success',
code: 0
}
}
}
}

// Act
await Service.prepare(headers, message, dataUri)

// Delete non-deterministic fields
delete resultMessageProtocol.id
delete resultMessageProtocol.metadata.event.id
delete resultMessageProtocol.metadata.event.createdAt

// Assert
test.deepEqual(resultMessageProtocol, expectedMessageProtocol, 'messageProtocols should match')
test.end()
})

formatTest.end()
})

serviceTest.end()
})