Skip to content

Commit

Permalink
feat: patchThirdpartyRequestsTransaction (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
eoln authored Mar 17, 2021
1 parent 10249e3 commit 4b65bd3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ declare namespace SDKStandardComponents {
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function patchThirdpartyRequestsTransactions
* @description
* Executes a `PATCH /thirdpartyRequests/transactions/${transactionRequestId}` request
* @param {Object} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
* @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
* @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
* @returns {Promise<object>} JSON response body if one was received
*/
patchThirdpartyRequestsTransactions(
thirdpartyRequestsTransactionsBody: tpAPI.Schemas.ThirdpartyRequestsTransactionsIDPatchResponse,
transactionRequestId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putThirdpartyRequestsTransactionsError
* @description
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 @@ -50,6 +50,11 @@ class ThirdpartyRequests extends BaseRequests {
return this._get(url, 'thirdparty', destParticipantId);
}

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

async putThirdpartyRequestsTransactions(thirdpartyRequestsTransactionsBody, transactionRequestId, destParticipantId) {
const url = `thirdpartyRequests/transactions/${transactionRequestId}`;
return this._put(url, 'thirdparty', thirdpartyRequestsTransactionsBody, destParticipantId);
Expand Down
5 changes: 5 additions & 0 deletions src/test/unit/data/patchThirdpartyRequestTransaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"transactionId": "987",
"transactionRequestState": "ACCEPTED",
"transactionState": "COMPLETED"
}
46 changes: 46 additions & 0 deletions src/test/unit/lib/requests/thirdpartyRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,52 @@ describe('ThirdpartyRequests', () => {
});
});

describe('patchThirdpartyRequestsTransactions', () => {
const patchSuccessRequest = require('../../data/patchThirdpartyRequestTransaction.json');
const wso2Auth = new WSO2Auth({ logger: mockLogger({app: 'patch-thirdparty-request-transaction-test'})});
const config = {
logger: mockLogger({ app: 'patchThirdpartyRequestsTransaction-test' }),
peerEndpoint: '127.0.0.1',
tls: {
mutualTLS: {
enabled: false
}
},
jwsSign: false,
jwsSignPutParties: false,
jwsSigningKey: jwsSigningKey,
wso2Auth,
};

it('executes a `PATCH /thirdpartyRequests/transactions/{ID}` request', async () => {
// Arrange
http.__request = jest.fn(() => ({
statusCode: 202,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const requestBody = patchSuccessRequest;
const transactionRequestId = 1;

// Act
await tpr.patchThirdpartyRequestsTransactions(requestBody, transactionRequestId, 'pispa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(requestBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PATCH',
'path': '/thirdpartyRequests/transactions/1',
'headers': expect.objectContaining({
'fspiop-destination': 'pispa'
})
})
);
});
});

describe('getThirdpartyRequestsTransactions', () => {
const wso2Auth = new WSO2Auth({ logger: mockLogger({app: 'get-thirdparty-request-transaction-test'})});
const config = {
Expand Down

0 comments on commit 4b65bd3

Please sign in to comment.