-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1498d17
commit a87cfe9
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / buildtest/modules/get_activity/app/get_activity.test.ts > Testing Get Activity Presenter > should get activity for admin user
|
||
}); | ||
|
||
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"); | ||
}); | ||
}); |