Skip to content

Commit

Permalink
chore(): minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 11, 2022
2 parents 7bf6e99 + 5652905 commit fabdf6f
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 58 deletions.
35 changes: 32 additions & 3 deletions e2e/express.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NestFactory } from '@nestjs/core';
import * as SwaggerParser from 'swagger-parser';
import { DocumentBuilder, SwaggerModule } from '../lib';
import { ApplicationModule } from './src/app.module';
import {
ExpressAdapter,
NestExpressApplication
} from '@nestjs/platform-express';
import * as request from 'supertest';
import * as SwaggerParser from 'swagger-parser';
import { DocumentBuilder, SwaggerModule } from '../lib';
import { ApplicationModule } from './src/app.module';

describe('Express Swagger', () => {
let app: NestExpressApplication;
Expand Down Expand Up @@ -66,5 +67,33 @@ describe('Express Swagger', () => {

await app.init();
expect(app.getHttpAdapter().getInstance()).toBeDefined();
await app.close();
});

describe('served swagger ui', () => {
const SWAGGER_RELATIVE_URL = '/apidoc';

beforeEach(async () => {
const swaggerDocument = SwaggerModule.createDocument(
app,
builder.build()
);
SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument);

await app.init();
});

afterEach(async () => {
await app.close();
});

it('content type of served json document should be valid', async () => {
const response = await request(app.getHttpServer()).get(
`${SWAGGER_RELATIVE_URL}-json`
);

expect(response.status).toEqual(200);
expect(Object.keys(response.body).length).toBeGreaterThan(0);
});
});
});
29 changes: 29 additions & 0 deletions e2e/fastify.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FastifyAdapter,
NestFastifyApplication
} from '@nestjs/platform-fastify';
import * as request from 'supertest';
import * as SwaggerParser from 'swagger-parser';
import { DocumentBuilder, SwaggerModule } from '../lib';
import { ApplicationModule } from './src/app.module';
Expand Down Expand Up @@ -70,4 +71,32 @@ describe('Fastify Swagger', () => {
app.getHttpAdapter().getInstance().ready()
).resolves.toBeDefined();
});

describe('served swagger ui', () => {
const SWAGGER_RELATIVE_URL = '/apidoc';

beforeEach(async () => {
const swaggerDocument = SwaggerModule.createDocument(
app,
builder.build()
);
SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument);

await app.init();
await app.getHttpAdapter().getInstance().ready();
});

afterEach(async () => {
await app.close();
});

it('content type of served json document should be valid', async () => {
const response = await request(app.getHttpServer()).get(
`${SWAGGER_RELATIVE_URL}-json`
);

expect(response.status).toEqual(200);
expect(Object.keys(response.body).length).toBeGreaterThan(0);
});
});
});
2 changes: 1 addition & 1 deletion lib/swagger-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SwaggerModule {
});

httpAdapter.get(`${finalPath}-json`, (req, res) => {
res.type('text/json');
res.type('application/json');
res.send(jsonDocument);
});

Expand Down
166 changes: 112 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"prettier": "2.7.1",
"reflect-metadata": "0.1.13",
"release-it": "15.1.1",
"supertest": "^6.2.4",
"swagger-parser": "10.0.3",
"ts-jest": "28.0.5",
"typescript": "4.7.4"
Expand Down

0 comments on commit fabdf6f

Please sign in to comment.