@tscircuit/fake-snippets 0.0.7 → 0.0.8
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.
- package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +2 -5
- package/bun-tests/fake-snippets-api/routes/packages/{list.test.ts → list-1.test.ts} +3 -55
- package/bun-tests/fake-snippets-api/routes/packages/list-2.test.ts +59 -0
- package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +34 -1
- package/bun.lock +3 -0
- package/dist/bundle.js +146 -62
- package/fake-snippets-api/lib/db/db-client.ts +46 -51
- package/fake-snippets-api/lib/db/schema.ts +15 -6
- package/fake-snippets-api/lib/public-mapping/public-map-package.ts +9 -2
- package/fake-snippets-api/routes/api/snippets/create.ts +123 -29
- package/package.json +2 -1
|
@@ -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 =
|
|
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 {
|
|
@@ -4,6 +4,9 @@ import { expect, test } from "bun:test"
|
|
|
4
4
|
test("list packages", async () => {
|
|
5
5
|
const { axios, db } = await getTestServer()
|
|
6
6
|
|
|
7
|
+
// Log the initial state of packages in the database
|
|
8
|
+
console.log("Initial packages in DB:", db.packages)
|
|
9
|
+
|
|
7
10
|
// Add some test packages
|
|
8
11
|
const packages = [
|
|
9
12
|
{
|
|
@@ -110,58 +113,3 @@ test("list packages", async () => {
|
|
|
110
113
|
})
|
|
111
114
|
expect(authData.packages).toHaveLength(3) // Should return all packages when authenticated
|
|
112
115
|
})
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
2
|
-
import {
|
|
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
|
+
})
|
package/bun.lock
CHANGED
|
@@ -126,6 +126,7 @@
|
|
|
126
126
|
"@vitejs/plugin-react": "^4.3.1",
|
|
127
127
|
"autoprefixer": "^10.4.20",
|
|
128
128
|
"circuit-to-svg": "^0.0.101",
|
|
129
|
+
"get-port": "^7.1.0",
|
|
129
130
|
"globals": "^15.9.0",
|
|
130
131
|
"postcss": "^8.4.47",
|
|
131
132
|
"prismjs": "^1.29.0",
|
|
@@ -1375,6 +1376,8 @@
|
|
|
1375
1376
|
|
|
1376
1377
|
"get-nonce": ["get-nonce@1.0.1", "", {}, "sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q=="],
|
|
1377
1378
|
|
|
1379
|
+
"get-port": ["get-port@7.1.0", "", {}, "sha512-QB9NKEeDg3xxVwCCwJQ9+xycaz6pBB6iQ76wiWMl1927n0Kir6alPiP+yuiICLLU4jpMe08dXfpebuQppFA2zw=="],
|
|
1380
|
+
|
|
1378
1381
|
"get-stream": ["get-stream@9.0.1", "", { "dependencies": { "@sec-ant/readable-stream": "^0.4.1", "is-stream": "^4.0.1" } }, "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA=="],
|
|
1379
1382
|
|
|
1380
1383
|
"github-from-package": ["github-from-package@0.0.0", "", {}, "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw=="],
|