Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Dec 20, 2024
1 parent ef993ef commit bfbd32e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/index.test.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { describe, it } from 'node:test';
import type { RequestListener } from 'node:http';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import express, { type Application, type NextFunction, type Request, type Response } from 'express';
import express, { type NextFunction, type Request, type Response } from 'express';
import request from 'supertest';
import { installOpenApiValidator } from '../lib/index.mjs';

interface IWithStatus {
status?: number;
}

function buildServer(install: boolean, env: string): Application {
function buildServer(install: boolean, env: string): RequestListener {
const app = express();
app.set('x-powered-by', false);

if (install) {
app.use(installOpenApiValidator(join(dirname(fileURLToPath(import.meta.url)), 'openapi.yaml'), env));
Expand All @@ -23,13 +25,15 @@ function buildServer(install: boolean, env: string): Application {
});
});

app.get('/auth', (_req, res): unknown => res.status(204).end());
app.get('/auth', (_req, res): void => {
res.status(204).end();
});

app.use((err: unknown, _req: Request, res: Response, _next: NextFunction) =>
res.status((err as IWithStatus).status ?? 500).json(err),
);
app.use((err: unknown, _req: Request, res: Response, _next: NextFunction): void => {
res.status((err as IWithStatus).status ?? 500).json(err);
});

return app;
return app as RequestListener;
}

const keepTSHappy = (): Promise<void> => Promise.resolve();
Expand Down

0 comments on commit bfbd32e

Please sign in to comment.