@tscircuit/fake-snippets 0.0.35 → 0.0.36
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/.github/workflows/bun-test.yml +0 -3
- package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +1 -0
- package/bun-tests/fake-snippets-api/routes/packages/fork.test.ts +133 -0
- package/dist/bundle.js +259 -130
- package/fake-snippets-api/routes/api/packages/fork.ts +162 -0
- package/package.json +2 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
2
|
+
import { test, expect } from "bun:test"
|
|
3
|
+
|
|
4
|
+
test("POST /packages/fork - successful fork using package_id", async () => {
|
|
5
|
+
const { axios, jane_axios } = await getTestServer()
|
|
6
|
+
|
|
7
|
+
// user creates a package with files
|
|
8
|
+
const sourcePackage = await axios
|
|
9
|
+
.post("/api/packages/create", {
|
|
10
|
+
name: "testuser/test-package-for-fork",
|
|
11
|
+
description: "A package to be forked",
|
|
12
|
+
})
|
|
13
|
+
.then((r: any) => r.data.package)
|
|
14
|
+
|
|
15
|
+
// user creates a release
|
|
16
|
+
const sourceRelease = await axios
|
|
17
|
+
.post("/api/package_releases/create", {
|
|
18
|
+
package_id: sourcePackage.package_id,
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
})
|
|
21
|
+
.then((r: any) => r.data.package_release)
|
|
22
|
+
|
|
23
|
+
// user creates a file
|
|
24
|
+
await axios.post("/api/package_files/create", {
|
|
25
|
+
package_release_id: sourceRelease.package_release_id,
|
|
26
|
+
file_path: "index.tsx",
|
|
27
|
+
content_text: "console.log('Hello from original package');",
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Jane forks the package
|
|
31
|
+
const forkedPackageResponse = await jane_axios.post("/api/packages/fork", {
|
|
32
|
+
package_id: sourcePackage.package_id,
|
|
33
|
+
is_private: false,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const forkedPackage = forkedPackageResponse.data.package
|
|
37
|
+
|
|
38
|
+
// Verify fork was created successfully
|
|
39
|
+
expect(forkedPackage.name).toBe(`jane/${sourcePackage.unscoped_name}`)
|
|
40
|
+
expect(forkedPackage.description).toBe(sourcePackage.description)
|
|
41
|
+
expect(forkedPackage.is_private).toBe(false)
|
|
42
|
+
|
|
43
|
+
// List files from the forked package
|
|
44
|
+
const packageFilesResponse = await jane_axios.post(
|
|
45
|
+
"/api/package_files/list",
|
|
46
|
+
{
|
|
47
|
+
package_name: forkedPackage.name,
|
|
48
|
+
use_latest_version: true,
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const package_files = packageFilesResponse.data.package_files
|
|
53
|
+
|
|
54
|
+
expect(package_files.length).toBe(1)
|
|
55
|
+
expect(package_files[0].file_path).toBe("index.tsx")
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test("POST /packages/fork - successful fork using package_name", async () => {
|
|
59
|
+
const { axios, jane_axios } = await getTestServer()
|
|
60
|
+
|
|
61
|
+
// Jane creates a package with files
|
|
62
|
+
const sourcePackage = await jane_axios
|
|
63
|
+
.post("/api/packages/create", {
|
|
64
|
+
name: "jane/test-package-for-name-fork",
|
|
65
|
+
description: "A package to be forked by name",
|
|
66
|
+
})
|
|
67
|
+
.then((r: any) => r.data.package)
|
|
68
|
+
|
|
69
|
+
// Create a release
|
|
70
|
+
const sourceRelease = await jane_axios
|
|
71
|
+
.post("/api/package_releases/create", {
|
|
72
|
+
package_id: sourcePackage.package_id,
|
|
73
|
+
version: "1.0.0",
|
|
74
|
+
})
|
|
75
|
+
.then((r: any) => r.data.package_release)
|
|
76
|
+
|
|
77
|
+
// Create a file
|
|
78
|
+
await jane_axios.post("/api/package_files/create", {
|
|
79
|
+
package_release_id: sourceRelease.package_release_id,
|
|
80
|
+
file_path: "index.tsx",
|
|
81
|
+
content_text: "console.log('Hello from name package');",
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// user forks Jane's package using package_name
|
|
85
|
+
const forkedPackage = await axios
|
|
86
|
+
.post("/api/packages/fork", {
|
|
87
|
+
package_name: "jane/test-package-for-name-fork",
|
|
88
|
+
is_private: true,
|
|
89
|
+
})
|
|
90
|
+
.then((r: any) => r.data.package)
|
|
91
|
+
|
|
92
|
+
// Verify fork was created successfully with privacy settings
|
|
93
|
+
expect(forkedPackage.name).toBe(`testuser/${sourcePackage.unscoped_name}`)
|
|
94
|
+
expect(forkedPackage.is_private).toBe(true)
|
|
95
|
+
expect(forkedPackage.is_unlisted).toBe(true) // Should be unlisted since it's private
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test("POST /packages/fork - error when package not found", async () => {
|
|
99
|
+
const { axios } = await getTestServer()
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
await axios.post("/api/packages/fork", {
|
|
103
|
+
package_id: "00000000-0000-0000-0000-000000000000", // Non-existent ID
|
|
104
|
+
})
|
|
105
|
+
// If it doesn't throw, fail the test
|
|
106
|
+
expect(true).toBe(false)
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
expect(error.status).toBe(404)
|
|
109
|
+
expect(error.data.error.error_code).toBe("package_not_found")
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test("POST /packages/fork - error when trying to fork own package", async () => {
|
|
114
|
+
const { jane_axios } = await getTestServer()
|
|
115
|
+
|
|
116
|
+
const sourcePackage = await jane_axios
|
|
117
|
+
.post("/api/packages/create", {
|
|
118
|
+
name: "jane/test-package-for-fork",
|
|
119
|
+
description: "A package to be forked",
|
|
120
|
+
})
|
|
121
|
+
.then((r: any) => r.data.package)
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await jane_axios.post("/api/packages/fork", {
|
|
125
|
+
package_id: sourcePackage.package_id,
|
|
126
|
+
})
|
|
127
|
+
// If it doesn't throw, fail the test
|
|
128
|
+
expect(true).toBe(false)
|
|
129
|
+
} catch (error: any) {
|
|
130
|
+
expect(error.status).toBe(400)
|
|
131
|
+
expect(error.data.error.error_code).toBe("cannot_fork_own_package")
|
|
132
|
+
}
|
|
133
|
+
})
|