From b7d26631c2242565fe0c0d13e1f77eeceeeee849 Mon Sep 17 00:00:00 2001 From: Nathan Lie Date: Tue, 21 May 2024 07:23:17 -0700 Subject: [PATCH] feat: test openapi validation error --- packages/auth/src/shared/gnapErrors.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/auth/src/shared/gnapErrors.test.ts b/packages/auth/src/shared/gnapErrors.test.ts index 5014211bae..17eb654d44 100644 --- a/packages/auth/src/shared/gnapErrors.test.ts +++ b/packages/auth/src/shared/gnapErrors.test.ts @@ -9,6 +9,7 @@ import { GNAPServerRouteError, gnapServerErrorMiddleware } from './gnapErrors' +import { OpenAPIValidatorMiddlewareError } from '@interledger/openapi' describe('gnapServerErrorMiddleware', (): void => { let deps: IocContract @@ -31,6 +32,23 @@ describe('gnapServerErrorMiddleware', (): void => { ctx.container = deps }) + test('handles OpenAPIValidatorMiddlewareError', async (): Promise => { + const error = new OpenAPIValidatorMiddlewareError('Validation error', 400) + const next = jest.fn().mockImplementationOnce(() => { + throw error + }) + + const ctxThrowSpy = jest.spyOn(ctx, 'throw') + + await expect(gnapServerErrorMiddleware(ctx, next)).rejects.toMatchObject({ + status: error.status, + message: error.message + }) + + expect(ctxThrowSpy).toHaveBeenCalledWith(error.status, error.message) + expect(next).toHaveBeenCalledTimes(1) + }) + test('handles GNAPServerRouteError error', async (): Promise => { const error = new GNAPServerRouteError( 401,