Skip to content

Commit

Permalink
chore: add accounts handler and update API def (#91)
Browse files Browse the repository at this point in the history
* chore: add accounts handler and update API def

* chore: improve test coverage
  • Loading branch information
sridharvoruganti authored Mar 11, 2021
1 parent c6e1a23 commit 9400256
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/simulator/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ paths:
description: |
The HTTP request `GET /accounts/{ID}` is used to retrieve the list of potential accounts available for linking.
tags:
- accounts
- Accounts
parameters:
- name: ID
in: path
Expand All @@ -569,7 +569,7 @@ paths:
content:
application/json:
schema:
type: object
$ref: '#/components/schemas/AccountsIDPutResponse'
400:
description: 'invalid request'
content:
Expand Down Expand Up @@ -1683,6 +1683,16 @@ components:
minLength: 1
maxLength: 128

accountAddress:
type: string
description: |
A long-lived unique account identifier provided by the DFSP. This MUST NOT
be Bank Account Number or anything that may expose a User's private bank
account information.
pattern: '^([0-9A-Za-z_~\-\.]+[0-9A-Za-z_~\-])$'
minLength: 1
maxLength: 1023

transferState:
type: string
enum:
Expand Down Expand Up @@ -1765,3 +1775,22 @@ components:
entered the authentication value. - REJECTED Consumer rejected the
transaction. - RESEND Consumer requested to resend the authentication
value.
AccountsIDPutResponse:
title: AccountsIDPutResponse
type: array
items:
type: object
description: |
`GET /accounts/{ID}` response.
properties:
accountNickname:
$ref: '#/components/schemas/accountAddress'
id:
$ref: '#/components/schemas/accountAddress'
currency:
$ref: '#/components/schemas/currency'
required:
- accountNickname
- id
- currency
16 changes: 16 additions & 0 deletions src/simulator/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ const healthCheck = async (ctx) => {
ctx.response.body = '';
};

const getAccountsByUserId = async (ctx) => {
try {
const { ID } = ctx.state.path.params;
// if rules not configured, return ID not found error
ctx.state.logger.log(`getAccountsByUserId rules not configured for : ${ID}`);
ctx.response.body = ApiErrorCodes.ID_NOT_FOUND;
ctx.response.status = 404;
return;
} catch (err) {
ctx.response.body = ApiErrorCodes.SERVER_ERROR;
ctx.response.status = 500;
}
};

const map = {
'/': {
Expand Down Expand Up @@ -263,6 +276,9 @@ const map = {
'/transfers/{transferId}': {
put: putTransfersById,
},
'/accounts/{ID}': {
get: getAccountsByUserId,
},
};


Expand Down
8 changes: 8 additions & 0 deletions src/test/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ test('get an otp', async (t) => {
t.is(t.context.response.status, 200);
});

test('get accounts by user Id', async (t) => {
// eslint-disable-next-line no-param-reassign
t.context.state.path = { params: { ID: 'test123' } };
await map['/accounts/{ID}'].get(t.context);
t.truthy(t.context.response.body);
t.is(t.context.response.status, 404);
});

test('get a party', async (t) => {
await t.context.state.model.party.create(party);
// eslint-disable-next-line no-param-reassign
Expand Down

0 comments on commit 9400256

Please sign in to comment.