Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed Feb 27, 2024
1 parent 4bc4f82 commit fa57151
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
4 changes: 3 additions & 1 deletion packages/cli/src/commands/validate/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe('validate', () => {
.setCwd(path.resolve('./'))
.invoke(['validate', './packages/cli/src/commands/validate/invalid.json'])

logs.should.contain('Cannot find supported swagger/openapi version')
logs.should.contain(
'Cannot find supported Swagger/OpenAPI version in specification, version must be a string.',
)
logs.should.not.contain('OpenAPI 3.1')
expect(exitCode).toBe(1)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createMockServer } from './createMockServer'
describe('onRequest', () => {
it('call custom onRequest hook', async () => {
return new Promise(async (resolve) => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -21,7 +21,7 @@ describe('onRequest', () => {
}

const server = await createMockServer({
openapi,
specification,
onRequest({ context, operation }) {
expect(context.req.method).toBe('GET')
expect(context.req.path).toBe('/foobar')
Expand Down
36 changes: 18 additions & 18 deletions packages/mock-server/src/lib/createMockServer.openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createMockServer } from './createMockServer'

describe('openapi.{json|yaml}', () => {
it('GET /openapi.json (object)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -14,17 +14,17 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.json')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})

it('GET /openapi.json (JSON string)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -34,17 +34,17 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.json')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})

it.skip('GET /openapi.json (YAML string)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -54,17 +54,17 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.json')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})

it.skip('GET /openapi.yaml (object)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -74,17 +74,17 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.yaml')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})

it.skip('GET /openapi.yaml (YAML string)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -94,17 +94,17 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.yaml')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})

it.skip('GET /openapi.yaml (JSON string)', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -114,12 +114,12 @@ describe('openapi.{json|yaml}', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/openapi.yaml')

expect(response.status).toBe(200)
expect(await response.json()).toMatchObject(openapi)
expect(await response.json()).toMatchObject(specification)
})
})
20 changes: 10 additions & 10 deletions packages/mock-server/src/lib/createMockServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createMockServer } from './createMockServer'

describe('createMockServer', () => {
it('GET /foobar -> example JSON', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -31,7 +31,7 @@ describe('createMockServer', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/foobar')
Expand All @@ -43,7 +43,7 @@ describe('createMockServer', () => {
})

it('POST /foobar -> example JSON', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -70,7 +70,7 @@ describe('createMockServer', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/foobar', {
Expand All @@ -84,7 +84,7 @@ describe('createMockServer', () => {
})

it('POST /foobar/{id} -> example JSON', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand All @@ -111,7 +111,7 @@ describe('createMockServer', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/foobar/123')
Expand All @@ -123,7 +123,7 @@ describe('createMockServer', () => {
})

it('GET /foobar -> example from schema', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('createMockServer', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/foobar')
Expand All @@ -168,7 +168,7 @@ describe('createMockServer', () => {
})

it('GET /foobar/{id} -> example from schema', async () => {
const openapi = {
const specification = {
openapi: '3.1.0',
info: {
title: 'Hello World',
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('createMockServer', () => {
}

const server = await createMockServer({
openapi,
specification,
})

const response = await server.request('/foobar/123')
Expand Down

0 comments on commit fa57151

Please sign in to comment.