diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-03-11 20:09:32 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-03-11 20:09:32 +0000 |
| commit | b8c587e3c3e717263da84522d59c7904715ae22a (patch) | |
| tree | a26a67162118b4a629d33a833dd25be67d344855 /packages/e2e_tests/tests/api/users.test.ts | |
| parent | 59c444a503c0124988608c190342acc53c797107 (diff) | |
| download | karakeep-b8c587e3c3e717263da84522d59c7904715ae22a.tar.zst | |
feat: Add endpoints for whoami and user stats. Fixes #1113
Diffstat (limited to 'packages/e2e_tests/tests/api/users.test.ts')
| -rw-r--r-- | packages/e2e_tests/tests/api/users.test.ts | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/packages/e2e_tests/tests/api/users.test.ts b/packages/e2e_tests/tests/api/users.test.ts new file mode 100644 index 00000000..36c0868d --- /dev/null +++ b/packages/e2e_tests/tests/api/users.test.ts @@ -0,0 +1,102 @@ +import { createHoarderClient } from "@hoarderapp/sdk"; +import { beforeEach, describe, expect, inject, it } from "vitest"; + +import { createTestUser } from "../../utils/api"; + +describe("Users API", () => { + const port = inject("hoarderPort"); + + if (!port) { + throw new Error("Missing required environment variables"); + } + + let client: ReturnType<typeof createHoarderClient>; + let apiKey: string; + + beforeEach(async () => { + apiKey = await createTestUser(); + client = createHoarderClient({ + baseUrl: `http://localhost:${port}/api/v1/`, + headers: { + "Content-Type": "application/json", + authorization: `Bearer ${apiKey}`, + }, + }); + }); + + it("should response with user info", async () => { + // Get the user info + const { data: userInfo } = await client.GET("/users/me"); + expect(userInfo).toBeDefined(); + expect(userInfo?.name).toEqual("Test User"); + }); + + it("should response with user stats", async () => { + //////////////////////////////////////////////////////////////////////////////////// + // Prepare some data + //////////////////////////////////////////////////////////////////////////////////// + const { data: createdBookmark1 } = await client.POST("/bookmarks", { + body: { + type: "text", + text: "This is a test bookmark", + favourited: true, + }, + }); + await client.POST("/bookmarks", { + body: { + type: "text", + text: "This is a test bookmark", + archived: true, + }, + }); + // Create a highlight + await client.POST("/highlights", { + body: { + bookmarkId: createdBookmark1!.id, + startOffset: 0, + endOffset: 5, + text: "This is a test highlight", + note: "Test note", + color: "yellow", + }, + }); + // attach a tag + await client.POST("/bookmarks/{bookmarkId}/tags", { + params: { + path: { + bookmarkId: createdBookmark1!.id, + }, + }, + body: { + tags: [{ tagName: "test-tag" }], + }, + }); + // create two list + await client.POST("/lists", { + body: { + name: "Test List", + icon: "s", + }, + }); + await client.POST("/lists", { + body: { + name: "Test List 2", + icon: "s", + }, + }); + + //////////////////////////////////////////////////////////////////////////////////// + // The actual test + //////////////////////////////////////////////////////////////////////////////////// + + const { data: userStats } = await client.GET("/users/me/stats"); + + expect(userStats).toBeDefined(); + expect(userStats?.numBookmarks).toBe(2); + expect(userStats?.numFavorites).toBe(1); + expect(userStats?.numArchived).toBe(1); + expect(userStats?.numTags).toBe(1); + expect(userStats?.numLists).toBe(2); + expect(userStats?.numHighlights).toBe(1); + }); +}); |
