From ad0814dfb2ed2221e229fa53e45ed28128181221 Mon Sep 17 00:00:00 2001 From: Kevin Leyow Date: Thu, 4 Apr 2024 17:21:31 -0500 Subject: [PATCH 1/2] chore: more coverage --- package-lock.json | 8 +- package.json | 2 +- src/domain/fx/cyril.js | 6 +- src/handlers/transfers/prepare.js | 1 - test/unit/domain/fx/cyril.test.js | 429 +++++++++++++++++++ test/unit/domain/fx/index.test.js | 84 ++++ test/unit/handlers/transfers/prepare.test.js | 31 ++ 7 files changed, 554 insertions(+), 7 deletions(-) create mode 100644 test/unit/domain/fx/cyril.test.js create mode 100644 test/unit/domain/fx/index.test.js diff --git a/package-lock.json b/package-lock.json index 37d21523f..445cae3a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@hapi/catbox-memory": "6.0.1", "@hapi/good": "9.0.1", - "@hapi/hapi": "21.3.7", + "@hapi/hapi": "21.3.8", "@hapi/inert": "7.1.0", "@hapi/joi": "17.1.1", "@hapi/vision": "7.0.3", @@ -948,9 +948,9 @@ "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" }, "node_modules/@hapi/hapi": { - "version": "21.3.7", - "resolved": "https://registry.npmjs.org/@hapi/hapi/-/hapi-21.3.7.tgz", - "integrity": "sha512-33J0nreMfqkhY7wwRAZRy+9J+7J4QOH1JtICMjIUmxfaOYSJL/d8JJCtg57SX60944bhlCeu7isb7qyr2jT2oA==", + "version": "21.3.8", + "resolved": "https://registry.npmjs.org/@hapi/hapi/-/hapi-21.3.8.tgz", + "integrity": "sha512-2YGNQZTnWKAWiexoLxvsSFFpJvFBJKhtRzARNxR6G1dHbDfL1WPQBXF00rmMRJLdo+oi7d+Ntgdno6V+z+js7w==", "dependencies": { "@hapi/accept": "^6.0.1", "@hapi/ammo": "^6.0.1", diff --git a/package.json b/package.json index f8afd99bc..a1661f504 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "dependencies": { "@hapi/catbox-memory": "6.0.1", "@hapi/good": "9.0.1", - "@hapi/hapi": "21.3.7", + "@hapi/hapi": "21.3.8", "@hapi/inert": "7.1.0", "@hapi/joi": "17.1.1", "@hapi/vision": "7.0.3", diff --git a/src/domain/fx/cyril.js b/src/domain/fx/cyril.js index e49fd56fd..d66ff2f72 100644 --- a/src/domain/fx/cyril.js +++ b/src/domain/fx/cyril.js @@ -227,7 +227,11 @@ const processFulfilMessage = async (transferId, payload, transfer) => { } else if (sendingFxpExists) { // If we have a sending FXP, Create obligation between FXP and creditor party to the transfer in currency of FX transfer // Get participantCurrencyId for transfer.payeeParticipantId/transfer.payeeFsp and sendingFxpRecord.targetCurrency - const participantCurrency = await ParticipantFacade.getByNameAndCurrency(transfer.payeeFsp, sendingFxpRecord.targetCurrency, Enum.Accounts.LedgerAccountType.POSITION) + const participantCurrency = await ParticipantFacade.getByNameAndCurrency( + transfer.payeeFsp, + sendingFxpRecord.targetCurrency, + Enum.Accounts.LedgerAccountType.POSITION + ) result.positionChanges.push({ isFxTransferStateChange: false, transferId, diff --git a/src/handlers/transfers/prepare.js b/src/handlers/transfers/prepare.js index 10e397d6b..fd22c35f5 100644 --- a/src/handlers/transfers/prepare.js +++ b/src/handlers/transfers/prepare.js @@ -266,7 +266,6 @@ const prepare = async (error, messages) => { module.exports = { prepare, - checkDuplication, processDuplication, savePreparedRequest, diff --git a/test/unit/domain/fx/cyril.test.js b/test/unit/domain/fx/cyril.test.js new file mode 100644 index 000000000..0090b2d3b --- /dev/null +++ b/test/unit/domain/fx/cyril.test.js @@ -0,0 +1,429 @@ +'use strict' + +const Test = require('tapes')(require('tape')) +const Sinon = require('sinon') +const Cyril = require('../../../../src/domain/fx/cyril') +const Logger = require('@mojaloop/central-services-logger') +const { Enum } = require('@mojaloop/central-services-shared') +const TransferModel = require('../../../../src/models/transfer/transfer') +const ParticipantFacade = require('../../../../src/models/participant/facade') +const { fxTransfer, watchList } = require('../../../../src/models/fxTransfer') + +Test('Cyril', cyrilTest => { + let sandbox + let fxPayload + let payload + cyrilTest.beforeEach(t => { + sandbox = Sinon.createSandbox() + sandbox.stub(Logger, 'isDebugEnabled').value(true) + sandbox.stub(watchList) + sandbox.stub(fxTransfer) + sandbox.stub(TransferModel) + sandbox.stub(ParticipantFacade) + payload = { + transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', + payerFsp: 'dfsp1', + payeeFsp: 'dfsp2', + amount: { + currency: 'USD', + amount: '433.88' + }, + ilpPacket: 'AYIBgQAAAAAAAASwNGxldmVsb25lLmRmc3AxLm1lci45T2RTOF81MDdqUUZERmZlakgyOVc4bXFmNEpLMHlGTFGCAUBQU0svMS4wCk5vbmNlOiB1SXlweUYzY3pYSXBFdzVVc05TYWh3CkVuY3J5cHRpb246IG5vbmUKUGF5bWVudC1JZDogMTMyMzZhM2ItOGZhOC00MTYzLTg0NDctNGMzZWQzZGE5OGE3CgpDb250ZW50LUxlbmd0aDogMTM1CkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbgpTZW5kZXItSWRlbnRpZmllcjogOTI4MDYzOTEKCiJ7XCJmZWVcIjowLFwidHJhbnNmZXJDb2RlXCI6XCJpbnZvaWNlXCIsXCJkZWJpdE5hbWVcIjpcImFsaWNlIGNvb3BlclwiLFwiY3JlZGl0TmFtZVwiOlwibWVyIGNoYW50XCIsXCJkZWJpdElkZW50aWZpZXJcIjpcIjkyODA2MzkxXCJ9IgA', + condition: 'YlK5TZyhflbXaDRPtR5zhCu8FrbgvrQwwmzuH0iQ0AI', + expiration: new Date((new Date()).getTime() + (24 * 60 * 60 * 1000)), // tomorrow + extensionList: { + extension: [ + { + key: 'key1', + value: 'value1' + }, + { + key: 'key2', + value: 'value2' + } + ] + } + } + + fxPayload = { + commitRequestId: '88622a75-5bde-4da4-a6cc-f4cd23b268c4', + determiningTransferId: 'c05c3f31-33b5-4e33-8bfd-7c3a2685fb6c', + condition: 'YlK5TZyhflbXaDRPtR5zhCu8FrbgvrQwwmzuH0iQ0AI', + expiration: new Date((new Date()).getTime() + (24 * 60 * 60 * 1000)), // tomorrow + initiatingFsp: 'fx_dfsp1', + counterPartyFsp: 'fx_dfsp2', + sourceAmount: { + currency: 'USD', + amount: '433.88' + }, + targetAmount: { + currency: 'EUR', + amount: '200.00' + } + } + + t.end() + }) + + cyrilTest.afterEach(t => { + sandbox.restore() + t.end() + }) + + cyrilTest.test('getParticipantAndCurrencyForTransferMessage should', getParticipantAndCurrencyForTransferMessageTest => { + getParticipantAndCurrencyForTransferMessageTest.test('return details about regular transfer', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve([])) + const result = await Cyril.getParticipantAndCurrencyForTransferMessage(payload) + + test.deepEqual(result, { + participantName: 'dfsp1', + currencyId: 'USD', + amount: '433.88' + }) + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + + getParticipantAndCurrencyForTransferMessageTest.test('return details about fxtransfer', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve([ + { + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYER_CONVERSION, + createdDate: new Date() + } + ])) + fxTransfer.getAllDetailsByCommitRequestId.withArgs( + fxPayload.commitRequestId + ).returns(Promise.resolve( + { + targetAmount: fxPayload.targetAmount.amount, + targetCurrency: fxPayload.targetAmount.currency, + counterPartyFspName: 'fx_dfsp2' + } + )) + const result = await Cyril.getParticipantAndCurrencyForTransferMessage(payload) + + test.deepEqual(result, { + participantName: 'fx_dfsp2', + currencyId: 'EUR', + amount: '200.00' + }) + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.ok(fxTransfer.getAllDetailsByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.pass('Error not thrown') + test.end() + } catch (e) { + console.log(e) + test.fail('Error Thrown') + test.end() + } + }) + getParticipantAndCurrencyForTransferMessageTest.end() + }) + + cyrilTest.test('getParticipantAndCurrencyForFxTransferMessage should', getParticipantAndCurrencyForFxTransferMessageTest => { + getParticipantAndCurrencyForFxTransferMessageTest.test('return details about fxtransfer debtor party initited msg', async (test) => { + try { + TransferModel.getById.returns(Promise.resolve(null)) + const result = await Cyril.getParticipantAndCurrencyForFxTransferMessage(fxPayload) + + test.ok(watchList.addToWatchList.calledWith({ + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYER_CONVERSION + })) + test.deepEqual(result, { + participantName: fxPayload.initiatingFsp, + currencyId: fxPayload.sourceAmount.currency, + amount: fxPayload.sourceAmount.amount + }) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + + getParticipantAndCurrencyForFxTransferMessageTest.test('return details about fxtransfer creditor party initited msg', async (test) => { + try { + TransferModel.getById.returns(Promise.resolve({})) + const result = await Cyril.getParticipantAndCurrencyForFxTransferMessage(fxPayload) + + test.ok(watchList.addToWatchList.calledWith({ + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYEE_CONVERSION + })) + test.deepEqual(result, { + participantName: fxPayload.counterPartyFsp, + currencyId: fxPayload.targetAmount.currency, + amount: fxPayload.targetAmount.amount + }) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + getParticipantAndCurrencyForFxTransferMessageTest.end() + }) + + cyrilTest.test('processFxFulfilMessage should', processFxFulfilMessageTest => { + processFxFulfilMessageTest.test('throws error when commitRequestId not in watchlist', async (test) => { + try { + watchList.getItemInWatchListByCommitRequestId.returns(Promise.resolve(null)) + await Cyril.processFxFulfilMessage(fxPayload.commitRequestId) + test.ok(watchList.getItemInWatchListByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.fail('Error not thrown') + test.end() + } catch (e) { + test.pass('Error Thrown') + test.end() + } + }) + + processFxFulfilMessageTest.test('should return fxTransferRecord when commitRequestId is in watchlist', async (test) => { + try { + const fxTransferRecordDetails = { + initiatingFspParticipantCurrencyId: 1, + initiatingFspParticipantId: 1, + initiatingFspName: 'fx_dfsp1', + counterPartyFspSourceParticipantCurrencyId: 1, + counterPartyFspTargetParticipantCurrencyId: 2, + counterPartyFspParticipantId: 2, + counterPartyFspName: 'fx_dfsp2' + } + watchList.getItemInWatchListByCommitRequestId.returns(Promise.resolve({ + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYER_CONVERSION, + createdDate: new Date() + })) + fxTransfer.getAllDetailsByCommitRequestId.returns(Promise.resolve(fxTransferRecordDetails)) + const result = await Cyril.processFxFulfilMessage(fxPayload.commitRequestId) + test.ok(watchList.getItemInWatchListByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.ok(fxTransfer.getAllDetailsByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.deepEqual(result, fxTransferRecordDetails) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + + processFxFulfilMessageTest.end() + }) + + cyrilTest.test('processFulfilMessage should', processFulfilMessageTest => { + processFulfilMessageTest.test('return false if transferId is not in watchlist', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve(null)) + const result = await Cyril.processFulfilMessage(payload.transferId, payload, payload) + + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.deepEqual(result, { + isFx: false, + positionChanges: [], + patchNotifications: [] + }) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + + processFulfilMessageTest.test('process watchlist with only payer conversion found', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve( + [{ + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYER_CONVERSION, + createdDate: new Date() + }] + )) + fxTransfer.getAllDetailsByCommitRequestId.returns(Promise.resolve( + { + initiatingFspParticipantCurrencyId: 1, + targetAmount: fxPayload.targetAmount.amount, + commitRequestId: fxPayload.commitRequestId, + counterPartyFspSourceParticipantCurrencyId: 1, + counterPartyFspTargetParticipantCurrencyId: 2, + sourceAmount: fxPayload.sourceAmount.amount, + targetCurrency: fxPayload.targetAmount.currency + } + )) + ParticipantFacade.getByNameAndCurrency.returns(Promise.resolve({ + participantId: 1, + participantCurrencyId: 1, + participantName: 'fx_dfsp1', + isActive: 1 + })) + const result = await Cyril.processFulfilMessage(payload.transferId, payload, payload) + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.ok(fxTransfer.getAllDetailsByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.ok(ParticipantFacade.getByNameAndCurrency.calledWith( + 'dfsp2', + fxPayload.targetAmount.currency, + Enum.Accounts.LedgerAccountType.POSITION + )) + test.deepEqual(result, { + isFx: true, + positionChanges: [{ + isFxTransferStateChange: true, + commitRequestId: '88622a75-5bde-4da4-a6cc-f4cd23b268c4', + participantCurrencyId: 1, + amount: -433.88 + }, + { + isFxTransferStateChange: false, + transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', + participantCurrencyId: 1, + amount: -200 + } + ], + patchNotifications: [] + }) + test.pass('Error not thrown') + test.end() + } catch (e) { + console.log(e) + test.fail('Error Thrown') + test.end() + } + }) + + processFulfilMessageTest.test('process watchlist with only payee conversion found', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve( + [{ + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYEE_CONVERSION, + createdDate: new Date() + }] + )) + fxTransfer.getAllDetailsByCommitRequestId.returns(Promise.resolve( + { + initiatingFspParticipantCurrencyId: 1, + targetAmount: fxPayload.targetAmount.amount, + commitRequestId: fxPayload.commitRequestId, + counterPartyFspSourceParticipantCurrencyId: 1, + counterPartyFspTargetParticipantCurrencyId: 2, + sourceAmount: fxPayload.sourceAmount.amount, + targetCurrency: fxPayload.targetAmount.currency + } + )) + const result = await Cyril.processFulfilMessage(payload.transferId, payload, payload) + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.ok(fxTransfer.getAllDetailsByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.deepEqual(result, { + isFx: true, + positionChanges: [{ + isFxTransferStateChange: false, + transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', + participantCurrencyId: 1, + amount: -200 + }, + { + isFxTransferStateChange: true, + commitRequestId: '88622a75-5bde-4da4-a6cc-f4cd23b268c4', + participantCurrencyId: 1, + amount: -433.88 + } + ], + patchNotifications: [] + } + ) + test.pass('Error not thrown') + test.end() + } catch (e) { + console.log(e) + test.fail('Error Thrown') + test.end() + } + }) + + processFulfilMessageTest.test('process watchlist with both payer and payee conversion found', async (test) => { + try { + watchList.getItemsInWatchListByDeterminingTransferId.returns(Promise.resolve( + [ + { + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYEE_CONVERSION, + createdDate: new Date() + }, + { + commitRequestId: fxPayload.commitRequestId, + determiningTransferId: fxPayload.determiningTransferId, + fxTransferTypeId: Enum.Fx.FxTransferType.PAYER_CONVERSION, + createdDate: new Date() + } + ] + )) + fxTransfer.getAllDetailsByCommitRequestId.returns(Promise.resolve( + { + initiatingFspParticipantCurrencyId: 1, + targetAmount: fxPayload.targetAmount.amount, + commitRequestId: fxPayload.commitRequestId, + counterPartyFspSourceParticipantCurrencyId: 1, + counterPartyFspTargetParticipantCurrencyId: 2, + sourceAmount: fxPayload.sourceAmount.amount, + targetCurrency: fxPayload.targetAmount.currency + } + )) + const result = await Cyril.processFulfilMessage(payload.transferId, payload, payload) + test.ok(watchList.getItemsInWatchListByDeterminingTransferId.calledWith(payload.transferId)) + test.ok(fxTransfer.getAllDetailsByCommitRequestId.calledWith(fxPayload.commitRequestId)) + test.deepEqual(result, { + isFx: true, + positionChanges: [ + { + isFxTransferStateChange: false, + transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', + participantCurrencyId: 1, + amount: -200 + }, + { + isFxTransferStateChange: true, + commitRequestId: '88622a75-5bde-4da4-a6cc-f4cd23b268c4', + participantCurrencyId: 1, + amount: -433.88 + }, + { + isFxTransferStateChange: true, + commitRequestId: '88622a75-5bde-4da4-a6cc-f4cd23b268c4', + participantCurrencyId: 1, + amount: -433.88 + } + ], + patchNotifications: [] + } + ) + test.pass('Error not thrown') + test.end() + } catch (e) { + console.log(e) + test.fail('Error Thrown') + test.end() + } + }) + processFulfilMessageTest.end() + }) + + cyrilTest.end() +}) diff --git a/test/unit/domain/fx/index.test.js b/test/unit/domain/fx/index.test.js new file mode 100644 index 000000000..78c2f8cb4 --- /dev/null +++ b/test/unit/domain/fx/index.test.js @@ -0,0 +1,84 @@ +'use strict' + +const Test = require('tapes')(require('tape')) +const Sinon = require('sinon') +const Fx = require('../../../../src/domain/fx') +const Logger = require('@mojaloop/central-services-logger') +const { fxTransfer } = require('../../../../src/models/fxTransfer') +const { Enum } = require('@mojaloop/central-services-shared') + +const TransferEventAction = Enum.Events.Event.Action + +Test('Fx', fxIndexTest => { + let sandbox + let payload + fxIndexTest.beforeEach(t => { + sandbox = Sinon.createSandbox() + sandbox.stub(Logger, 'isDebugEnabled').value(true) + sandbox.stub(fxTransfer) + payload = { + transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', + payerFsp: 'dfsp1', + payeeFsp: 'dfsp2', + amount: { + currency: 'USD', + amount: '433.88' + }, + ilpPacket: 'AYIBgQAAAAAAAASwNGxldmVsb25lLmRmc3AxLm1lci45T2RTOF81MDdqUUZERmZlakgyOVc4bXFmNEpLMHlGTFGCAUBQU0svMS4wCk5vbmNlOiB1SXlweUYzY3pYSXBFdzVVc05TYWh3CkVuY3J5cHRpb246IG5vbmUKUGF5bWVudC1JZDogMTMyMzZhM2ItOGZhOC00MTYzLTg0NDctNGMzZWQzZGE5OGE3CgpDb250ZW50LUxlbmd0aDogMTM1CkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbgpTZW5kZXItSWRlbnRpZmllcjogOTI4MDYzOTEKCiJ7XCJmZWVcIjowLFwidHJhbnNmZXJDb2RlXCI6XCJpbnZvaWNlXCIsXCJkZWJpdE5hbWVcIjpcImFsaWNlIGNvb3BlclwiLFwiY3JlZGl0TmFtZVwiOlwibWVyIGNoYW50XCIsXCJkZWJpdElkZW50aWZpZXJcIjpcIjkyODA2MzkxXCJ9IgA', + condition: 'YlK5TZyhflbXaDRPtR5zhCu8FrbgvrQwwmzuH0iQ0AI', + expiration: new Date((new Date()).getTime() + (24 * 60 * 60 * 1000)), // tomorrow + extensionList: { + extension: [ + { + key: 'key1', + value: 'value1' + }, + { + key: 'key2', + value: 'value2' + } + ] + } + } + + t.end() + }) + + fxIndexTest.afterEach(t => { + sandbox.restore() + t.end() + }) + + fxIndexTest.test('handleFulfilResponse should', handleFulfilResponseTest => { + handleFulfilResponseTest.test('return details about regular transfer', async (test) => { + try { + fxTransfer.saveFxFulfilResponse.returns(Promise.resolve()) + const result = await Fx.handleFulfilResponse(payload.transferId, payload, TransferEventAction.FX_RESERVE, null) + test.deepEqual(result, {}) + test.ok(fxTransfer.saveFxFulfilResponse.calledWith(payload.transferId, payload, TransferEventAction.FX_RESERVE, null)) + test.pass('Error not thrown') + test.end() + } catch (e) { + test.fail('Error Thrown') + test.end() + } + }) + + handleFulfilResponseTest.test('throw errors', async (test) => { + try { + fxTransfer.saveFxFulfilResponse.throws(new Error('Error')) + const result = await Fx.handleFulfilResponse(payload.transferId, payload, TransferEventAction.FX_RESERVE, null) + test.deepEqual(result, {}) + test.ok(fxTransfer.saveFxFulfilResponse.calledWith(payload.transferId, payload, TransferEventAction.FX_RESERVE, null)) + test.fail('Error not thrown') + test.end() + } catch (e) { + test.pass('Error Thrown') + test.end() + } + }) + + handleFulfilResponseTest.end() + }) + fxIndexTest.end() +}) diff --git a/test/unit/handlers/transfers/prepare.test.js b/test/unit/handlers/transfers/prepare.test.js index 8d3e9488c..cdf8765f8 100644 --- a/test/unit/handlers/transfers/prepare.test.js +++ b/test/unit/handlers/transfers/prepare.test.js @@ -50,6 +50,7 @@ const Comparators = require('@mojaloop/central-services-shared').Util.Comparator const Proxyquire = require('proxyquire') const Participant = require('../../../../src/domain/participant') const Config = require('../../../../src/lib/config') +const { Action } = Enum.Events.Event const transfer = { transferId: 'b51ec534-ee48-4575-b6a9-ead2955b8999', @@ -793,5 +794,35 @@ Test('Transfer handler', transferHandlerTest => { prepareTest.end() }) + + transferHandlerTest.test('processDuplication', processDuplicationTest => { + processDuplicationTest.test('return undefined hasDuplicateId is falsey', async (test) => { + const result = await prepare.processDuplication({ + duplication: { + hasDuplicateId: false + } + }) + test.equal(result, undefined) + test.end() + }) + + processDuplicationTest.test('throw error if action is BULK_PREPARE', async (test) => { + try { + await prepare.processDuplication({ + duplication: { + hasDuplicateId: true + }, + duplicationId: 'test', + hasDuplicateHash: true, + action: Action.BULK_PREPARE + }) + test.fail('Error not thrown') + } catch (e) { + test.pass('Error thrown') + } + test.end() + }) + processDuplicationTest.end() + }) transferHandlerTest.end() }) From 971162872bc2f95779cb9b95b11568742e1633cb Mon Sep 17 00:00:00 2001 From: Kevin Leyow Date: Fri, 5 Apr 2024 06:55:44 -0500 Subject: [PATCH 2/2] coverage --- test/unit/handlers/transfers/prepare.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/handlers/transfers/prepare.test.js b/test/unit/handlers/transfers/prepare.test.js index cdf8765f8..5dd3ae82d 100644 --- a/test/unit/handlers/transfers/prepare.test.js +++ b/test/unit/handlers/transfers/prepare.test.js @@ -810,10 +810,10 @@ Test('Transfer handler', transferHandlerTest => { try { await prepare.processDuplication({ duplication: { - hasDuplicateId: true + hasDuplicateId: true, + hasDuplicateHash: true }, - duplicationId: 'test', - hasDuplicateHash: true, + location: { module: 'PrepareHandler', method: '', path: '' }, action: Action.BULK_PREPARE }) test.fail('Error not thrown')