Skip to content

Commit

Permalink
Adding get tests for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhish-nayak committed Apr 23, 2024
1 parent 2285983 commit 6e403a3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions server/src/__tests__/integration/controllers/comment/get.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
48 changes: 48 additions & 0 deletions server/src/__tests__/integration/controllers/friend/get.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 6e403a3

Please sign in to comment.