Merge branch 'frontend' of github.com:imbus64/TTime into frontend
This commit is contained in:
commit
eae252c2a4
1 changed files with 88 additions and 0 deletions
88
frontend/src/API/API.test.ts
Normal file
88
frontend/src/API/API.test.ts
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
import { describe, expect, test } from "@jest/globals";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
import { NewUser, NewWeeklyReport } from "../Types/goTypes";
|
||||||
|
|
||||||
|
describe("API", () => {
|
||||||
|
test("registerUser", async () => {
|
||||||
|
const user: NewUser = {
|
||||||
|
username: "lol", // Add the username property
|
||||||
|
password: "lol",
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await api.registerUser(user);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty("userId");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("createProject", async () => {
|
||||||
|
const project = {
|
||||||
|
name: "Project X",
|
||||||
|
description: "This is a test project",
|
||||||
|
};
|
||||||
|
const token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
||||||
|
|
||||||
|
const response = await api.createProject(project, token);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty("projectId");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renewToken", async () => {
|
||||||
|
const refreshToken =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
||||||
|
|
||||||
|
const response = await api.renewToken(refreshToken);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty("accessToken");
|
||||||
|
expect(response.data).toHaveProperty("refreshToken");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getUserProjects", async () => {
|
||||||
|
const token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
||||||
|
const username = "rrgumdzpmc";
|
||||||
|
const response = await api.getUserProjects(username, token);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty("projects");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("submitWeeklyReport", async () => {
|
||||||
|
const report: NewWeeklyReport = {
|
||||||
|
projectName: "vtmosxssst",
|
||||||
|
week: 2,
|
||||||
|
developmentTime: 40,
|
||||||
|
meetingTime: 5,
|
||||||
|
adminTime: 2,
|
||||||
|
ownWorkTime: 10,
|
||||||
|
studyTime: 12,
|
||||||
|
testingTime: 41,
|
||||||
|
};
|
||||||
|
const token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
||||||
|
|
||||||
|
const response = await api.submitWeeklyReport(report, token);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty(
|
||||||
|
"message",
|
||||||
|
"Report submitted successfully",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("login", async () => {
|
||||||
|
const user: NewUser = {
|
||||||
|
username: "rrgumdzpmc", // Add an empty string value for the username property
|
||||||
|
password: "always_same",
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await api.login(user);
|
||||||
|
|
||||||
|
expect(response.success).toBe(true);
|
||||||
|
expect(response.data).toHaveProperty("accessToken");
|
||||||
|
expect(response.data).toHaveProperty("refreshToken");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue