Skip to content

Commit

Permalink
chore: add post authorizations to mojaloopRequests (#126)
Browse files Browse the repository at this point in the history
* chore: add post authorizations to mojaloopRequests

* chore: bump version
  • Loading branch information
sridharvoruganti authored Feb 18, 2021
1 parent 7ad89cb commit 8f6e44d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,19 @@ declare namespace SDKStandardComponents {
destParticipantId: string
): Promise<GenericRequestResponse | MojaloopRequestResponse>;

/**
* @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<object>} JSON response body if one was received
*/
postAuthorizations (
authorizationRequest: PostAuthorizationsRequest,
destFspId: string
): Promise<GenericRequestResponse | MojaloopRequestResponse>;

/**
* @function putAuthorizations
* @description
Expand Down
9 changes: 9 additions & 0 deletions src/lib/requests/mojaloopRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/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 src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
55 changes: 50 additions & 5 deletions src/test/unit/lib/requests/mojaloopRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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();
Expand Down Expand Up @@ -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');
});
});

0 comments on commit 8f6e44d

Please sign in to comment.