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 request headers to accounts endpoint #60

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/handlers/outbound/accounts/{ID}.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function get (_context: any, request: Request, h: StateResponseToolkit): P
const userId: string = request.params.ID
// prepare config
const data: OutboundAccountsData = {
toParticipantId: '',
toParticipantId: request.headers['fspiop-destination'],
userId: userId,
currentState: 'start'
}
Expand Down
28 changes: 28 additions & 0 deletions src/interface/api-outbound.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ paths:
- accounts
parameters:
- $ref: '#/components/parameters/ID'
- $ref: '#/components/parameters/FSPIOP-Source'
- $ref: '#/components/parameters/FSPIOP-Destination'
responses:
'200':
$ref: '#/components/responses/AccountsByUserIdResponse'
Expand Down Expand Up @@ -1617,3 +1619,29 @@ components:
schema:
type: string
description: The identifier value.
FSPIOP-Source:
name: FSPIOP-Source
in: header
schema:
type: string
required: true
description: >-
The `FSPIOP-Source` header field is a non-HTTP standard field used by
the API for identifying the sender of the HTTP request. The field should
be set by the original sender of the request. Required for routing and
signature verification (see header field `FSPIOP-Signature`).
FSPIOP-Destination:
name: FSPIOP-Destination
in: header
schema:
type: string
required: false
description: >-
The `FSPIOP-Destination` header field is a non-HTTP standard field used
by the API for HTTP header based routing of requests and responses to
the destination. The field must be set by the original sender of the
request if the destination is known (valid for all services except GET
/parties) so that any entities between the client and the server do not
need to parse the payload for routing purposes. If the destination is
not known (valid for service GET /parties), the field should be left
empty.
8 changes: 8 additions & 0 deletions src/interface/outbound/api_interfaces/openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export interface operations {
path: {
ID: components["parameters"]["ID"];
};
header: {
"FSPIOP-Source": components["parameters"]["FSPIOP-Source"];
"FSPIOP-Destination"?: components["parameters"]["FSPIOP-Destination"];
};
};
responses: {
200: components["responses"]["AccountsByUserIdResponse"];
Expand All @@ -184,6 +188,10 @@ export interface components {
parameters: {
/** The identifier value. */
ID: string;
/** The `FSPIOP-Source` header field is a non-HTTP standard field used by the API for identifying the sender of the HTTP request. The field should be set by the original sender of the request. Required for routing and signature verification (see header field `FSPIOP-Signature`). */
"FSPIOP-Source": string;
/** The `FSPIOP-Destination` header field is a non-HTTP standard field used by the API for HTTP header based routing of requests and responses to the destination. The field must be set by the original sender of the request if the destination is known (valid for all services except GET /parties) so that any entities between the client and the server do not need to parse the payload for routing purposes. If the destination is not known (valid for service GET /parties), the field should be left empty. */
"FSPIOP-Destination": string;
};
schemas: {
/** The API data type ErrorCode is a JSON String of four characters, consisting of digits only. Negative numbers are not allowed. A leading zero is not allowed. Each error code in the API is a four-digit number, for example, 1234, where the first number (1 in the example) represents the high-level error category, the second number (2 in the example) represents the low-level error category, and the last two numbers (34 in the example) represent the specific error. */
Expand Down
4 changes: 4 additions & 0 deletions src/interface/outbound/api_template/paths/accounts_ID.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ get:
tags:
- accounts
parameters:
#Path
- $ref: '../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/ID.yaml'
#Headers
- $ref: '../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/FSPIOP-Source.yaml'
- $ref: '../../../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/FSPIOP-Destination.yaml'
responses:
'200':
$ref: '../components/responses/AccountsByUserIdResponse.yaml'
Expand Down
3 changes: 2 additions & 1 deletion src/models/accounts.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
ThirdpartyRequests
} from '@mojaloop/sdk-standard-components'
import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import { PubSub } from '~/shared/pub-sub'
Expand All @@ -44,7 +45,7 @@ export enum OutboundAccountsModelState {
}

export interface OutboundAccountsGetResponse {
accounts: tpAPI.Schemas.AccountsIDPutResponse,
accounts: tpAPI.Schemas.AccountsIDPutResponse | fspiopAPI.Schemas.ErrorInformationObject,
currentState: OutboundAccountsModelState;
}

Expand Down
11 changes: 7 additions & 4 deletions src/models/outbound/accounts.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
OutboundAccountsStateMachine
} from '~/models/accounts.interface'
import {
v1_1 as fspiopAPI,
thirdparty as tpAPI
} from '@mojaloop/api-snippets'
import { Message, PubSub } from '~/shared/pub-sub'
Expand Down Expand Up @@ -99,13 +100,15 @@ export class OutboundAccountsModel
// in handlers/inbound is implemented UpdateAccountsByUserId handler
// which publish getAccounts response to channel
subId = this.pubSub.subscribe(channel, async (channel: string, message: Message, sid: number) => {
// if (!message) {
// return reject(new Error('invalid Message'))
// }

// first unsubscribe
pubSub.unsubscribe(channel, sid)

const putResponse = [ ...message as unknown as tpAPI.Schemas.AccountsIDPutResponse ]
let putResponse: tpAPI.Schemas.AccountsIDPutResponse | fspiopAPI.Schemas.ErrorInformationObject
sridharvoruganti marked this conversation as resolved.
Show resolved Hide resolved
if (JSON.stringify(message).indexOf('errorCode') === -1)
putResponse = [...message as unknown as tpAPI.Schemas.AccountsIDPutResponse]
else
putResponse = { ...message as unknown as fspiopAPI.Schemas.ErrorInformationObject }
// store response which will be returned by 'getResponse' method in workflow 'run'
this.data.response = {
accounts: putResponse,
Expand Down
9 changes: 8 additions & 1 deletion test/integration/outbound/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import axios from 'axios'

describe('GET /accounts/{ID}', (): void => {
const scenariosURI = `http://127.0.0.1:4056/accounts/username1234`
const requestConfig = {
headers: {
'FSPIOP-Source': 'pisp',
'FSPIOP-Destination': 'dfspA',
Date: new Date().toUTCString()
}
}
const expectedResp = {
accounts: [
{
Expand All @@ -47,7 +54,7 @@ describe('GET /accounts/{ID}', (): void => {

it('PISP requests DFSP to return user accounts for linking', async (): Promise<void> => {
// Act
const response = await axios.get(scenariosURI)
const response = await axios.get(scenariosURI, requestConfig)

// Assert
expect(response.status).toBe(200)
Expand Down
5 changes: 4 additions & 1 deletion test/unit/handlers/outbound-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ describe('Outbound API routes', (): void => {
const request = {
method: 'GET',
url: '/accounts/username1234',
headers: {}
headers: {
'FSPIOP-Source': 'pisp',
'FSPIOP-Destination': 'dfspA',
}
}
const pubSub = new PubSub({} as RedisConnectionConfig)
// defer publication to notification channel
Expand Down