Skip to content

Commit

Permalink
feat(thirdparty): add tpr/authorizations calls (#160)
Browse files Browse the repository at this point in the history
* feat: add *ThirdpartyRequestsAuthorizations API calls

* feat(unit): tests for tpr/authorizations calls

* chore: appease linting gods
  • Loading branch information
lewisdaly authored Aug 27, 2021
1 parent c87e3ca commit dca8da5
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 8 deletions.
47 changes: 47 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ declare namespace SDKStandardComponents {
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @deprecated - use postThirdpartyRequestsAuthorizations instead
* @function postThirdpartyRequestsTransactionsAuthorizations
* @description
* Executes a `POST /thirdpartyRequests/transactions/${transactionRequestId}/authorizations` request
Expand All @@ -269,6 +270,7 @@ declare namespace SDKStandardComponents {
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @deprecated - use putThirdpartyRequestsAuthorizations instead
* @function putThirdpartyRequestsTransactionsAuthorizations
* @description
* Executes a `PUT /thirdpartyRequests/transactions/${transactionRequestId}/authorizations` request
Expand All @@ -284,6 +286,7 @@ declare namespace SDKStandardComponents {
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @deprecated - use putThirdpartyRequestsAuthorizationsError instead
* @function putThirdpartyRequestsTransactionsAuthorizationsError
* @description
* Executes a `PUT thirdpartyRequests/transactions/${transactionRequestId}/authorizations/error` request
Expand All @@ -298,6 +301,50 @@ declare namespace SDKStandardComponents {
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;


/**
* @function postThirdpartyRequestsAuthorizations
* @description
* Executes a `POST /thirdpartyRequests/authorizations` request
* @param {Object} body The authorization request body
* @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
* @returns {Promise<object>} JSON response body if one was received
*/
postThirdpartyRequestsAuthorizations(
body: tpAPI.Schemas.ThirdpartyRequestsAuthorizationsPostRequest,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putThirdpartyRequestsAuthorizations
* @description
* Executes a `PUT /thirdpartyRequests/authorizations/${authorizationRequestId}` request
* @param {Object} body The authorization response body
* @param {string} authorizationRequestId The authorizationRequestId
* @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
* @returns {Promise<object>} JSON response body if one was received
*/
putThirdpartyRequestsAuthorizations(
body: tpAPI.Schemas.ThirdpartyRequestsAuthorizationsIDPutResponse,
authorizationRequestId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putThirdpartyRequestsAuthorizations
* @description
* Executes a `PUT /thirdpartyRequests/authorizations/${authorizationRequestId}/error` request
* @param {Object} body The error body
* @param {string} authorizationRequestId The authorizationRequestId
* @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
* @returns {Promise<object>} JSON response body if one was received
*/
putThirdpartyRequestsAuthorizationsError(
body: tpAPI.Schemas.ThirdpartyRequestsAuthorizationsIDPutResponse,
authorizationRequestId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function getAccounts
* @description Executes a `GET /accounts/{id}` request.
Expand Down
19 changes: 19 additions & 0 deletions src/lib/requests/thirdpartyRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,39 @@ class ThirdpartyRequests extends BaseRequests {
}

async postThirdpartyRequestsTransactionsAuthorizations(thirdpartyRequestsTransactionsBody, transactionRequestId, destParticipantId) {
this.logger.log('postThirdpartyRequestsTransactionsAuthorizations is deprecated. Use `postThirdpartyRequestsAuthorizations` instead');
const url = `thirdpartyRequests/transactions/${transactionRequestId}/authorizations`;
return this._post(url, 'thirdparty', thirdpartyRequestsTransactionsBody, destParticipantId);
}

async putThirdpartyRequestsTransactionsAuthorizations(thirdpartyRequestsTransactionsBody, transactionRequestId, destParticipantId) {
this.logger.log('putThirdpartyRequestsTransactionsAuthorizations is deprecated. Use `putThirdpartyRequestsAuthorizations` instead');

const url = `thirdpartyRequests/transactions/${transactionRequestId}/authorizations`;
return this._put(url, 'thirdparty', thirdpartyRequestsTransactionsBody, destParticipantId);
}

async putThirdpartyRequestsTransactionsAuthorizationsError(thirdpartyRequestsTransactionsBody, transactionRequestId, destParticipantId) {
this.logger.log('putThirdpartyRequestsTransactionsAuthorizationsError is deprecated. Use `putThirdpartyRequestsAuthorizationsError` instead');
const url = `thirdpartyRequests/transactions/${transactionRequestId}/authorizations/error`;
return this._put(url, 'thirdparty', thirdpartyRequestsTransactionsBody, destParticipantId);
}

async postThirdpartyRequestsAuthorizations(body, destParticipantId) {
const url = 'thirdpartyRequests/authorizations';
return this._post(url, 'thirdparty', body, destParticipantId);
}

async putThirdpartyRequestsAuthorizations(body, authorizationRequestId, destParticipantId) {
const url = `thirdpartyRequests/authorizations/${authorizationRequestId}`;
return this._put(url, 'thirdparty', body, destParticipantId);
}

async putThirdpartyRequestsAuthorizationsError(body, authorizationRequestId, destParticipantId) {
const url = `thirdpartyRequests/authorizations/${authorizationRequestId}/error`;
return this._put(url, 'thirdparty', body, destParticipantId);
}

async postThirdpartyRequestsVerifications(thirdpartyRequestsVerificationsBody, destParticipantId) {
const url = 'thirdpartyRequests/verifications';
return this._post(url, 'thirdparty', thirdpartyRequestsVerificationsBody, destParticipantId);
Expand Down
23 changes: 16 additions & 7 deletions 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
Expand Up @@ -34,7 +34,7 @@
"jws": "4.0.0"
},
"devDependencies": {
"@mojaloop/api-snippets": "^12.6.0",
"@mojaloop/api-snippets": "^12.6.6",
"@types/jest": "^25.2.1",
"@types/node": "^14.11.8",
"eslint": "7.0.0",
Expand Down
35 changes: 35 additions & 0 deletions src/test/unit/data/postThirdpartyRequestsAuthorizationBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"authorizationRequestId": "5f8ee7f9-290f-4e03-ae1c-1e81ecf398df",
"transactionRequestId": "2cf08eed-3540-489e-85fa-b2477838a8c5",
"challenge": "<base64 encoded binary - the encoded challenge>",
"transferAmount": {
"amount": "100",
"currency": "USD"
},
"payeeReceiveAmount": {
"amount": "99",
"currency": "USD"
},
"fees": {
"amount": "1",
"currency": "USD"
},
"payee": {
"partyIdInfo": {
"partyIdType": "MSISDN",
"partyIdentifier": "+4412345678",
"fspId": "dfspb"
}
},
"payer": {
"partyIdType": "THIRD_PARTY_LINK",
"partyIdentifier": "qwerty-123456",
"fspId": "dfspa"
},
"transactionType": {
"scenario": "TRANSFER",
"initiator": "PAYER",
"initiatorType": "CONSUMER"
},
"expiration": "2020-06-15T12:00:00.000Z"
}
13 changes: 13 additions & 0 deletions src/test/unit/data/putThirdpartyRequestsAuthorizationBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"signedPayloadType": "FIDO",
"signedPayload": {
"id": "45c-TkfkjQovQeAWmOy-RLBHEJ_e4jYzQYgD8VdbkePgM5d98BaAadadNYrknxgH0jQEON8zBydLgh1EqoC9DA",
"rawId": "45c+TkfkjQovQeAWmOy+RLBHEJ/e4jYzQYgD8VdbkePgM5d98BaAadadNYrknxgH0jQEON8zBydLgh1EqoC9DA==",
"response": {
"authenticatorData": "SZYN5YgOjGh0NBcPZHZgW4/krrmihjLHmVzzuoMdl2MBAAAACA==",
"clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoiQUFBQUFBQUFBQUFBQUFBQUFBRUNBdyIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDIxODEiLCJjcm9zc09yaWdpbiI6ZmFsc2UsIm90aGVyX2tleXNfY2FuX2JlX2FkZGVkX2hlcmUiOiJkbyBub3QgY29tcGFyZSBjbGllbnREYXRhSlNPTiBhZ2FpbnN0IGEgdGVtcGxhdGUuIFNlZSBodHRwczovL2dvby5nbC95YWJQZXgifQ==",
"signature": "MEUCIDcJRBu5aOLJVc/sPyECmYi23w8xF35n3RNhyUNVwQ2nAiEA+Lnd8dBn06OKkEgAq00BVbmH87ybQHfXlf1Y4RJqwQ8="
},
"type": "public-key"
}
}
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"
}
]
}
}
}
103 changes: 103 additions & 0 deletions src/test/unit/lib/requests/thirdpartyRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,109 @@ describe('ThirdpartyRequests', () => {
});
});

