Skip to content

Commit

Permalink
fix: openapi package tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Oct 10, 2023
1 parent bdb2f56 commit e860b72
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions openapi/resource-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ paths:
properties:
walletAddress:
$ref: ./schemas.yaml#/components/schemas/walletAddress
required: true
incomingAmount:
$ref: ./schemas.yaml#/components/schemas/amount
description: The maximum amount that should be paid into the wallet address under this incoming payment.
Expand Down Expand Up @@ -333,6 +332,7 @@ paths:
examples:
Create an outgoing payment based on a quote:
value:
walletAddress: 'https://ilp.rafiki.money/alice/'
quoteId: 'https://ilp.rafiki.money/quotes/ab03296b-0c8b-4776-b94e-7ee27d868d4d'
metadata:
externalRef: INV2022-02-0137
Expand All @@ -341,7 +341,6 @@ paths:
properties:
walletAddress:
$ref: ./schemas.yaml#/components/schemas/walletAddress
required: true
quoteId:
type: string
format: uri
Expand All @@ -352,6 +351,7 @@ paths:
description: Additional metadata associated with the outgoing payment. (Optional)
required:
- quoteId
- walletAddress
additionalProperties: false
description: |-
A subset of the outgoing payments schema is accepted as input to create a new outgoing payment.
Expand Down Expand Up @@ -721,7 +721,8 @@ paths:
properties:
walletAddress:
$ref: ./schemas.yaml#/components/schemas/walletAddress
required: true
required:
- walletAddress
examples:
Complete incoming payment for https://openpayments.guide/alice:
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export interface operations {
requestBody: {
content: {
"application/json": {
walletAddress?: external["schemas.yaml"]["components"]["schemas"]["walletAddress"];
walletAddress: external["schemas.yaml"]["components"]["schemas"]["walletAddress"];
/**
* Format: uri
* @description The URL of the quote defining this payment's amounts.
Expand Down Expand Up @@ -636,7 +636,7 @@ export interface operations {
requestBody: {
content: {
"application/json": {
walletAddress?: external["schemas.yaml"]["components"]["schemas"]["walletAddress"];
walletAddress: external["schemas.yaml"]["components"]["schemas"]["walletAddress"];
};
};
};
Expand Down
11 changes: 8 additions & 3 deletions packages/openapi/src/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function createContext<T extends Koa.Context>(

const PATH = '/incoming-payments'
const SPEC = path.resolve(__dirname, '../../../openapi/resource-server.yaml')
const WALLET_ADDRESS = 'https://openpayments.guide/alice'

describe('OpenAPI Validator', (): void => {
let openApi: OpenAPI
Expand Down Expand Up @@ -75,7 +76,7 @@ describe('OpenAPI Validator', (): void => {
const ctx = createContext(
{
headers: { Accept: 'application/json' },
url: `${PATH}?first=${first}`
url: `${PATH}?first=${first}&wallet-address=${WALLET_ADDRESS}`
},
{}
)
Expand All @@ -88,7 +89,7 @@ describe('OpenAPI Validator', (): void => {
const ctx = createContext(
{
headers: { Accept: 'application/json' },
url: `${PATH}?first=NaN`
url: `${PATH}?first=NaN&wallet-address=${WALLET_ADDRESS}`
},
{}
)
Expand Down Expand Up @@ -145,6 +146,8 @@ describe('OpenAPI Validator', (): void => {
)
addTestSignatureHeaders(ctx)
ctx.request.body = body
? { ...body, walletAddress: WALLET_ADDRESS }
: body
await expect(validatePostMiddleware(ctx, next)).rejects.toMatchObject({
status: 400,
message
Expand All @@ -161,10 +164,12 @@ describe('OpenAPI Validator', (): void => {
{}
)
addTestSignatureHeaders(ctx)
ctx.request.query = { 'wallet-address': WALLET_ADDRESS }
const next = jest.fn().mockImplementation(() => {
expect(ctx.request.query).toEqual({
first: 10,
last: 10
last: 10,
'wallet-address': WALLET_ADDRESS
})
ctx.response.body = {}
})
Expand Down

0 comments on commit e860b72

Please sign in to comment.