@tscircuit/fake-snippets 0.0.118 → 0.0.120
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/routes/bug_reports/create.test.ts +37 -0
- package/bun-tests/fake-snippets-api/routes/bug_reports/upload_file.test.ts +89 -0
- package/bun-tests/fake-snippets-api/routes/packages/get.test.ts +3 -0
- package/bun.lock +2 -2
- package/dist/bundle.js +778 -508
- package/dist/index.d.ts +161 -6
- package/dist/index.js +102 -3
- package/dist/schema.d.ts +225 -7
- package/dist/schema.js +38 -3
- package/fake-snippets-api/lib/db/db-client.ts +98 -0
- package/fake-snippets-api/lib/db/schema.ts +37 -0
- package/fake-snippets-api/lib/public-mapping/public-map-package-release.ts +6 -0
- package/fake-snippets-api/lib/public-mapping/public-map-package.ts +9 -0
- package/fake-snippets-api/routes/api/bug_reports/create.ts +43 -0
- package/fake-snippets-api/routes/api/bug_reports/upload_file.ts +113 -0
- package/package.json +2 -2
- package/src/components/Header.tsx +16 -0
- package/src/components/PackageCard.tsx +7 -4
- package/src/components/PackageSearchResults.tsx +1 -7
- package/src/components/SearchComponent.tsx +64 -53
- package/src/components/TrendingPackagesCarousel.tsx +16 -23
- package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +3 -2
- package/src/components/ViewPackagePage/components/preview-image-squares.tsx +6 -3
- package/src/hooks/use-preview-images.ts +22 -17
- package/src/hooks/useUpdatePackageFilesMutation.ts +8 -0
- package/src/lib/utils/getPackagePreviewImageUrl.ts +15 -0
- package/src/pages/dashboard.tsx +0 -1
- package/src/pages/editor.tsx +12 -9
- package/src/pages/organization-profile.tsx +0 -1
- package/src/pages/package-editor.tsx +13 -9
- package/src/pages/user-profile.tsx +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
2
|
+
import { expect, test } from "bun:test"
|
|
3
|
+
|
|
4
|
+
test("create bug report with defaults", async () => {
|
|
5
|
+
const { axios, db, seed } = await getTestServer()
|
|
6
|
+
|
|
7
|
+
const response = await axios.post("/api/bug_reports/create", {})
|
|
8
|
+
|
|
9
|
+
expect(response.status).toBe(200)
|
|
10
|
+
const bugReport = response.data.bug_report
|
|
11
|
+
expect(bugReport).toBeDefined()
|
|
12
|
+
expect(bugReport.reporter_account_id).toBe(seed.account.account_id)
|
|
13
|
+
expect(bugReport.text).toBeNull()
|
|
14
|
+
expect(bugReport.is_auto_deleted).toBe(false)
|
|
15
|
+
expect(bugReport.delete_at).toBeNull()
|
|
16
|
+
expect(bugReport.file_count).toBe(0)
|
|
17
|
+
|
|
18
|
+
const stored = db.getBugReportById(bugReport.bug_report_id)
|
|
19
|
+
expect(stored).toBeDefined()
|
|
20
|
+
expect(stored?.bug_report_id).toBe(bugReport.bug_report_id)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test("requires delete_at when auto deletion is enabled", async () => {
|
|
24
|
+
const { axios } = await getTestServer()
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
await axios.post("/api/bug_reports/create", {
|
|
28
|
+
is_auto_deleted: true,
|
|
29
|
+
})
|
|
30
|
+
throw new Error("Expected request to fail")
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
expect(error.status).toBe(400)
|
|
33
|
+
expect(error.data.message).toContain(
|
|
34
|
+
"delete_at is required when is_auto_deleted is true",
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer"
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
3
|
+
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
4
|
+
import { expect, test } from "bun:test"
|
|
5
|
+
|
|
6
|
+
const sampleBase64 = Buffer.from("binary-data").toString("base64")
|
|
7
|
+
|
|
8
|
+
test("upload text file to bug report", async () => {
|
|
9
|
+
const { axios, db } = await getTestServer()
|
|
10
|
+
|
|
11
|
+
const createResponse = await axios.post("/api/bug_reports/create", {
|
|
12
|
+
text: "Initial report",
|
|
13
|
+
})
|
|
14
|
+
const bugReportId = createResponse.data.bug_report.bug_report_id
|
|
15
|
+
|
|
16
|
+
const uploadResponse = await axios.post("/api/bug_reports/upload_file", {
|
|
17
|
+
bug_report_id: bugReportId,
|
|
18
|
+
file_path: "./src//issue.txt",
|
|
19
|
+
content_text: "Steps to reproduce",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
expect(uploadResponse.status).toBe(200)
|
|
23
|
+
expect(uploadResponse.data.bug_report_file.file_path).toBe("src/issue.txt")
|
|
24
|
+
expect(uploadResponse.data.bug_report_file.is_text).toBe(true)
|
|
25
|
+
|
|
26
|
+
const storedReport = db.getBugReportById(bugReportId)
|
|
27
|
+
expect(storedReport?.file_count).toBe(1)
|
|
28
|
+
|
|
29
|
+
const storedFiles = db.getBugReportFilesByBugReportId(bugReportId)
|
|
30
|
+
expect(storedFiles).toHaveLength(1)
|
|
31
|
+
expect(storedFiles[0].content_text).toBe("Steps to reproduce")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("upload binary file requires ownership", async () => {
|
|
35
|
+
const { axios, jane_axios } = await getTestServer()
|
|
36
|
+
|
|
37
|
+
const createResponse = await axios.post("/api/bug_reports/create", {
|
|
38
|
+
text: "Owned by primary account",
|
|
39
|
+
})
|
|
40
|
+
const bugReportId = createResponse.data.bug_report.bug_report_id
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await jane_axios.post("/api/bug_reports/upload_file", {
|
|
44
|
+
bug_report_id: bugReportId,
|
|
45
|
+
file_path: "attachments/data.bin",
|
|
46
|
+
content_base64: sampleBase64,
|
|
47
|
+
})
|
|
48
|
+
throw new Error("Expected request to fail")
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
expect(error.status).toBe(403)
|
|
51
|
+
expect(error.data.error.error_code).toBe("bug_report_forbidden")
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test("cannot supply both text and base64 content", async () => {
|
|
56
|
+
const { axios } = await getTestServer()
|
|
57
|
+
|
|
58
|
+
const createResponse = await axios.post("/api/bug_reports/create", {
|
|
59
|
+
text: "Initial",
|
|
60
|
+
})
|
|
61
|
+
const bugReportId = createResponse.data.bug_report.bug_report_id
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await axios.post("/api/bug_reports/upload_file", {
|
|
65
|
+
bug_report_id: bugReportId,
|
|
66
|
+
file_path: "details.txt",
|
|
67
|
+
content_text: "foo",
|
|
68
|
+
content_base64: sampleBase64,
|
|
69
|
+
})
|
|
70
|
+
throw new Error("Expected request to fail")
|
|
71
|
+
} catch (error: any) {
|
|
72
|
+
expect(error.status).toBe(400)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test("uploading to unknown bug report returns 404", async () => {
|
|
77
|
+
const { axios } = await getTestServer()
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await axios.post("/api/bug_reports/upload_file", {
|
|
81
|
+
bug_report_id: randomUUID(),
|
|
82
|
+
file_path: "missing.txt",
|
|
83
|
+
})
|
|
84
|
+
throw new Error("Expected request to fail")
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
expect(error.status).toBe(404)
|
|
87
|
+
expect(error.data.error.error_code).toBe("bug_report_not_found")
|
|
88
|
+
}
|
|
89
|
+
})
|
|
@@ -38,6 +38,9 @@ test("GET /api/packages/get - should return package by package_id", async () =>
|
|
|
38
38
|
const responseBody = getResponse.data
|
|
39
39
|
expect(responseBody.ok).toBe(true)
|
|
40
40
|
expect(responseBody.package).toBeDefined()
|
|
41
|
+
expect(responseBody.package.latest_pcb_preview_image_url).toBeDefined()
|
|
42
|
+
expect(responseBody.package.latest_sch_preview_image_url).toBeDefined()
|
|
43
|
+
expect(responseBody.package.latest_cad_preview_image_url).toBeDefined()
|
|
41
44
|
})
|
|
42
45
|
|
|
43
46
|
test("GET /api/packages/get - should return 404 if package not found", async () => {
|
package/bun.lock
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@tscircuit/3d-viewer": "^0.0.407",
|
|
52
52
|
"@tscircuit/assembly-viewer": "^0.0.5",
|
|
53
53
|
"@tscircuit/create-snippet-url": "^0.0.8",
|
|
54
|
-
"@tscircuit/eval": "^0.0.
|
|
54
|
+
"@tscircuit/eval": "^0.0.414",
|
|
55
55
|
"@tscircuit/layout": "^0.0.29",
|
|
56
56
|
"@tscircuit/mm": "^0.0.8",
|
|
57
57
|
"@tscircuit/pcb-viewer": "^1.11.218",
|
|
@@ -765,7 +765,7 @@
|
|
|
765
765
|
|
|
766
766
|
"@tscircuit/create-snippet-url": ["@tscircuit/create-snippet-url@0.0.8", "", { "dependencies": { "fflate": "^0.8.2" }, "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-VMixgwQRsOXlQGwVh2RZIFLLtsn8YWl2Bht61T26MHNM71A1Wzo5qGZtqcdbVkFnvlA42KmdVVjvxYDvEyWdJw=="],
|
|
767
767
|
|
|
768
|
-
"@tscircuit/eval": ["@tscircuit/eval@0.0.
|
|
768
|
+
"@tscircuit/eval": ["@tscircuit/eval@0.0.414", "", { "peerDependencies": { "@tscircuit/core": "*", "circuit-json": "*", "typescript": "^5.0.0", "zod": "3" } }, "sha512-XiXeopXQsIq2Awfa0vipzJR8wW890i3GaExplNRNBoN17rCM/upEw6cJ7wbKvUEJpYIzalklPbJH780DltiuPA=="],
|
|
769
769
|
|
|
770
770
|
"@tscircuit/featured-snippets": ["@tscircuit/featured-snippets@0.0.1", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-SNUbCQmyaAaWq7DqqDbYlZkYttbfaObtp5rOheZvlJ2TGYvooECFpB8SzNo06bqKGoIwNjgaAGUTB2DcxdX7ow=="],
|
|
771
771
|
|