(
methodName: 'swaggerUi'|'swaggerUiBundle'|'swaggerUiStandalonePreset',
filename: string,
contentType: string
)
| 346 | }); |
| 347 | |
| 348 | function testAsset( |
| 349 | methodName: 'swaggerUi'|'swaggerUiBundle'|'swaggerUiStandalonePreset', |
| 350 | filename: string, |
| 351 | contentType: string |
| 352 | ): void { |
| 353 | describe(`has a "${methodName}" method that`, () => { |
| 354 | |
| 355 | it(`should handle requests at GET /${filename}.`, () => { |
| 356 | strictEqual(getHttpMethod(ConcreteClass, methodName), 'GET'); |
| 357 | strictEqual(getPath(ConcreteClass, methodName), `/${filename}`); |
| 358 | }); |
| 359 | |
| 360 | it(`should return an HttpResponseOK whose content is the ${filename} asset.`, async () => { |
| 361 | const controller = new ConcreteClass(); |
| 362 | const response = await controller[methodName](); |
| 363 | |
| 364 | if (!isHttpResponseOK(response)) { |
| 365 | throw new Error(`SwaggerController.${methodName} should return an HttpResponseOK instance.`); |
| 366 | } |
| 367 | |
| 368 | strictEqual(response.getHeader('Content-Type'), contentType); |
| 369 | strictEqual(response.stream, true); |
| 370 | |
| 371 | const filePath = `../../node_modules/swagger-ui-dist/${filename}`; |
| 372 | const stats = await stat(filePath); |
| 373 | strictEqual(response.getHeader('Content-Length'), stats.size.toString()); |
| 374 | |
| 375 | const content = await streamToBuffer(response.body); |
| 376 | const expected = readFileSync(filePath); |
| 377 | ok(expected.equals(content)); |
| 378 | }); |
| 379 | |
| 380 | }); |
| 381 | } |
| 382 | |
| 383 | testAsset('swaggerUi', 'swagger-ui.css', 'text/css'); |
| 384 | testAsset('swaggerUiBundle', 'swagger-ui-bundle.js', 'application/javascript'); |
no test coverage detected