From 8f6e44da051ce55e9ef609b8a2d52b5152335741 Mon Sep 17 00:00:00 2001 From: sridharvoruganti <36686863+sridharvoruganti@users.noreply.github.com> Date: Thu, 18 Feb 2021 17:21:55 +0530 Subject: [PATCH] chore: add post authorizations to mojaloopRequests (#126) * chore: add post authorizations to mojaloopRequests * chore: bump version --- src/index.d.ts | 13 +++++ src/lib/requests/mojaloopRequests.js | 9 +++ src/package-lock.json | 2 +- src/package.json | 2 +- .../lib/requests/mojaloopRequests.test.js | 55 +++++++++++++++++-- 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 7845146..aac4a9e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -552,6 +552,19 @@ declare namespace SDKStandardComponents { destParticipantId: string ): Promise; + /** + * @function postAuthorizations + * @description + * Executes a `POST /authorizations` request for the specified `authorizations request` + * @param {Object} authorizationRequest The authorization request + * @param {string} destFspId The id of the destination participant + * @returns {Promise} JSON response body if one was received + */ + postAuthorizations ( + authorizationRequest: PostAuthorizationsRequest, + destFspId: string + ): Promise; + /** * @function putAuthorizations * @description diff --git a/src/lib/requests/mojaloopRequests.js b/src/lib/requests/mojaloopRequests.js index 475035b..569f4b1 100644 --- a/src/lib/requests/mojaloopRequests.js +++ b/src/lib/requests/mojaloopRequests.js @@ -247,6 +247,15 @@ class MojaloopRequests extends BaseRequests { return this._get(url , 'authorizations', destFspId); } + /** + * Executes a POST /authorizations request for the specified authorization request + * + * @returns {object} - JSON response body if one was received + */ + async postAuthorizations(authorizationRequest, destFspId) { + return this._post('authorizations', 'authorizations', authorizationRequest, destFspId); + } + /** * Executes a PUT /authorizations/{ID} request for the specified transactionRequestId * diff --git a/src/package-lock.json b/src/package-lock.json index 4d89157..59747b5 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/sdk-standard-components", - "version": "14.0.0", + "version": "14.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index 59ffd29..9ece3d5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/sdk-standard-components", - "version": "14.0.0", + "version": "14.1.0", "description": "A set of standard components for connecting to Mojaloop API enabled Switches", "main": "index.js", "types": "index.d.ts", diff --git a/src/test/unit/lib/requests/mojaloopRequests.test.js b/src/test/unit/lib/requests/mojaloopRequests.test.js index bc9bd9b..43ba1c1 100644 --- a/src/test/unit/lib/requests/mojaloopRequests.test.js +++ b/src/test/unit/lib/requests/mojaloopRequests.test.js @@ -20,8 +20,8 @@ const jwsSigningKey = fs.readFileSync(__dirname + '/../../data/jwsSigningKey.pem describe('PUT /parties', () => { - async function testPutParties(jwsSign, jwsSignPutParties, expectUndefined) { - const wso2Auth = new WSO2Auth({logger: console}); + async function testPutParties (jwsSign, jwsSignPutParties, expectUndefined) { + const wso2Auth = new WSO2Auth({ logger: console }); // Everything is false by default const conf = { @@ -92,8 +92,8 @@ describe('PUT /parties', () => { describe('PUT /quotes', () => { - async function testPutQuotes(jwsSign, jwsSignPutParties, expectUndefined) { - const wso2Auth = new WSO2Auth({logger: console}); + async function testPutQuotes (jwsSign, jwsSignPutParties, expectUndefined) { + const wso2Auth = new WSO2Auth({ logger: console }); // Everything is false by default const conf = { @@ -118,7 +118,7 @@ describe('PUT /quotes', () => { })); const testMr = new mr(conf); - await testMr.putQuotes('fake-quote', {quoteId: 'dummy'}, 'dummy'); + await testMr.putQuotes('fake-quote', { quoteId: 'dummy' }, 'dummy'); if (expectUndefined) { expect(http.__request.mock.calls[0][0].headers['fspiop-signature']).toBeUndefined(); @@ -170,3 +170,48 @@ describe('PUT /quotes', () => { ); }); +describe('postAuthorizations', () => { + const wso2Auth = new WSO2Auth({ logger: mockLogger({ app: 'post-authorizations-test' }) }); + const conf = { + logger: mockLogger({ app: 'postAuthorizations-test' }), + peerEndpoint: '127.0.0.1', + tls: { + mutualTLS: { + enabled: false + } + }, + jwsSign: false, + jwsSignPutParties: false, + jwsSigningKey: jwsSigningKey, + wso2Auth, + }; + + it('executes a `POST /authorizations` request', async () => { + // Arrange + http.__request = jest.fn(() => ({ + statusCode: 202, + headers: { + 'content-length': 0 + }, + })); + const testMR = new mr(conf); + const authorizationRequest = { + transactionRequestId: '123', + authenticationType: 'U2F', + retriesLeft: '1', + amount: { + amount: '100', + currency: 'U2F', + }, + transactionId: '987' + }; + + // Act + await testMR.postAuthorizations(authorizationRequest, 'pispa'); + + // Assert + expect(http.__write.mock.calls[0][0]).toStrictEqual(JSON.stringify(authorizationRequest)); + expect(http.__request.mock.calls[0][0].headers['fspiop-destination']).toBe('pispa'); + expect(http.__request.mock.calls[0][0].path).toBe('/authorizations'); + }); +}); \ No newline at end of file