Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add accounts requests to thirdparty requests #132

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,43 @@ declare namespace SDKStandardComponents {
transactionRequestId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function getAccounts
* @description Executes a `GET /accounts/{id}` request.
* @param {string} userId The `id` of the user
* @param {string} destParticipantId The id of the destination participant
*/
getAccounts (
userId: string,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putAccounts
* @description Executes a `PUT /accounts/{id}` request.
* @param {string} userId The `id` of the user
* @param {AccountsIDPutResponse} accountsBody The body of the accounts object
* @param {string} destParticipantId The id of the destination participant
*/
putAccounts (
userId: string,
accountsBody: tpAPI.Schemas.AccountsIDPutResponse,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;

/**
* @function putAccountsError
* @description Executes a `PUT /accounts/{id}/error` request.
* @param {string} userId The `id` of the user
* @param {TErrorInformationObject} accountsBody The body of the error object
* @param {string} destParticipantId The id of the destination participant
*/
putAccountsError (
userId: string,
accountsBody: fspiopAPI.Schemas.ErrorInformationObject,
destParticipantId: string
): Promise<GenericRequestResponse | GenericRequestResponseUndefined>;
}

class MojaloopRequests extends BaseRequests {
Expand Down
15 changes: 15 additions & 0 deletions src/lib/requests/thirdpartyRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ class ThirdpartyRequests extends BaseRequests {
const url = `thirdpartyRequests/transactions/${transactionRequestId}/authorizations/error`;
return this._put(url, 'thirdparty', thirdpartyRequestsTransactionsBody, destParticipantId);
}

async getAccounts (userId, destParticipantId) {
const url = `accounts/${userId}`;
return this._get(url, 'thirdparty', destParticipantId);
}

async putAccounts (userId, accountsBody, destParticipantId) {
const url = `accounts/${userId}`;
return this._put(url, 'thirdparty', accountsBody, destParticipantId);
}

async putAccountsError (userId, accountsBody, destParticipantId) {
const url = `accounts/${userId}/error`;
return this._put(url, 'thirdparty', accountsBody, destParticipantId);
}
}


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.1.0",
"version": "15.2.0",
"description": "A set of standard components for connecting to Mojaloop API enabled Switches",
"main": "index.js",
"types": "index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions src/test/unit/data/putAccountsByRequestError.json
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"
}
]
}
}
}
12 changes: 12 additions & 0 deletions src/test/unit/data/putAccountsByUserIdRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"accountNickname": "dfspa.user.nickname1",
"id": "dfspa.username.1234",
"currency": "ZAR"
},
{
"accountNickname": "dfspa.user.nickname2",
"id": "dfspa.username.5678",
"currency": "USD"
}
]
104 changes: 104 additions & 0 deletions src/test/unit/lib/requests/thirdpartyRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,108 @@ describe('ThirdpartyRequests', () => {
);
});
});

describe('accountRequests', () => {
const putAccountsRequest = require('../../data/putAccountsByUserIdRequest.json');
const putErrorRequest = require('../../data/putAccountsByRequestError.json');
const wso2Auth = new WSO2Auth({ logger: mockLogger({ app: 'accounts-requests-test' }) });
const config = {
logger: mockLogger({ app: 'accounts-requests-test' }),
peerEndpoint: '127.0.0.1',
tls: {
mutualTLS: {
enabled: false
}
},
jwsSign: false,
jwsSignPutParties: false,
jwsSigningKey: jwsSigningKey,
wso2Auth,
};

it('executes a `GET /accounts/{ID}` request', async () => {
// Arrange
http.__request.mockClear();
http.__request = jest.fn(() => ({
statusCode: 202,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const userId = 'username1234';

// Act
await tpr.getAccounts(userId, 'dfspa');

// Assert
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'GET',
'path': '/accounts/username1234',
'headers': expect.objectContaining({
'fspiop-destination': 'dfspa'
})
})
);
});

it('executes a `PUT /accounts/{ID}` request', async () => {
// Arrange
http.__request.mockClear();
http.__request = jest.fn(() => ({
statusCode: 200,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const requestBody = putAccountsRequest;
const userId = 'username1234';

// Act
await tpr.putAccounts(userId, requestBody, 'pispa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(requestBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PUT',
'path': '/accounts/username1234',
'headers': expect.objectContaining({
'fspiop-destination': 'pispa'
})
})
);
});

it('executes a `PUT /accounts/{ID}/error` request', async () => {
http.__request.mockClear();
// Arrange
http.__request = jest.fn(() => ({
statusCode: 200,
headers: {
'content-length': 0
},
}));
const tpr = new ThirdpartyRequests(config);
const requestBody = putErrorRequest;
const userId = 'username1234';

// Act
await tpr.putAccountsError(userId, requestBody, 'pispa');

// Assert
expect(http.__write).toHaveBeenCalledWith((JSON.stringify(requestBody)));
expect(http.__request).toHaveBeenCalledWith(
expect.objectContaining({
'method': 'PUT',
'path': '/accounts/username1234/error',
'headers': expect.objectContaining({
'fspiop-destination': 'pispa'
})
})
);
});
});
});