From 6e403a3bfd514461fa9ede11dd928b813ae9c429 Mon Sep 17 00:00:00 2001 From: nidhish-nayak Date: Tue, 23 Apr 2024 23:41:55 +0530 Subject: [PATCH] Adding get tests for comments --- .../controllers/comment/get.test.ts | 30 ++++++++++++ .../controllers/friend/get.test.ts | 48 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 server/src/__tests__/integration/controllers/comment/get.test.ts create mode 100644 server/src/__tests__/integration/controllers/friend/get.test.ts diff --git a/server/src/__tests__/integration/controllers/comment/get.test.ts b/server/src/__tests__/integration/controllers/comment/get.test.ts new file mode 100644 index 0000000..c2c5d65 --- /dev/null +++ b/server/src/__tests__/integration/controllers/comment/get.test.ts @@ -0,0 +1,30 @@ +import { createApp } from "../../utils/setup.util"; +import authRoutes from "../../../../routes/auth.route"; +import commentRoutes from "../../../../routes/comment.route"; + +import { existingUserLogin } from "../../utils/auth.util"; +import { customGet } from "../../utils/custom.util"; + +const app = createApp(); + +// Global variables +let user_id: number; +let token: string; + +describe("Comments controller GET tests", () => { + beforeAll(async () => { + app.use("/api/auth", authRoutes); + app.use("/api/comments", commentRoutes); + + const login = await existingUserLogin(app); + if (login.status !== 200) throw new Error("Failed existingUser login!"); + user_id = login.userId; + token = login.token; + }); + + it("responds 200 for GET /api/comments/", async () => { + const endpoint = "/api/comments/count?postId=1"; + const res = await customGet(app, endpoint, token); + expect(res.status).toBe(200); + }); +}); diff --git a/server/src/__tests__/integration/controllers/friend/get.test.ts b/server/src/__tests__/integration/controllers/friend/get.test.ts new file mode 100644 index 0000000..9b0139b --- /dev/null +++ b/server/src/__tests__/integration/controllers/friend/get.test.ts @@ -0,0 +1,48 @@ +import { createApp } from "../../utils/setup.util"; +import authRoutes from "../../../../routes/auth.route"; +import friendRoutes from "../../../../routes/friend.route"; + +import { existingUserLogin } from "../../utils/auth.util"; +import { customGet } from "../../utils/custom.util"; + +const app = createApp(); + +// Global variables +let user_id: number; +let token: string; + +describe("Friends controller GET tests", () => { + beforeAll(async () => { + app.use("/api/auth", authRoutes); + app.use("/api/friends", friendRoutes); + + const login = await existingUserLogin(app); + if (login.status !== 200) throw new Error("Failed existingUser login!"); + user_id = login.userId; + token = login.token; + }); + + it("responds 200 for GET /api/friends/", async () => { + const endpoint = "/api/friends/"; + const res = await customGet(app, endpoint, token); + expect(res.status).toBe(200); + }); + + it("responds 200 for GET /api/friends/followers", async () => { + const endpoint = "/api/friends/followers"; + const res = await customGet(app, endpoint, token); + expect(res.status).toBe(200); + }); + + it("responds 200 for GET /api/friends/following", async () => { + const endpoint = "/api/friends/following"; + const res = await customGet(app, endpoint, token); + expect(res.status).toBe(200); + }); + + it("responds 200 for GET /api/friends/findPeople", async () => { + const endpoint = "/api/friends/findPeople"; + const res = await customGet(app, endpoint, token); + expect(res.status).toBe(200); + }); +});