@tscircuit/fake-snippets 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +2 -5
  2. package/bun-tests/fake-snippets-api/routes/packages/{list.test.ts → list-1.test.ts} +0 -55
  3. package/bun-tests/fake-snippets-api/routes/packages/list-2.test.ts +59 -0
  4. package/bun-tests/fake-snippets-api/routes/snippets/add_star.test.ts +32 -27
  5. package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +34 -1
  6. package/bun-tests/fake-snippets-api/routes/snippets/get.test.ts +114 -0
  7. package/bun-tests/fake-snippets-api/routes/snippets/get_image.test.ts +10 -6
  8. package/bun-tests/fake-snippets-api/routes/snippets/images.test.ts +8 -6
  9. package/bun-tests/fake-snippets-api/routes/snippets/list_newest.test.ts +2 -2
  10. package/bun-tests/fake-snippets-api/routes/snippets/list_trending.test.ts +10 -10
  11. package/bun-tests/fake-snippets-api/routes/snippets/remove_star.test.ts +8 -6
  12. package/bun-tests/fake-snippets-api/routes/snippets/search.test.ts +1 -1
  13. package/bun-tests/fake-snippets-api/routes/snippets/star-count.test.ts +19 -12
  14. package/bun-tests/fake-snippets-api/routes/snippets/update.test.ts +57 -16
  15. package/bun.lock +148 -569
  16. package/dist/bundle.js +844 -194
  17. package/fake-snippets-api/lib/db/db-client.ts +761 -147
  18. package/fake-snippets-api/lib/db/schema.ts +27 -6
  19. package/fake-snippets-api/lib/public-mapping/public-map-package.ts +8 -0
  20. package/fake-snippets-api/routes/api/packages/list.ts +4 -1
  21. package/fake-snippets-api/routes/api/snippets/add_star.ts +30 -8
  22. package/fake-snippets-api/routes/api/snippets/create.ts +123 -29
  23. package/fake-snippets-api/routes/api/snippets/delete.ts +5 -5
  24. package/fake-snippets-api/routes/api/snippets/download.ts +24 -10
  25. package/fake-snippets-api/routes/api/snippets/get.ts +46 -13
  26. package/fake-snippets-api/routes/api/snippets/list.ts +37 -2
  27. package/fake-snippets-api/routes/api/snippets/update.ts +36 -14
  28. package/package.json +4 -5
  29. package/src/components/CodeAndPreview.tsx +13 -48
  30. package/src/components/CodeEditor.tsx +10 -7
  31. package/src/components/EditorNav.tsx +0 -21
  32. package/src/components/PreviewContent.tsx +2 -2
  33. package/src/components/ViewSnippetHeader.tsx +4 -0
  34. package/src/hooks/use-global-store.ts +0 -5
  35. package/src/hooks/use-package-as-snippet.ts +78 -0
  36. package/src/hooks/use-run-tsx/index.tsx +4 -0
  37. package/src/lib/jlc-parts-engine.ts +4 -2
@@ -1,10 +1,8 @@
1
1
  import { afterEach } from "bun:test"
2
- import { tmpdir } from "node:os"
3
2
  import defaultAxios from "redaxios"
4
3
  import { startServer } from "./start-server"
5
4
  import { DbClient } from "fake-snippets-api/lib/db/db-client"
6
-
7
- let testNumber = 1
5
+ import getPort from "get-port"
8
6
 
9
7
  interface TestFixture {
10
8
  url: string
@@ -15,7 +13,7 @@ interface TestFixture {
15
13
  }
16
14
 
17
15
  export const getTestServer = async (): Promise<TestFixture> => {
18
- const port = 3000 + testNumber++
16
+ const port = await getPort()
19
17
  const testInstanceId = Math.random().toString(36).substring(2, 15)
20
18
  const testDbName = `testdb${testInstanceId}`
21
19
 
@@ -37,7 +35,6 @@ export const getTestServer = async (): Promise<TestFixture> => {
37
35
  if (server && typeof server.stop === "function") {
38
36
  await server.stop()
39
37
  }
40
- // Here you might want to add logic to drop the test database
41
38
  })
42
39
 
43
40
  return {
@@ -110,58 +110,3 @@ test("list packages", async () => {
110
110
  })
111
111
  expect(authData.packages).toHaveLength(3) // Should return all packages when authenticated
112
112
  })
