Skip to content

Commit

Permalink
test: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev committed Jul 10, 2024
1 parent 5113952 commit 77d4b56
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/unit/handlers/transfers/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ optionally within square brackets <email>.
const Sinon = require('sinon')
const Test = require('tapes')(require('tape'))
const Kafka = require('@mojaloop/central-services-shared').Util.Kafka
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Validator = require('../../../../src/handlers/transfers/validator')
const TransferService = require('../../../../src/domain/transfer')
const Cyril = require('../../../../src/domain/fx/cyril')
Expand Down Expand Up @@ -937,6 +938,36 @@ Test('Transfer handler', transferHandlerTest => {
test.end()
})

prepareTest.test('produce error for unexpected state', async (test) => {
await Consumer.createHandler(topicName, config, command)
Kafka.transformAccountToTopicName.returns(topicName)
Kafka.proceed.returns(true)
TransferService.getById.returns(Promise.resolve({ transferState: Enum.Transfers.TransferInternalState.RESERVED_TIMEOUT }))
Comparators.duplicateCheckComparator.withArgs(transfer.transferId, transfer).returns(Promise.resolve({
hasDuplicateId: false,
hasDuplicateHash: false
}))
const result = await allTransferHandlers.prepare(null, forwardedMessages[0])
test.equal(Kafka.proceed.getCall(0).args[2].fspiopError.errorInformation.errorCode, ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR.code)
test.equal(result, true)
test.end()
})

prepareTest.test('produce error on transfer not found', async (test) => {
await Consumer.createHandler(topicName, config, command)
Kafka.transformAccountToTopicName.returns(topicName)
Kafka.proceed.returns(true)
TransferService.getById.returns(Promise.resolve(null))
Comparators.duplicateCheckComparator.withArgs(transfer.transferId, transfer).returns(Promise.resolve({
hasDuplicateId: false,
hasDuplicateHash: false
}))
const result = await allTransferHandlers.prepare(null, forwardedMessages[0])
test.equal(result, true)
test.equal(Kafka.proceed.getCall(0).args[2].fspiopError.errorInformation.errorCode, ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND.code)
test.end()
})

prepareTest.end()
})

Expand Down

0 comments on commit 77d4b56

Please sign in to comment.