Skip to content

Commit

Permalink
add PATCH /transfers/{transferId} request to mojaloopRequests module (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bushjames authored Jun 15, 2021
1 parent 7945358 commit b08746a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/lib/requests/mojaloopRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ class MojaloopRequests extends BaseRequests {
return this._put(`transfers/${transferId}`, 'transfers', fulfilment, destFspId);
}

/**
* Executes a PATCH /transfers/{ID} request for the specified transfer update
*
* @returns {object} - JSON response body if one was received
*/
async patchTransfers(transferId, body, destFspId) {
return this._patch(`transfers/${transferId}`, 'transfers', body, destFspId);
}

/**
* Executes a PUT /transfers/{ID}/error request for the specified error
*
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": "15.10.5",
"version": "15.11.0",
"description": "A set of standard components for connecting to Mojaloop API enabled Switches",
"main": "index.js",
"types": "index.d.ts",
Expand Down
47 changes: 46 additions & 1 deletion src/test/unit/lib/requests/mojaloopRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,49 @@ describe('postAuthorizations', () => {
expect(http.__request.mock.calls[0][0].headers['fspiop-destination']).toBe('pispa');
expect(http.__request.mock.calls[0][0].path).toBe('/authorizations');
});
});
});

describe('patchTransfers', () => {
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 PATCH /transfers request', async () => {
// Arrange
http.__request = jest.fn(() => ({
statusCode: 202,
headers: {
'content-length': 0
},
}));
const testMR = new mr(conf);

const now = new Date();
const xferId = '123456';

const patchRequest = {
completedTimestamp: now.toISOString(),
transferState: 'COMMITTED',
};

// Act
await testMR.patchTransfers(xferId, patchRequest, 'patchdfsp');

// Assert
expect(http.__write.mock.calls[0][0]).toStrictEqual(JSON.stringify(patchRequest));
expect(http.__request.mock.calls[0][0].headers['fspiop-destination']).toBe('patchdfsp');
expect(http.__request.mock.calls[0][0].path).toBe(`/transfers/${xferId}`);
expect(http.__request.mock.calls[0][0].method).toBe('PATCH');
});
});

0 comments on commit b08746a

Please sign in to comment.