-
Notifications
You must be signed in to change notification settings - Fork 89
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
663/mk/open payments validate #679
Changes from 30 commits
d3470c4
7f968c3
79e7cd7
32e2a31
050ebef
9893029
c15fdbc
130e310
e067011
dc28878
39b561b
9393e47
3c3a0b7
120dcae
80d9856
218f1f0
d7c203c
dfc07cb
d59c2ea
43335f6
723de2f
02b8f9f
f8c1846
f560c79
e11ec65
0dad54d
000fc9b
25d2617
f734dff
4552188
85db136
dc4aa0f
c927291
3ed946b
347075a
90bc6b0
3129f2a
05b6cfb
f1d2412
f6eb6a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { getILPStreamConnection } from './ilp-stream-connection' | ||
import { OpenAPI, HttpMethod, createOpenAPI } from 'openapi' | ||
import { createAxiosInstance } from './requests' | ||
import config from '../config' | ||
|
||
jest.mock('./requests', () => ({ | ||
...jest.requireActual('./requests'), | ||
get: jest.fn() | ||
})) | ||
|
||
describe('ilp-stream-connection', (): void => { | ||
let openApi: OpenAPI | ||
|
||
beforeAll(async () => { | ||
openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
}) | ||
|
||
const axiosInstance = createAxiosInstance() | ||
|
||
describe('getILPStreamConnection', (): void => { | ||
test('calls createResponseValidator properly', async (): Promise<void> => { | ||
const createResponseValidatorSpy = jest.spyOn( | ||
openApi, | ||
'createResponseValidator' | ||
) | ||
|
||
await getILPStreamConnection(axiosInstance, openApi, { | ||
url: 'http://localhost:1000/incoming-payment' | ||
}) | ||
expect(createResponseValidatorSpy).toHaveBeenCalledWith({ | ||
path: '/connections/{id}', | ||
method: HttpMethod.GET | ||
}) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AxiosInstance } from 'axios' | ||
import { OpenAPI, HttpMethod } from 'openapi' | ||
import { getPath, ILPStreamConnection } from '../types' | ||
import { GetArgs, get } from './requests' | ||
|
||
export const getILPStreamConnection = async ( | ||
axios: AxiosInstance, | ||
openApi: OpenAPI, | ||
args: GetArgs | ||
): Promise<ILPStreamConnection> => { | ||
return get( | ||
axios, | ||
args, | ||
openApi.createResponseValidator({ | ||
path: getPath('/connections/{id}'), | ||
method: HttpMethod.GET | ||
}) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { getIncomingPayment } from './incoming-payment' | ||
import { OpenAPI, HttpMethod, createOpenAPI } from 'openapi' | ||
import { createAxiosInstance } from './requests' | ||
import config from '../config' | ||
|
||
jest.mock('./requests', () => ({ | ||
...jest.requireActual('./requests'), | ||
get: jest.fn() | ||
})) | ||
|
||
describe('incoming-payment', (): void => { | ||
let openApi: OpenAPI | ||
|
||
beforeAll(async () => { | ||
openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
}) | ||
|
||
const axiosInstance = createAxiosInstance() | ||
|
||
describe('getIncomingPayment', (): void => { | ||
test('calls createResponseValidator properly', async (): Promise<void> => { | ||
const createResponseValidatorSpy = jest.spyOn( | ||
openApi, | ||
'createResponseValidator' | ||
) | ||
|
||
await getIncomingPayment(axiosInstance, openApi, { | ||
url: 'http://localhost:1000/incoming-payment' | ||
}) | ||
expect(createResponseValidatorSpy).toHaveBeenCalledWith({ | ||
path: '/incoming-payments/{id}', | ||
method: HttpMethod.GET | ||
}) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AxiosInstance } from 'axios' | ||
import { OpenAPI, HttpMethod } from 'openapi' | ||
import { IncomingPayment, getPath } from '../types' | ||
import { GetArgs, get } from './requests' | ||
|
||
export const getIncomingPayment = async ( | ||
axios: AxiosInstance, | ||
openApi: OpenAPI, | ||
args: GetArgs | ||
): Promise<IncomingPayment> => { | ||
return get( | ||
axios, | ||
args, | ||
openApi.createResponseValidator({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The response validator library uses Ajv, which recommends instantiating once at initialization (vs once per request here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, updated to create the validators just once. Will also update the docs. |
||
path: getPath('/incoming-payments/{id}'), | ||
method: HttpMethod.GET | ||
}) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createOpenAPI } from 'openapi' | ||
|
||
import { ILPStreamConnection, IncomingPayment } from '../types' | ||
import config from '../config' | ||
import { getIncomingPayment } from './incoming-payment' | ||
import { getILPStreamConnection } from './ilp-stream-connection' | ||
import { createAxiosInstance, GetArgs } from './requests' | ||
|
||
export interface CreateOpenPaymentClientArgs { | ||
timeout?: number | ||
} | ||
|
||
export interface OpenPaymentsClient { | ||
incomingPayment: { | ||
get(args: GetArgs): Promise<IncomingPayment> | ||
} | ||
ilpStreamConnection: { | ||
get(args: GetArgs): Promise<ILPStreamConnection> | ||
} | ||
} | ||
|
||
export const createClient = async ( | ||
args?: CreateOpenPaymentClientArgs | ||
): Promise<OpenPaymentsClient> => { | ||
const axios = createAxiosInstance(args) | ||
const openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using the same version to validate the Open API as was used for generating the types in the first place |
||
|
||
return { | ||
incomingPayment: { | ||
get: (args: GetArgs) => getIncomingPayment(axios, openApi, args) | ||
}, | ||
ilpStreamConnection: { | ||
get: (args: GetArgs) => getILPStreamConnection(axios, openApi, args) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how important these tests in particular are, but I thought it was worth making sure we are adding the correct path for the response validator