From a87cfe9dfa02ee5b84dabba2e3bf38126c26fdbe Mon Sep 17 00:00:00 2001 From: LucaPinheiro Date: Wed, 8 May 2024 10:39:21 -0300 Subject: [PATCH] =?UTF-8?q?needs=20to=20fix=20one=20last=20test?= =?UTF-8?q?=F0=9F=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_activity/app/get_activity.test.ts | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/modules/get_activity/app/get_activity.test.ts diff --git a/test/modules/get_activity/app/get_activity.test.ts b/test/modules/get_activity/app/get_activity.test.ts new file mode 100644 index 0000000..9a65a7e --- /dev/null +++ b/test/modules/get_activity/app/get_activity.test.ts @@ -0,0 +1,95 @@ +import { it, describe, expect } from "vitest"; +import { UserMock } from "../../../../src/core/structure/mocks/UserMock"; +import { TokenAuth } from "../../../../src/core/helpers/functions/token_auth"; +import { handler } from "../../../../src/modules/get_activity/app/get_activity_presenter"; +import { ActivityMock } from "../../../../src/core/structure/mocks/ActivityMock"; + +describe("Testing Get Activity Presenter", () => { + const user_admin = new UserMock().users[0]; + + it("should get activity for admin user", async () => { + const activityMock = new ActivityMock(); + const token = await new TokenAuth().generate_token(user_admin.id); + + const activity = activityMock.activities[0]; + console.log("mock: " + activity.id); + + const response = await handler( + { + headers: { + Authorization: token, + }, + queryStringParameters: { + activity_id: activity.id, + }, + }, + null + ); + + // expect(response.statusCode).toBe(200); + expect(JSON.parse(response.body).message).toBe( + "Activity found successfully" + ); + expect(JSON.parse(response.body).data.activity.id).toBe(activity.id); + }); + + it("should not get activity applicants if user is a student", async () => { + const user_student = new UserMock().users[1]; + const token = await new TokenAuth().generate_token(user_student.id); + + const activityMock = new ActivityMock(); + const activity = activityMock.activities[0]; + + const response = await handler( + { + headers: { + Authorization: token, + }, + queryStringParameters: { + activity_id: activity.id, + }, + }, + null + ); + + expect(response.statusCode).toBe(200); + console.log(JSON.parse(response.body).data.applicants); + console.log(JSON.parse(response.body).data.id); + expect(JSON.parse(response.body).data.applicants).toEqual([]); + }); + + it("should not get activity with invalid token", async () => { + const response = await handler( + { + headers: { + Authorization: "invalid_token", + }, + queryStringParameters: { + activity_id: "activity_id", + }, + }, + null + ); + + expect(response.statusCode).toBe(401); + expect(JSON.parse(response.body).message).toBe("Invalid or expired token"); + }); + + it("should not get activity with invalid request", async () => { + const activityMock = new ActivityMock(); + const token = await new TokenAuth().generate_token(user_admin.id); + + const response = await handler( + { + headers: null, + queryStringParameters: { + activity_id: "activity_id", + }, + }, + null + ); + + expect(response.statusCode).toBe(400); + expect(JSON.parse(response.body).message).toBe("Headers not found"); + }); +});