1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
import { beforeEach, describe, expect, inject, it } from "vitest";
import { createHoarderClient } from "@karakeep/sdk";
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 respond 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 respond 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);
});
});
|