describe('*ThirdpartyRequestsAuthorizations', () => {
const postThirdpartyRequestsAuthorizationBody = require('../../data/postThirdpartyRequestsAuthorizationBody.json');
const putThirdpartyRequestsAuthorizationBody = require('../../data/putThirdpartyRequestsAuthorizationBody.json');
const putThirdpartyRequestsAuthorizationErrorBody = require('../../data/putThirdpartyRequestsAuthorizationErrorBody.json');
const wso2Auth = new WSO2Auth({ logger: mockLogger({ app: '*ThirdpartyRequestsAuthorizations-test' }) });

const config = {
logger: mockLogger({ app: '*ThirdpartyRequestsAuthorizations-test' }),
peerEndpoint: '127.0.0.1',
tls: {
mutualTLS: {
enabled: false
}
},
jwsSign: false,
jwsSignPutParties: false,
jwsSigningKey: jwsSigningKey,
wso2Auth,
};

it('executes a POST /thirdpartyRequests/authorizations call', async () => {
// Arrange
http.__request = jest.fn(() => ({
statusCode: 202,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);

// Act
await tpr.postThirdpartyRequestsAuthorizations(postThirdpartyRequestsAuthorizationBody, 'dfspa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(postThirdpartyRequestsAuthorizationBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'POST',
'path': '/thirdpartyRequests/authorizations',
'headers': expect.objectContaining({
'fspiop-destination': 'dfspa'
})
})
);
});

it('executes a PUT /thirdpartyRequests/authorizations/{ID} call', async () => {
// Arrange
http.__request = jest.fn(() => ({
statusCode: 200,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const authorizationRequestId = 1;

// Act
await tpr.putThirdpartyRequestsAuthorizations(putThirdpartyRequestsAuthorizationBody, authorizationRequestId, 'dfspa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(putThirdpartyRequestsAuthorizationBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PUT',
'path': '/thirdpartyRequests/authorizations/1',
'headers': expect.objectContaining({
'fspiop-destination': 'dfspa'
})
})
);
});

it('executes a PUT /thirdpartyRequests/authorizations/{ID}/error call', async () => {
// Arrange
http.__request = jest.fn(() => ({
statusCode: 200,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const authorizationRequestId = 1;

// Act
await tpr.putThirdpartyRequestsAuthorizationsError(putThirdpartyRequestsAuthorizationErrorBody, authorizationRequestId, 'dfspa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(putThirdpartyRequestsAuthorizationErrorBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PUT',
'path': '/thirdpartyRequests/authorizations/1/error',
'headers': expect.objectContaining({
'fspiop-destination': 'dfspa'
})
})
);
});


});

describe('accountRequests', () => {
const putAccountsRequest = require('../../data/putAccountsByUserIdRequest.json');
const putErrorRequest = require('../../data/putAccountsByRequestError.json');
Expand Down

0 comments on commit dca8da5

Please sign in to comment.