Skip to content

Commit

Permalink
test(tutories): add tutories integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Nov 23, 2024
1 parent 1a0b186 commit 8041c91
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { seedTutors } from "@/module/tutor/tutor.seeder";
export default async function setup() {
await seedSubjects();
// await seedLearners();
// await seedTutors();
// await seedServices({ randomTeachingMethodology: true });
await seedTutors();
await seedTutories({ randomTeachingMethodology: true });
}
65 changes: 65 additions & 0 deletions tests/integration/tutories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { app } from "@/main";
import supertest from "supertest";
import { describe, expect, test } from "vitest";
import { container } from "@/container";
import { generateUser } from "@tests/helpers/generate.helper";

const tutoriesRepository = container.tutoriesRepository;

async function registerAndLoginLearner() {
const newLearner = generateUser("learner");

const res = await supertest(app)
.post("/api/v1/auth/register")
.send(newLearner)
.expect(201);

const userId = res.body.data.userId;
expect(userId).toBeDefined();

const loginRes = await supertest(app)
.post("/api/v1/auth/login")
.send({ email: newLearner.email, password: newLearner.password })
.expect(200);

const token = loginRes.body.data.token;
expect(token).toBeDefined();

return { learner: newLearner, token };
}

describe("Get tutories", async () => {
test("Get all tutories without token", async () => {
await supertest(app).get("/api/v1/tutors/services").expect(401);
});

test("Get all tutories with token", async () => {
const { token } = await registerAndLoginLearner();
await supertest(app)
.get("/api/v1/tutors/services")
.set("Authorization", `Bearer ${token}`)
.expect(200);
});
});

describe("Get tutories availability", async () => {
const tutories = await tutoriesRepository.getTutories();
const tutoriesId = tutories[0].id;

const { token } = await registerAndLoginLearner();

test("Get tutories availability without token", async () => {
await supertest(app)
.get(`/api/v1/tutors/services/${tutoriesId}/availability`)
.expect(401);
});

test("Get tutories availability with token", async () => {
const res = await supertest(app)
.get(`/api/v1/tutors/services/${tutoriesId}/availability`)
.set("Authorization", `Bearer ${token}`)
.expect(200);

expect(res.body.data).toBeTruthy();
});
});

0 comments on commit 8041c91

Please sign in to comment.