MCPcopy
hub / github.com/FoalTS/foal / testAsset

Function testAsset

packages/swagger/src/swagger-controller.spec.ts:348–381  ·  view source on GitHub ↗
(
    methodName: 'swaggerUi'|'swaggerUiBundle'|'swaggerUiStandalonePreset',
    filename: string,
    contentType: string
  )

Source from the content-addressed store, hash-verified

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');

Callers 1

Calls 4

getHttpMethodFunction · 0.90
getPathFunction · 0.90
isHttpResponseOKFunction · 0.90
streamToBufferFunction · 0.90

Tested by

no test coverage detected