Skip to content

Commit

Permalink
feat: test openapi validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed May 21, 2024
1 parent c67c3b5 commit b7d2663
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/auth/src/shared/gnapErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GNAPServerRouteError,
gnapServerErrorMiddleware
} from './gnapErrors'
import { OpenAPIValidatorMiddlewareError } from '@interledger/openapi'

describe('gnapServerErrorMiddleware', (): void => {
let deps: IocContract<AppServices>
Expand All @@ -31,6 +32,23 @@ describe('gnapServerErrorMiddleware', (): void => {
ctx.container = deps
})

test('handles OpenAPIValidatorMiddlewareError', async (): Promise<void> => {
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<void> => {
const error = new GNAPServerRouteError(
401,
Expand Down

0 comments on commit b7d2663

Please sign in to comment.