113
-
114
- test("list packages with is_writable filter", async () => {
115
- const { axios, db } = await getTestServer()
116
-
117
- // Add test packages
118
- const packages = [
119
- {
120
- package_id: "pkg1",
121
- name: "Package1",
122
- unscoped_name: "Package1",
123
- owner_github_username: "testuser", // Matches auth context github_username
124
- creator_account_id: "account-1234", // Matches auth context account_id
125
- created_at: "2023-01-01T00:00:00Z",
126
- updated_at: "2023-01-01T00:00:00Z",
127
- description: "Description 1",
128
- ai_description: "AI Description 1",
129
- owner_org_id: "org-1234", // Matches auth context personal_org_id
130
- latest_version: "1.0.0",
131
- license: "MIT",
132
- is_source_from_github: true,
133
- star_count: 0,
134
- },
135
- {
136
- package_id: "pkg2",
137
- name: "Package2",
138
- unscoped_name: "Package2",
139
- owner_github_username: "user2",
140
- creator_account_id: "creator2",
141
- created_at: "2023-01-02T00:00:00Z",
142
- updated_at: "2023-01-02T00:00:00Z",
143
- description: "Description 2",
144
- ai_description: "AI Description 2",
145
- owner_org_id: "other-org",
146
- latest_version: "1.0.0",
147
- license: "MIT",
148
- is_source_from_github: true,
149
- star_count: 0,
150
- },
151
- ]
152
-
153
- // Add only these test packages
154
- for (const pkg of packages) {
155
- db.addPackage(pkg as any)
156
- }
157
-
158
- // Test with is_writable filter (requires auth)
159
- const { data: writableData } = await axios.get("/api/packages/list", {
160
- params: { is_writable: true },
161
- headers: {
162
- Authorization: "Bearer 1234",
163
- },
164
- })
165
- expect(writableData.packages).toHaveLength(1)
166
- expect(writableData.packages[0].owner_org_id).toBe("org-1234")
167
- })
@@ -0,0 +1,59 @@
1
+ import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
+ import { expect, test } from "bun:test"
3
+ test("list packages with is_writable filter", async () => {
4
+ const { axios, db } = await getTestServer()
5
+
6
+ // Log the initial state of packages in the database
7
+ console.log("LIST-2 TEST - Initial packages in DB:", db.packages)
8
+
9
+ // Add test packages
10
+ const packages = [
11
+ {
12
+ package_id: "pkg1",
13
+ name: "Package1",
14
+ unscoped_name: "Package1",
15
+ owner_github_username: "testuser", // Matches auth context github_username
16
+ creator_account_id: "account-1234", // Matches auth context account_id
17
+ created_at: "2023-01-01T00:00:00Z",
18
+ updated_at: "2023-01-01T00:00:00Z",
19
+ description: "Description 1",
20
+ ai_description: "AI Description 1",
21
+ owner_org_id: "org-1234", // Matches auth context personal_org_id
22
+ latest_version: "1.0.0",
23
+ license: "MIT",
24
+ is_source_from_github: true,
25
+ star_count: 0,
26
+ },
27
+ {
28
+ package_id: "pkg2",
29
+ name: "Package2",
30
+ unscoped_name: "Package2",
31
+ owner_github_username: "user2",
32
+ creator_account_id: "creator2",
33
+ created_at: "2023-01-02T00:00:00Z",
34
+ updated_at: "2023-01-02T00:00:00Z",
35
+ description: "Description 2",
36
+ ai_description: "AI Description 2",
37
+ owner_org_id: "other-org",
38
+ latest_version: "1.0.0",
39
+ license: "MIT",
40
+ is_source_from_github: true,
41
+ star_count: 0,
42
+ },
43
+ ]
44
+
45
+ // Add only these test packages
46
+ for (const pkg of packages) {
47
+ db.addPackage(pkg as any)
48
+ }
49
+
50
+ // Test with is_writable filter (requires auth)
51
+ const { data: writableData } = await axios.get("/api/packages/list", {
52
+ params: { is_writable: true },
53
+ headers: {
54
+ Authorization: "Bearer 1234",
55
+ },
56
+ })
57
+ expect(writableData.packages).toHaveLength(1)
58
+ expect(writableData.packages[0].owner_org_id).toBe("org-1234")
59
+ })
@@ -1,27 +1,27 @@
1
1
  import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
