Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update consentRequests simulator resp to support all error cases #86

Merged
merged 3 commits into from
Apr 15, 2021
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
6 changes: 3 additions & 3 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
Expand Up @@ -88,7 +88,7 @@
"@mojaloop/central-services-metrics": "^9.5.0",
"@mojaloop/central-services-shared": "^11.5.9",
"@mojaloop/sdk-scheme-adapter": "^11.15.0",
"@mojaloop/sdk-standard-components": "^15.6.0",
"@mojaloop/sdk-standard-components": "^15.7.0",
"@types/axios": "^0.14.0",
"@types/convict": "^5.2.2",
"@types/hapi": "^18.0.5",
Expand Down
8 changes: 6 additions & 2 deletions src/models/inbound/dfspConsentRequests.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { Method } from 'javascript-state-machine'
import { ThirdpartyRequests } from '@mojaloop/sdk-standard-components';
import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import { PubSub } from '~/shared/pub-sub'
Expand All @@ -40,8 +41,11 @@ import * as OutboundAPI from '~/interface/outbound/api_interfaces'

export interface BackendValidateConsentRequestsResponse {
isValid: boolean
authChannels: OutboundAPI.Schemas.AuthChannels
authUri?: string
data: {
sridharvoruganti marked this conversation as resolved.
Show resolved Hide resolved
authChannels: OutboundAPI.Schemas.AuthChannels
authUri?: string
}
errorInformation?: fspiopAPI.Schemas.ErrorInformation
}

export interface BackendSendOTPRequest {
Expand Down
13 changes: 6 additions & 7 deletions src/models/inbound/dfspConsentRequests.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import inspect from '~/shared/inspect'
import { reformatError } from '~/shared/util'
import { reformatError, mkMojaloopFSPIOPError } from '~/shared/util'
import {
DFSPConsentRequestsData,
DFSPConsentRequestsStateMachine,
Expand Down Expand Up @@ -88,11 +88,11 @@ export class DFSPConsentRequestsModel
const response = await this.dfspBackendRequests.validateConsentRequests(request)

if (!response) {
throw new Errors.MojaloopFSPIOPError('', '', '', Errors.MojaloopApiErrorCodes.TP_FSP_CONSENT_SCOPES_ERROR)
throw mkMojaloopFSPIOPError(Errors.MojaloopApiErrorCodes.TP_CONSENT_REQ_VALIDATION_ERROR)
}

if (!response.isValid) {
throw new Errors.MojaloopFSPIOPError('', '', '', Errors.MojaloopApiErrorCodes.TP_NO_SUPPORTED_SCOPE_ACTIONS)
throw mkMojaloopFSPIOPError(Errors.MojaloopApiErrorCodeFromCode(`${response.errorInformation?.errorCode}`))
}

this.data.response = response
Expand All @@ -102,13 +102,12 @@ export class DFSPConsentRequestsModel
const consentRequestResponse = {
scopes: request.scopes,
callbackUri: request.callbackUri,
authChannels: response.authChannels,
authUri: response.authUri,
authChannels: response.data.authChannels,
authUri: response.data.authUri,
initiatorId: toParticipantId
} as consentRequestResponseType
await this.thirdpartyRequests.putConsentRequests(request.id, consentRequestResponse, toParticipantId)


} catch (error) {
const mojaloopError = await reformatError(error)

Expand All @@ -130,7 +129,7 @@ export class DFSPConsentRequestsModel
const { request, response } = this.data

try {
const channel = [...response!.authChannels].pop()
const channel = [...response!.data.authChannels].pop()
switch (channel) {
case 'WEB': {
await this.dfspBackendRequests.storeConsentRequests(request)
Expand Down
14 changes: 13 additions & 1 deletion src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ async function reformatError (err: Error): Promise<Errors.MojaloopApiErrorObject
return new Errors.MojaloopFSPIOPError(err, '', '', mojaloopErrorCode).toApiErrorObject()
}

/**
* @function mkMojaloopFSPIOPError
* @description Helper function to create MojaloopFSPIOPError
* @param {MojaloopApiErrorCode} errorCode
* @returns {MojaloopFSPIOPError}
*/
function mkMojaloopFSPIOPError (errorCode: Errors.MojaloopApiErrorCode): Errors.MojaloopFSPIOPError {
// TODO: investigate passing non empty strings for other args
return new Errors.MojaloopFSPIOPError('', '', '', errorCode)
}

export {
reformatError
reformatError,
mkMojaloopFSPIOPError
}
32 changes: 21 additions & 11 deletions test/unit/data/mockData.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,35 @@
},
"response": {
"isValid": true,
"authChannels": [
"WEB"
],
"authUri": "dfspa.com/authorize?consentRequestId=456"
"data": {
"authChannels": [
"WEB"
],
"authUri": "dfspa.com/authorize?consentRequestId=456"
}
},
"responseOTP": {
"isValid": true,
"authChannels": [
"OTP"
]
"data": {
"authChannels": [
"OTP"
]
}
},
"responseError": {
"isValid": false,
"authChannels": []
"data": {},
"errorInformation": {
"errorCode": "7204",
"errorDescription": "FSP does not support any requested scope actions"
}
},
"responseErrorAuthChannel": {
"authChannels": [
"TEST"
]
"data": {
"authChannels": [
"TEST"
]
}
},
"otpRequest": {
"consentRequestId": "b51ec534-ee48-4575-b6a9-ead2955b8069",
Expand Down
6 changes: 3 additions & 3 deletions test/unit/models/inbound/dfspConsentRequests.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ describe('dfspConsentRequestsModel', () => {
await model.fsm.validateRequest()
shouldNotBeExecuted()
} catch (err) {
expect(err.apiErrorCode.code).toEqual('7207')
expect(err.apiErrorCode.code).toEqual('7208')
}

// check a PUT /consentsRequest/{ID}/error response was sent to source participant
expect(modelConfig.thirdpartyRequests.putConsentRequestsError).toBeCalledWith(
mockData.consentRequestsPutError.params.ID,
{
errorInformation: {
errorCode: '7207',
errorDescription: 'FSP failed retrieve scopes for consent request'
errorCode: '7208',
errorDescription: 'FSP failed to validate consent request'
}
},
'pispa'
Expand Down
11 changes: 9 additions & 2 deletions test/unit/shared/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
* Sridhar Voruganti <sridhar.voruganti@modusbox.com>
--------------
******/
import { reformatError } from '~/shared/util'
import { reformatError, mkMojaloopFSPIOPError } from '~/shared/util'
import { HTTPResponseError } from '~/shared/http-response-error'
import { Errors } from '@mojaloop/sdk-standard-components'
describe('shared/reformatError', (): void => {

describe('shared/reformatError', (): void => {
it('reformating of generic Error', async () => {
const expected = {
errorInformation: {
Expand Down Expand Up @@ -89,3 +89,10 @@ describe('shared/reformatError', (): void => {
})

})
describe('shared/mkMojaloopFSPIOPError', (): void => {
it('mkMojaloopFSPIOPError', () => {
const errorObj = mkMojaloopFSPIOPError(Errors.MojaloopApiErrorCodeFromCode('7204'))
expect(errorObj.apiErrorCode.code).toEqual('7204')
expect(errorObj.apiErrorCode.message).toEqual('FSP does not support any requested scope actions')
})
})