Skip to content

Commit

Permalink
feat: add consentRequests error request (#133)
Browse files Browse the repository at this point in the history
* feat: add consentRequests error request

* chore: fix function
  • Loading branch information
kleyow authored Mar 15, 2021
1 parent 7306e94 commit 10249e3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ declare namespace SDKStandardComponents {
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putConsentRequestsError
* @description Executes a `PUT /consentRequests/{id}/error` request.
* @param {string} consentRequestId The `id` of the consent request object to be updated
* @param {PutConsentsRequest} consentRequestBody The body of the consent request object
* @param {string} destParticipantId The id of the destination participant
*/
putConsentRequestsError(
consentRequestId: string,
consentRequestBody: fspiopAPI.Schemas.ErrorInformationObject,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function postAuthorizations
* @description
Expand Down Expand Up @@ -269,7 +282,7 @@ declare namespace SDKStandardComponents {
transactionRequestId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function getAccounts
* @description Executes a `GET /accounts/{id}` request.
Expand Down Expand Up @@ -305,7 +318,7 @@ declare namespace SDKStandardComponents {
userId: string,
accountsBody: fspiopAPI.Schemas.ErrorInformationObject,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;
}

class MojaloopRequests extends BaseRequests {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/requests/thirdpartyRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class ThirdpartyRequests extends BaseRequests {
return this._post('consentRequests', 'thirdparty', consentRequestBody, destParticipantId);
}

async putConsentRequestsError(consentRequestId, consentRequestBody, destParticipantId) {
const url = `consentRequests/${consentRequestId}/error`;
return this._put(url, 'thirdparty', consentRequestBody, destParticipantId);
}

async postAuthorizations(authorizationBody, destParticipantId) {
return this._post('authorizations', 'authorizations', authorizationBody, destParticipantId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-standard-components",
"version": "15.2.1",
"version": "15.3.0",
"description": "A set of standard components for connecting to Mojaloop API enabled Switches",
"main": "index.js",
"types": "index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions src/test/unit/data/putConsentRequestsRequestError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"errorInformation": {
"errorCode":"6000",
"errorDescription":"Generic third party error.",
"extensionList":{
"extension":[
{
"key":"errorDescription",
"value":"This is a more detailed error description"
}
]
}
}
}
47 changes: 47 additions & 0 deletions src/test/unit/lib/requests/thirdpartyRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,53 @@ describe('ThirdpartyRequests', () => {
});
});

describe('putConsentRequestsRequestError', () => {
const putConsentRequestsRequestError = require('../../data/putConsentRequestsRequestError.json');
const wso2Auth = new WSO2Auth({ logger: mockLogger({ app: 'put-consent-requests-error-test' }) });
const config = {
logger: mockLogger({ app: 'put-consent-requests-error-test' }),
peerEndpoint: '127.0.0.1',
thirdpartyRequestsEndpoint: 'thirdparty-api-adapter.local',
tls: {
mutualTLS: {
enabled: false
}
},
jwsSign: false,
jwsSignPutParties: false,
jwsSigningKey: jwsSigningKey,
wso2Auth,
};

it('executes a `PUT /consentRequests/{ID}/error` request', async () => {
http.__request.mockClear();
// Arrange
http.__request = jest.fn(() => ({
statusCode: 200,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const requestBody = putConsentRequestsRequestError;
const consentRequestId = '12345';
// Act
await tpr.putConsentRequestsError(consentRequestId, requestBody, 'pispa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(requestBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PUT',
'path': '/consentRequests/12345/error',
'headers': expect.objectContaining({
'fspiop-destination': 'pispa'
})
})
);
});
});

describe('postConsentRequests', () => {
const postConsentRequestsRequest = require('../../data/postConsentRequestsRequest.json');
const wso2Auth = new WSO2Auth({ logger: mockLogger({ app: 'post-consent-requests-test' }) });
Expand Down

0 comments on commit 10249e3

Please sign in to comment.