- import { test, expect } from "bun:test"
2
+ import { expect, test } from "bun:test"
3
3
 
4
4
  test("add star to snippet", async () => {
5
- const { axios, db } = await getTestServer()
5
+ const { axios } = await getTestServer()
6
6
 
7
- // Add a test snippet
8
- const snippet = {
9
- unscoped_name: "TestSnippet",
10
- owner_name: "otheruser",
7
+ // Create a test snippet using the create endpoint
8
+ const newSnippetData = {
11
9
  code: "Test Content",
12
- created_at: "2023-01-01T00:00:00Z",
13
- updated_at: "2023-01-01T00:00:00Z",
14
- name: "otheruser/TestSnippet",
15
10
  snippet_type: "package",
16
11
  description: "Test Description",
17
12
  }
18
- const addedSnippet = db.addSnippet(snippet as any)!
13
+ const createResponse = await axios.post(
14
+ "/api/snippets/create",
15
+ newSnippetData,
16
+ )
17
+ expect(createResponse.status).toBe(200)
18
+ const createdSnippet = createResponse.data.snippet
19
19
 
20
20
  // Star the snippet
21
21
  const response = await axios.post(
22
22
  "/api/snippets/add_star",
23
23
  {
24
- snippet_id: addedSnippet.snippet_id,
24
+ snippet_id: createdSnippet.snippet_id,
25
25
  },
26
26
  {
27
27
  headers: {
@@ -32,12 +32,17 @@ test("add star to snippet", async () => {
32
32
 
33
33
  expect(response.status).toBe(200)
34
34
  expect(response.data.ok).toBe(true)
35
- expect(response.data.account_snippet).toBeDefined()
36
- expect(response.data.account_snippet.snippet_id).toBe(addedSnippet.snippet_id)
37
- expect(response.data.account_snippet.has_starred).toBe(true)
38
35
 
39
- // Verify star was added in database
40
- expect(db.hasStarred("account-1234", addedSnippet.snippet_id)).toBe(true)
36
+ // Verify star was added by checking the snippet again
37
+ const getResponse = await axios.get("/api/snippets/get", {
38
+ params: { snippet_id: createdSnippet.snippet_id },
39
+ headers: {
40
+ Authorization: "Bearer 1234",
41
+ },
42
+ })
43
+
44
+ expect(getResponse.status).toBe(200)
45
+ expect(getResponse.data.snippet.is_starred).toBe(true)
41
46
  })
42
47
 
43
48
  test("add star to non-existent snippet", async () => {
@@ -63,26 +68,26 @@ test("add star to non-existent snippet", async () => {
63
68
  })
64
69
 
65
70
  test("add star to already starred snippet", async () => {
66
- const { axios, db } = await getTestServer()
71
+ const { axios } = await getTestServer()
67
72
 
68
- // Add a test snippet
69
- const snippet = {
70
- unscoped_name: "TestSnippet",
71
- owner_name: "otheruser",
73
+ // Create a test snippet using the create endpoint
74
+ const newSnippetData = {
72
75
  code: "Test Content",
73
- created_at: "2023-01-01T00:00:00Z",
74
- updated_at: "2023-01-01T00:00:00Z",
75
- name: "otheruser/TestSnippet",
76
76
  snippet_type: "package",
77
77
  description: "Test Description",
78
78
  }
79
- const addedSnippet = db.addSnippet(snippet as any)
79
+ const createResponse = await axios.post(
80
+ "/api/snippets/create",
81
+ newSnippetData,
82
+ )
83
+ expect(createResponse.status).toBe(200)
84
+ const createdSnippet = createResponse.data.snippet
80
85
 
81
86
  // Star the snippet first time
82
87
  await axios.post(
83
88
  "/api/snippets/add_star",
84
89
  {
85
- snippet_id: addedSnippet.snippet_id,
90
+ snippet_id: createdSnippet.snippet_id,
86
91
  },
87
92
  {
88
93
  headers: {
@@ -96,7 +101,7 @@ test("add star to already starred snippet", async () => {
96
101
  await axios.post(
97
102
  "/api/snippets/add_star",
98
103
  {
99
- snippet_id: addedSnippet.snippet_id,
104
+ snippet_id: createdSnippet.snippet_id,
100
105
  },
101
106
  {
102
107
  headers: {
@@ -1,5 +1,5 @@
1
1
  import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
- import { test, expect } from "bun:test"
2
+ import { expect, test } from "bun:test"
3
3
 
4
4
  test("create snippet", async () => {
5
5
  const { axios } = await getTestServer()
@@ -26,3 +26,36 @@ test("create snippet", async () => {
26
26
  expect(response.data.snippet.snippet_type).toBe("package")
27
27
  expect(response.data.snippet.description).toBe("Test Description")
28
28
  })
29
+
30
+ test("create snippet and call package get to verify it exists", async () => {
31
+ const { axios, db } = await getTestServer()
32
+
33
+ const response = await axios.post("/api/snippets/create", {
34
+ unscoped_name: "example-package",
35
+ code: "console.log('Hello, world!');",
36
+ snippet_type: "package",
37
+ description: "Test Description",
38
+ })
39
+ const packageResponse = await axios.get(`/api/packages/get`, {
40
+ params: {
41
+ package_id: response.data.snippet.snippet_id,
42
+ },
43
+ })
44
+ expect(packageResponse.status).toBe(200)
45
+ expect(packageResponse.data.package.unscoped_name).toBe("example-package")
46
+ expect(packageResponse.data.package.owner_github_username).toBe("testuser")
47
+ expect(packageResponse.data.package.description).toBe("Test Description")
48
+
49
+ // Add package file verification
50
+ const packageFileResponse = await axios.post(`/api/package_files/get`, {
51
+ package_release_id: packageResponse.data.package.latest_package_release_id,
52
+ file_path: "index.tsx",
53
+ })
54
+
55
+ expect(packageFileResponse.status).toBe(200)
56
+ expect(packageFileResponse.data.ok).toBe(true)
57
+ expect(packageFileResponse.data.package_file).toBeDefined()
58
+ expect(packageFileResponse.data.package_file.content_text).toBe(
59
+ "console.log('Hello, world!');",
60
+ )
61
+ })
@@ -0,0 +1,114 @@
1
+ import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
+ import { expect, test } from "bun:test"
3
+ import { snippetSchema } from "fake-snippets-api/lib/db/schema"
4
+
5
+ test("GET /api/snippets/get - should return snippet by snippet_id", async () => {
6
+ const { axios } = await getTestServer()
7
+
8
+ // First create a snippet
9
+ const newSnippetData = {
10
+ code: "console.log('Hello World')",
11
+ snippet_type: "package",
12
+ description: "A test snippet",
13
+ compiled_js: "console.log('Hello World')",
14
+ dts: "export function hello(): void;",
15
+ }
16
+
17
+ const createResponse = await axios.post(
18
+ "/api/snippets/create",
19
+ newSnippetData,
20
+ )
21
+ expect(createResponse.status).toBe(200)
22
+ const createdSnippet = createResponse.data.snippet
23
+
24
+ // Get the created snippet using the /get endpoint
25
+ const getResponse = await axios.get("/api/snippets/get", {
26
+ params: { snippet_id: createdSnippet.snippet_id },
27
+ })
28
+
29
+ expect(getResponse.status).toBe(200)
30
+ const responseBody = getResponse.data
31
+ expect(responseBody.ok).toBe(true)
32
+ expect(responseBody.snippet).toEqual(snippetSchema.parse(createdSnippet))
33
+ })
34
+
35
+ test("GET /api/snippets/get - should return 404 if snippet not found", async () => {
36
+ const { axios } = await getTestServer()
37
+
38
+ try {
39
+ await axios.get("/api/snippets/get", {
40
+ params: { snippet_id: "non_existent_snippet_id" },
41
+ })
42
+ throw new Error("Expected request to fail")
43
+ } catch (error: any) {
44
+ expect(error.status).toBe(404)
45
+ expect(error.data.error.error_code).toBe("snippet_not_found")
46
+ expect(error.data.error.message).toBe(
47
+ 'Snippet not found (searched using {"snippet_id":"non_existent_snippet_id"})',
48
+ )
49
+ }
50
+ })
51
+
52
+ test("GET /api/snippets/get - should return snippet by name and owner", async () => {
53
+ const { axios } = await getTestServer()
54
+
55
+ // First create a snippet
56
+ const newSnippetData = {
57
+ code: "console.log('Hello World')",
58
+ snippet_type: "package",
59
+ description: "A test snippet",
60
+ compiled_js: "console.log('Hello World')",
61
+ dts: "export function hello(): void;",
62
+ }
63
+
64
+ const createResponse = await axios.post(
65
+ "/api/snippets/create",
66
+ newSnippetData,
67
+ )
68
+ expect(createResponse.status).toBe(200)
69
+ const createdSnippet = createResponse.data.snippet
70
+
71
+ // Get the snippet using name and owner
72
+ const getResponse = await axios.get("/api/snippets/get", {
73
+ params: {
74
+ name: createdSnippet.name,
75
+ owner_name: createdSnippet.owner_name,
76
+ },
77
+ })
78
+
79
+ expect(getResponse.status).toBe(200)
80
+ const responseBody = getResponse.data
81
+ expect(responseBody.ok).toBe(true)
82
+ expect(responseBody.snippet).toEqual(snippetSchema.parse(createdSnippet))
83
+ })
84
+
85
+ test("GET /api/snippets/get - should return snippet by unscoped_name and owner", async () => {
86
+ const { axios, db } = await getTestServer()
87
+
88
+ // First create a snippet
89
+ const snippet = {
90
+ unscoped_name: "test-package",
91
+ owner_name: "testuser",
92
+ code: "export const TestComponent = () => <div>Test</div>",
93
+ dts: "export declare const TestComponent: () => JSX.Element",
94
+ created_at: "2023-01-01T00:00:00Z",
95
+ updated_at: "2023-01-01T00:00:00Z",
96
+ name: "testuser/test-package",
97
+ snippet_type: "package",
98
+ description: "Test package",
99
+ }
100
+
101
+ db.addSnippet(snippet as any)
102
+
103
+ // Get the snippet using name and owner
104
+ const getResponse = await axios.get("/api/snippets/get", {
105
+ params: {
106
+ unscoped_name: snippet.unscoped_name,
107
+ owner_name: snippet.owner_name,
108
+ },
109
+ })
110
+
111
+ expect(getResponse.status).toBe(200)
112
+ const responseBody = getResponse.data
113
+ expect(responseBody.ok).toBe(true)
114
+ })
@@ -5,7 +5,7 @@ import { generateCircuitJson } from "bun-tests/fake-snippets-api/fixtures/get-ci
5
5
  test("get schematic svg of a snippet", async () => {
6
6
  const { axios, db } = await getTestServer()
7
7
 
8
- const addedSnippet = db.addSnippet({
8
+ const addedSnippet = {
9
9
  name: "testuser/my-test-board",
10
10
  unscoped_name: "my-test-board",
11
11
  owner_name: "testuser",
@@ -42,11 +42,13 @@ test("get schematic svg of a snippet", async () => {
42
42
  exports.A555Timer = A555Timer;
43
43
  `.trim(),
44
44
  }),
45
- })
45
+ }
46
+
47
+ const createdSnippet = await axios.post("/api/snippets/create", addedSnippet)
46
48
 
47
49
  const response = await axios.get("/api/snippets/get_image", {
48
50
  params: {
49
- snippetId: addedSnippet.snippet_id,
51
+ snippetId: createdSnippet.data.snippet.snippet_id,
50
52
  image_of: "schematic",
51
53
  format: "svg",
52
54
  },
@@ -60,7 +62,7 @@ test("get schematic svg of a snippet", async () => {
60
62
  test("get pcb svg of a snippet", async () => {
61
63
  const { axios, db } = await getTestServer()
62
64
 
63
- const addedSnippet = db.addSnippet({
65
+ const addedSnippet = {
64
66
  name: "testuser/my-test-board",
65
67
  unscoped_name: "my-test-board",
66
68
  owner_name: "testuser",
@@ -97,11 +99,13 @@ test("get pcb svg of a snippet", async () => {
97
99
  exports.A555Timer = A555Timer;
98
100
  `.trim(),
99
101
  }),
100
- })
102
+ }
103
+
104
+ const createdSnippet = await axios.post("/api/snippets/create", addedSnippet)
101
105
 
102
106
  const response = await axios.get("/api/snippets/get_image", {
103
107
  params: {
104
- snippetId: addedSnippet.snippet_id,
108
+ snippetId: createdSnippet.data.snippet.snippet_id,
105
109
  image_of: "pcb",
106
110
  format: "svg",
107
111
  },
@@ -5,7 +5,7 @@ import { generateCircuitJson } from "bun-tests/fake-snippets-api/fixtures/get-ci
5
5
  test("get schematic svg of a snippet", async () => {
6
6
  const { axios, db } = await getTestServer()
7
7
 
8
- const addedSnippet = db.addSnippet({
8
+ const addedSnippet = {
9
9
  name: "testuser/my-test-board",
10
10
  unscoped_name: "my-test-board",
11
11
  owner_name: "testuser",
@@ -42,7 +42,8 @@ test("get schematic svg of a snippet", async () => {
42
42
  exports.A555Timer = A555Timer;
43
43
  `.trim(),
44
44
  }),
45
- })
45
+ }
46
+ const createdSnippet = await axios.post("/api/snippets/create", addedSnippet)
46
47
 
47
48
  const snippetName = addedSnippet.name.replace(
48
49
  addedSnippet.owner_name + "/",
@@ -50,7 +51,7 @@ test("get schematic svg of a snippet", async () => {
50
51
  )
51
52
 
52
53
  const response = await axios.get(
53
- `/api/snippets/images/${addedSnippet.owner_name}/${snippetName}/schematic.svg`,
54
+ `/api/snippets/images/${createdSnippet.data.snippet.owner_name}/${createdSnippet.data.snippet.unscoped_name}/schematic.svg`,
54
55
  )
55
56
 
56
57
  expect(response.status).toBe(200)
@@ -60,7 +61,7 @@ test("get schematic svg of a snippet", async () => {
60
61
  test("get pcb svg of a snippet", async () => {
61
62
  const { axios, db } = await getTestServer()
62
63
 
63
- const addedSnippet = db.addSnippet({
64
+ const addedSnippet = {
64
65
  name: "testuser/my-test-board",
65
66
  unscoped_name: "my-test-board",
66
67
  owner_name: "testuser",
@@ -97,14 +98,15 @@ test("get pcb svg of a snippet", async () => {
97
98
  exports.A555Timer = A555Timer;
98
99
  `.trim(),
99
100
  }),
100
- })
101
+ }
102
+ const createdSnippet = await axios.post("/api/snippets/create", addedSnippet)
101
103
 
102
104
  const snippetName = addedSnippet.name.replace(
103
105
  addedSnippet.owner_name + "/",
104
106
  "",
105
107
  )
106
108
  const response = await axios.get(
107
- `/api/snippets/images/${addedSnippet.owner_name}/${snippetName}/pcb.svg`,
109
+ `/api/snippets/images/${createdSnippet.data.snippet.owner_name}/${createdSnippet.data.snippet.unscoped_name}/pcb.svg`,
108
110
  )
109
111
 
110
112
  expect(response.status).toBe(200)
@@ -42,7 +42,7 @@ test("list newest snippets", async () => {
42
42
  const { data } = await axios.get("/api/snippets/list_newest")
43
43
 
44
44
  expect(data.snippets).toHaveLength(3)
45
- expect(data.snippets[0].unscoped_name).toBe("Snippet3")
45
+ expect(data.snippets[0].unscoped_name).toBe("Snippet1")
46
46
  expect(data.snippets[1].unscoped_name).toBe("Snippet2")
47
- expect(data.snippets[2].unscoped_name).toBe("Snippet1")
47
+ expect(data.snippets[2].unscoped_name).toBe("Snippet3")
48
48
  })
@@ -36,7 +36,7 @@ test("list trending snippets", async () => {
36
36
  ]
37
37
 
38
38
  for (const snippet of snippets) {
39
- db.addSnippet(snippet as any)
39
+ await axios.post("/api/snippets/create", snippet)
40
40
  }
41
41
 
42
42
  const now = new Date()
@@ -44,21 +44,21 @@ test("list trending snippets", async () => {
44
44
  const oldDate = new Date(now.getTime() - 10 * 24 * 60 * 60 * 1000) // 10 days ago
45
45
 
46
46
  // Add stars with different dates
47
- const snippet1 = db.snippets[0]
48
- const snippet2 = db.snippets[1]
49
- const snippet3 = db.snippets[2]
47
+ const package1 = db.packages[0]
48
+ const package2 = db.packages[1]
49
+ const package3 = db.packages[2]
50
50
 
51
51
  // Snippet2 should be most trending (3 recent stars)
52
- db.addStar("user1", snippet2.snippet_id)
53
- db.addStar("user2", snippet2.snippet_id)
54
- db.addStar("user3", snippet2.snippet_id)
52
+ db.addStar("user1", package2.package_id)
53
+ db.addStar("user2", package2.package_id)
54
+ db.addStar("user3", package2.package_id)
55
55
 
56
56
  // Snippet3 second (2 recent stars)
57
- db.addStar("user1", snippet3.snippet_id)
58
- db.addStar("user2", snippet3.snippet_id)
57
+ db.addStar("user1", package3.package_id)
58
+ db.addStar("user2", package3.package_id)
59
59
 
60
60
  // Snippet1 least trending (1 recent star, 1 old star)
61
- db.addStar("user1", snippet1.snippet_id)
61
+ db.addStar("user1", package1.package_id)
62
62
 
63
63
  const { data } = await axios.get("/api/snippets/list_trending")
64
64
 
@@ -15,13 +15,13 @@ test("remove star from snippet", async () => {
15
15
  snippet_type: "package",
16
16
  description: "Test Description",
17
17
  }
18
- const addedSnippet = db.addSnippet(snippet as any)!
19
18
 
19
+ const createdSnippet = await axios.post("/api/snippets/create", snippet)
20
20
  // Star the snippet
21
21
  await axios.post(
22
22
  "/api/snippets/add_star",
23
23
  {
24
- snippet_id: addedSnippet.snippet_id,
24
+ snippet_id: createdSnippet.data.snippet.snippet_id,
25
25
  },
26
26
  {
27
27
  headers: {
@@ -34,7 +34,7 @@ test("remove star from snippet", async () => {
34
34
  const response = await axios.post(
35
35
  "/api/snippets/remove_star",
36
36
  {
37
- snippet_id: addedSnippet.snippet_id,
37
+ snippet_id: createdSnippet.data.snippet.snippet_id,
38
38
  },
39
39
  {
40
40
  headers: {
@@ -48,7 +48,9 @@ test("remove star from snippet", async () => {
48
48
  expect(response.data.is_starred).toBe(false)
49
49
 
50
50
  // Verify star was removed in database
51
- expect(db.hasStarred("account-123", addedSnippet.snippet_id)).toBe(false)
51
+ expect(
52
+ db.hasStarred("account-123", createdSnippet.data.snippet.snippet_id),
53
+ ).toBe(false)
52
54
  })
53
55
 
54
56
  test("remove star from non-existent snippet", async () => {
@@ -87,14 +89,14 @@ test("remove star from unstarred snippet", async () => {
87
89
  snippet_type: "package",
88
90
  description: "Test Description",
89
91
  }
90
- const addedSnippet = db.addSnippet(snippet as any)
92
+ const createdSnippet = await axios.post("/api/snippets/create", snippet)
91
93
 
92
94
  // Remove star
93
95
  try {
94
96
  await axios.post(
95
97
  "/api/snippets/remove_star",
96
98
  {
97
- snippet_id: addedSnippet.snippet_id,
99
+ snippet_id: createdSnippet.data.snippet.snippet_id,
98
100
  },
99
101
  {
100
102
  headers: {
@@ -1,5 +1,5 @@
1
1
  import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
- import { test, expect } from "bun:test"
2
+ import { expect, test } from "bun:test"
3
3
 
4
4
  test("search snippets", async () => {
5
5
  const { axios, db } = await getTestServer()