@mojaloop/central-services-shared 17.6.3 → 17.6.4-snapshot.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/util/kafka/index.js
CHANGED
|
@@ -285,7 +285,7 @@ const commitMessageSync = async (kafkaConsumer, kafkaTopic, message) => {
|
|
|
285
285
|
|
|
286
286
|
const proceed = async (defaultKafkaConfig, params, opts) => {
|
|
287
287
|
const { message, kafkaTopic, consumer, decodedPayload, span, producer } = params
|
|
288
|
-
const { consumerCommit, fspiopError, eventDetail, fromSwitch, toDestination } = opts
|
|
288
|
+
const { consumerCommit, fspiopError, eventDetail, fromSwitch, toDestination, messageKey } = opts
|
|
289
289
|
let metadataState
|
|
290
290
|
|
|
291
291
|
if (consumerCommit) {
|
|
@@ -305,15 +305,12 @@ const proceed = async (defaultKafkaConfig, params, opts) => {
|
|
|
305
305
|
message.value.from = Enum.Http.Headers.FSPIOP.SWITCH.value
|
|
306
306
|
if (message.value.content.headers) message.value.content.headers[Enum.Http.Headers.FSPIOP.DESTINATION] = message.value.to
|
|
307
307
|
}
|
|
308
|
-
let key
|
|
309
308
|
if (typeof toDestination === 'string') {
|
|
310
309
|
message.value.to = toDestination
|
|
311
310
|
if (message.value.content.headers) message.value.content.headers[Enum.Http.Headers.FSPIOP.DESTINATION] = toDestination
|
|
312
|
-
} else if (toDestination === true) {
|
|
313
|
-
key = message.value.content.headers && message.value.content.headers[Enum.Http.Headers.FSPIOP.DESTINATION]
|
|
314
311
|
}
|
|
315
312
|
if (eventDetail && producer) {
|
|
316
|
-
await produceGeneralMessage(defaultKafkaConfig, producer, eventDetail.functionality, eventDetail.action, message.value, metadataState,
|
|
313
|
+
await produceGeneralMessage(defaultKafkaConfig, producer, eventDetail.functionality, eventDetail.action, message.value, metadataState, messageKey?.toString(), span)
|
|
317
314
|
}
|
|
318
315
|
return true
|
|
319
316
|
}
|
|
@@ -442,39 +442,56 @@ Test('Utility Test', utilityTest => {
|
|
|
442
442
|
})
|
|
443
443
|
|
|
444
444
|
utilityTest.test('proceed should', async proceedTest => {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
445
|
+
let proceedSandbox
|
|
446
|
+
let commitMessageSyncStub
|
|
447
|
+
let produceGeneralMessageStub
|
|
448
|
+
let params
|
|
449
|
+
let message
|
|
450
|
+
const transferId = Uuid()
|
|
448
451
|
const from = 'from'
|
|
449
452
|
const extList = []
|
|
450
|
-
const message = {
|
|
451
|
-
value: {
|
|
452
|
-
content: {
|
|
453
|
-
payload: {
|
|
454
|
-
extensionList: extList
|
|
455
|
-
},
|
|
456
|
-
headers: {
|
|
457
|
-
'fspiop-destination': 'dfsp'
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
from
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
const transferId = Uuid()
|
|
464
453
|
const kafkaTopic = 'kafkaTopic'
|
|
465
454
|
const consumer = 'consumer'
|
|
466
455
|
const producer = 'producer'
|
|
467
|
-
const
|
|
456
|
+
const successState = Enum.Events.EventStatus.SUCCESS
|
|
468
457
|
const eventDetail = { functionality: 'functionality', action: 'action' }
|
|
469
458
|
const UtilityProxy = rewire(`${src}/util/kafka/index`)
|
|
470
|
-
|
|
471
|
-
|
|
459
|
+
|
|
460
|
+
proceedTest.beforeEach(test => {
|
|
461
|
+
// `proceed` mutates the message so reset it after every test
|
|
462
|
+
message = {
|
|
463
|
+
value: {
|
|
464
|
+
content: {
|
|
465
|
+
payload: {
|
|
466
|
+
extensionList: extList
|
|
467
|
+
},
|
|
468
|
+
headers: {
|
|
469
|
+
'fspiop-destination': 'dfsp'
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
from
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
params = { message, transferId, kafkaTopic, consumer, decodedPayload: message.value.content.payload, producer }
|
|
477
|
+
proceedSandbox = Sinon.createSandbox()
|
|
478
|
+
commitMessageSyncStub = sandbox.stub().returns(Promise.resolve())
|
|
479
|
+
produceGeneralMessageStub = sandbox.stub().returns(Promise.resolve())
|
|
480
|
+
UtilityProxy.__set__('commitMessageSync', commitMessageSyncStub)
|
|
481
|
+
UtilityProxy.__set__('produceGeneralMessage', produceGeneralMessageStub)
|
|
482
|
+
test.end()
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
proceedTest.afterEach(test => {
|
|
486
|
+
proceedSandbox.restore()
|
|
487
|
+
test.end()
|
|
488
|
+
})
|
|
472
489
|
|
|
473
490
|
proceedTest.test('commitMessageSync when consumerCommit and produce toDestination', async test => {
|
|
474
491
|
const opts = { consumerCommit: true, eventDetail, toDestination: true }
|
|
475
492
|
try {
|
|
476
493
|
const result = await UtilityProxy.proceed(Config.KAFKA_CONFIG, params, opts)
|
|
477
|
-
test.ok(commitMessageSyncStub.calledOnce, 'commitMessageSyncStub called
|
|
494
|
+
test.ok(commitMessageSyncStub.calledOnce, 'commitMessageSyncStub not called')
|
|
478
495
|
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).calledOnce, 'produceGeneralMessageStub called once')
|
|
479
496
|
test.equal(result, true, 'result returned')
|
|
480
497
|
} catch (err) {
|
|
@@ -488,8 +505,22 @@ Test('Utility Test', utilityTest => {
|
|
|
488
505
|
const opts = { consumerCommit: true, eventDetail, toDestination: 'dfsp1' }
|
|
489
506
|
try {
|
|
490
507
|
const result = await UtilityProxy.proceed(Config.KAFKA_CONFIG, params, opts)
|
|
491
|
-
test.ok(commitMessageSyncStub.
|
|
492
|
-
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).
|
|
508
|
+
test.ok(commitMessageSyncStub.calledOnce, 'commitMessageSyncStub not called')
|
|
509
|
+
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).calledOnce, 'produceGeneralMessageStub not called')
|
|
510
|
+
test.equal(result, true, 'result returned')
|
|
511
|
+
} catch (err) {
|
|
512
|
+
test.fail(err.message)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
test.end()
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
proceedTest.test('produce message when messageKey is specified', async test => {
|
|
519
|
+
const opts = { consumerCommit: true, eventDetail, messageKey: 101 }
|
|
520
|
+
try {
|
|
521
|
+
const result = await UtilityProxy.proceed(Config.KAFKA_CONFIG, params, opts)
|
|
522
|
+
test.ok(commitMessageSyncStub.calledOnce, 'commitMessageSyncStub not called')
|
|
523
|
+
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState, '101').calledOnce, 'produceGeneralMessageStub not called')
|
|
493
524
|
test.equal(result, true, 'result returned')
|
|
494
525
|
} catch (err) {
|
|
495
526
|
test.fail(err.message)
|
|
@@ -502,7 +533,7 @@ Test('Utility Test', utilityTest => {
|
|
|
502
533
|
const opts = { fromSwitch: true, eventDetail }
|
|
503
534
|
try {
|
|
504
535
|
const result = await UtilityProxy.proceed(Config.KAFKA_CONFIG, params, opts)
|
|
505
|
-
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).
|
|
536
|
+
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).calledOnce, 'produceGeneralMessageStub not called')
|
|
506
537
|
test.equal(message.value.to, from, 'message destination set to sender')
|
|
507
538
|
test.equal(message.value.from, Enum.Http.Headers.FSPIOP.SWITCH.value, 'from set to switch')
|
|
508
539
|
test.equal(result, true, 'result returned')
|
|
@@ -519,9 +550,9 @@ Test('Utility Test', utilityTest => {
|
|
|
519
550
|
const localParams = clone(params)
|
|
520
551
|
delete localParams.message.value.content.headers
|
|
521
552
|
const result = await UtilityProxy.proceed(Config.KAFKA_CONFIG, localParams, opts)
|
|
522
|
-
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, message.value, successState).
|
|
523
|
-
test.equal(message.value.to, from, 'message destination set to sender')
|
|
524
|
-
test.equal(message.value.from, Enum.Http.Headers.FSPIOP.SWITCH.value, 'from set to switch')
|
|
553
|
+
test.ok(produceGeneralMessageStub.withArgs(Config.KAFKA_CONFIG, producer, eventDetail.functionality, eventDetail.action, localParams.message.value, successState).calledOnce, 'produceGeneralMessageStub not called')
|
|
554
|
+
test.equal(localParams.message.value.to, from, 'message destination set to sender')
|
|
555
|
+
test.equal(localParams.message.value.from, Enum.Http.Headers.FSPIOP.SWITCH.value, 'from set to switch')
|
|
525
556
|
test.equal(result, true, 'result returned')
|
|
526
557
|
} catch (err) {
|
|
527
558
|
test.fail(err.message)
|