From e860b726ff28ffc2779813bf59f1c7d34b800974 Mon Sep 17 00:00:00 2001 From: Nathan Lie Date: Thu, 5 Oct 2023 13:40:09 -0700 Subject: [PATCH] fix: openapi package tests --- openapi/resource-server.yaml | 7 ++++--- .../src/openapi/generated/resource-server-types.ts | 4 ++-- packages/openapi/src/middleware.test.ts | 11 ++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/openapi/resource-server.yaml b/openapi/resource-server.yaml index 2a9bcf04..8feb6a16 100644 --- a/openapi/resource-server.yaml +++ b/openapi/resource-server.yaml @@ -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. @@ -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 @@ -341,7 +341,6 @@ paths: properties: walletAddress: $ref: ./schemas.yaml#/components/schemas/walletAddress - required: true quoteId: type: string format: uri @@ -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. @@ -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: diff --git a/packages/open-payments/src/openapi/generated/resource-server-types.ts b/packages/open-payments/src/openapi/generated/resource-server-types.ts index 91fa50f0..af6c385a 100644 --- a/packages/open-payments/src/openapi/generated/resource-server-types.ts +++ b/packages/open-payments/src/openapi/generated/resource-server-types.ts @@ -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. @@ -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"]; }; }; }; diff --git a/packages/openapi/src/middleware.test.ts b/packages/openapi/src/middleware.test.ts index f7482884..cefaec06 100644 --- a/packages/openapi/src/middleware.test.ts +++ b/packages/openapi/src/middleware.test.ts @@ -37,6 +37,7 @@ export function createContext( 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 @@ -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}` }, {} ) @@ -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}` }, {} ) @@ -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 @@ -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 = {} })