Skip to content

Commit 663200a

Browse files
committed
Update server close handler
1 parent 8f2af07 commit 663200a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

course-matrix/backend/__tests__/timetablesController.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import request from "supertest";
22
import timetablesController from "../src/controllers/timetablesController";
33
import { Request, Response, NextFunction } from "express";
4-
import { jest, describe, test, expect, beforeEach, it } from "@jest/globals";
4+
import {
5+
jest,
6+
describe,
7+
test,
8+
expect,
9+
beforeEach,
10+
afterAll,
11+
} from "@jest/globals";
512
import { authHandler } from "../src/middleware/authHandler";
13+
import { supabase } from "../src/db/setupDb";
614
import { Json } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch/db_control";
715
import app from "../src/index";
16+
import { server } from "../src/index";
817

918
//Handle AI import from index.ts
1019
jest.mock("@ai-sdk/openai", () => ({
@@ -29,6 +38,10 @@ jest.mock("@pinecone-database/pinecone", () => ({
2938
})),
3039
}));
3140

41+
afterAll(async () => {
42+
server.close();
43+
});
44+
3245
// Function to create authenticated session dynamically based as provided user_id
3346
const mockAuthHandler = (user_id: string) => {
3447
return (req: Request, res: Response, next: NextFunction) => {

course-matrix/backend/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ app.get(
4949
asyncHandler(async (_, response) =>
5050
response.json({
5151
info: "Testing course matrix backend server",
52-
}),
53-
),
52+
})
53+
)
5454
);
5555

5656
/**
@@ -67,7 +67,7 @@ app.get(
6767
} catch (err) {
6868
return res.status(500).send({ err });
6969
}
70-
}),
70+
})
7171
);
7272

7373
server = app.listen(config.PORT, () => {
@@ -94,4 +94,5 @@ const unexpectedErrorHandler = (error: unknown) => {
9494
process.on("uncaughtException", unexpectedErrorHandler);
9595
process.on("unhandledRejection", unexpectedErrorHandler);
9696

97+
export { server };
9798
export default app;

0 commit comments

Comments
 (0)