Skip to content

Commit

Permalink
needs to fix one last test๐Ÿ˜Ž
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaPinheiro committed May 8, 2024
1 parent 1498d17 commit a87cfe9
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions test/modules/get_activity/app/get_activity.test.ts
Original file line number Diff line number Diff line change
@@ -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);

Check failure on line 33 in test/modules/get_activity/app/get_activity.test.ts

View workflow job for this annotation

GitHub Actions / build

test/modules/get_activity/app/get_activity.test.ts > Testing Get Activity Presenter > should get activity for admin user

TypeError: Cannot read properties of undefined (reading 'id') โฏ test/modules/get_activity/app/get_activity.test.ts:33:43
});

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");
});
});

0 comments on commit a87cfe9

Please sign in to comment.