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

chore: add accounts handler and update API def #91

Merged
merged 2 commits into from
Mar 11, 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
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