Skip to content

Commit

Permalink
Disregard 'SEND_TRANSFER_CONFIRMATION_TO_PAYEE' config for 'abort' ac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
oderayi committed Jun 8, 2020
1 parent 439cd22 commit 6aa729c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 5 additions & 11 deletions src/handlers/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,11 @@ const processMessage = async (msg, span) => {
Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`)
await Callback.sendRequest(callbackURLFrom, callbackHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, from, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span, jwsSigner)

// send an extra notification back to the payee (if enabled in config)
if (Config.SEND_TRANSFER_CONFIRMATION_TO_PAYEE) {
jwsSigner = getJWSSigner(from)
Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`)
callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch)
const response = await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span, jwsSigner)
histTimerEnd({ success: true, action })
return response
} else {
Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to payee (${to}) because feature is disabled in config.`)
}
// forward the 'abort' message to the payee
jwsSigner = getJWSSigner(from)
Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`)
callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch)
await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span, jwsSigner)
histTimerEnd({ success: true, action })
return true
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/handlers/notification/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ Test('Notification Service tests', async notificationTest => {
msg.value.metadata.event.action = 'abort'
await NotificationProxy.processMessage(msg)
test.ok(Callback.sendRequest.calledWith(fromUrl, fromHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, msg.value.from, method, JSON.stringify(message)))
test.notok(Callback.sendRequest.calledWith(toUrl, toHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, msg.value.to, method, JSON.stringify(message)))
test.ok(Callback.sendRequest.calledWith(toUrl, toHeaders, msg.value.from, msg.value.to, method, JSON.stringify(message)))

test.end()
})
Expand Down Expand Up @@ -867,7 +867,7 @@ Test('Notification Service tests', async notificationTest => {
const fromHeaders = createCallbackHeaders({ dfspId: msg.value.from, transferId: msg.value.content.payload.transferId, headers: msg.value.content.headers, httpMethod: method, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, true)
const message = { transferId: uuid }

const expected = 200
const expected = true

Callback.sendRequest.withArgs(fromUrl, fromHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, msg.value.from, method, JSON.stringify(message)).returns(Promise.resolve(200))
Callback.sendRequest.withArgs(toUrl, toHeaders, msg.value.from, msg.value.to, method, JSON.stringify(message)).returns(Promise.resolve(200))
Expand Down Expand Up @@ -1421,7 +1421,7 @@ Test('Notification Service tests', async notificationTest => {
const fromHeaders = createCallbackHeaders({ dfspId: msg.value.from, transferId: msg.value.content.payload.transferId, headers: msg.value.content.headers, httpMethod: method, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, true)
const message = { transferId: uuid }

const expected = 200
const expected = true
const logger = Logger
logger.log = logger.info

Expand Down

0 comments on commit 6aa729c

Please sign in to comment.