diff --git a/src/modules/users/user.routes.ts b/src/modules/users/user.routes.ts index 4a72ea5..0974537 100644 --- a/src/modules/users/user.routes.ts +++ b/src/modules/users/user.routes.ts @@ -104,6 +104,8 @@ export async function userRoutes(app: FastifyInstance): Promise { } as FastifySchema, }, (request, reply) => userController.getLearningPath(request, reply) + ); + app.get<{ Querystring: import("../notifications/notification.types.js").ListNotificationsQuery }>( "/me/notifications", { diff --git a/tests/e2e/users.test.ts b/tests/e2e/users.test.ts index 71538c8..5cbc754 100644 --- a/tests/e2e/users.test.ts +++ b/tests/e2e/users.test.ts @@ -171,6 +171,44 @@ describe("Users API", () => { }); }); + describe("GET /api/v1/users/me/learning-path", () => { + it("should reject unauthenticated requests", async () => { + const response = await app.inject({ + method: "GET", + url: "/api/v1/users/me/learning-path", + }); + + expect(response.statusCode).toBe(401); + }); + + it("should return an array of course recommendations for an authenticated user", async () => { + const token = createToken(); + + const response = await app.inject({ + method: "GET", + url: "/api/v1/users/me/learning-path", + headers: { authorization: `Bearer ${token}` }, + }); + + // May return 200 (success), 401 (auth rejected), or 404 (user not + // seeded in this environment's DB) -- mirrors the tolerance the other + // /me/* tests in this file use, since these e2e tests run against + // whatever DB state happens to be present. + expect([200, 401, 404]).toContain(response.statusCode); + if (response.statusCode === 200) { + const body = JSON.parse(response.payload); + expect(body.success).toBe(true); + expect(Array.isArray(body.data)).toBe(true); + for (const recommendation of body.data) { + expect(typeof recommendation.courseId).toBe("string"); + expect(typeof recommendation.courseTitle).toBe("string"); + expect(typeof recommendation.difficulty).toBe("string"); + expect(typeof recommendation.rationale).toBe("string"); + } + } + }); + }); + describe("GET /api/v1/users/me/activity", () => { it("should reject unauthenticated requests", async () => { const response = await app.inject({