@tscircuit/fake-snippets 0.0.9 → 0.0.10
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.
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
|
|
2
|
+
import { expect, test } from "bun:test"
|
|
3
|
+
|
|
4
|
+
test("update package", async () => {
|
|
5
|
+
const { axios, db } = await getTestServer()
|
|
6
|
+
|
|
7
|
+
// First create a package
|
|
8
|
+
const packageResponse = await axios.post(
|
|
9
|
+
"/api/packages/create",
|
|
10
|
+
{
|
|
11
|
+
name: "test-package",
|
|
12
|
+
description: "Test Description",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: "Bearer 1234",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
)
|
|
20
|
+
const packageId = packageResponse.data.package.package_id
|
|
21
|
+
|
|
22
|
+
// Update the package
|
|
23
|
+
const response = await axios.post(
|
|
24
|
+
"/api/packages/update",
|
|
25
|
+
{
|
|
26
|
+
package_id: packageId,
|
|
27
|
+
name: "updated-package",
|
|
28
|
+
description: "Updated Description",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: "Bearer 1234",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect(response.status).toBe(200)
|
|
38
|
+
expect(response.data.ok).toBe(true)
|
|
39
|
+
expect(response.data.package.name).toBe("testuser/updated-package")
|
|
40
|
+
expect(response.data.package.description).toBe("Updated Description")
|
|
41
|
+
|
|
42
|
+
// Verify the package was updated in the database
|
|
43
|
+
const updatedPackage = db.packages.find((p) => p.package_id === packageId)
|
|
44
|
+
expect(updatedPackage?.name).toBe("testuser/updated-package")
|
|
45
|
+
expect(updatedPackage?.description).toBe("Updated Description")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("update package privacy settings", async () => {
|
|
49
|
+
const { axios, db } = await getTestServer()
|
|
50
|
+
|
|
51
|
+
// Create initial public package
|
|
52
|
+
const packageResponse = await axios.post(
|
|
53
|
+
"/api/packages/create",
|
|
54
|
+
{
|
|
55
|
+
name: "public-package",
|
|
56
|
+
description: "Public Package",
|
|
57
|
+
is_private: false,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: "Bearer 1234",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
const packageId = packageResponse.data.package.package_id
|
|
66
|
+
|
|
67
|
+
// Update to make it private
|
|
68
|
+
const response = await axios.post(
|
|
69
|
+
"/api/packages/update",
|
|
70
|
+
{
|
|
71
|
+
package_id: packageId,
|
|
72
|
+
is_private: true,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
headers: {
|
|
76
|
+
Authorization: "Bearer 1234",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
expect(response.status).toBe(200)
|
|
82
|
+
expect(response.data.ok).toBe(true)
|
|
83
|
+
expect(response.data.package.is_private).toBe(true)
|
|
84
|
+
expect(response.data.package.is_public).toBe(false)
|
|
85
|
+
expect(response.data.package.is_unlisted).toBe(true) // Private packages should be unlisted
|
|
86
|
+
|
|
87
|
+
// Verify in database
|
|
88
|
+
const updatedPackage = db.packages.find((p) => p.package_id === packageId)
|
|
89
|
+
expect(updatedPackage?.is_private).toBe(true)
|
|
90
|
+
expect(updatedPackage?.is_public).toBe(false)
|
|
91
|
+
expect(updatedPackage?.is_unlisted).toBe(true)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test("update non-existent package", async () => {
|
|
95
|
+
const { axios } = await getTestServer()
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await axios.post(
|
|
99
|
+
"/api/packages/update",
|
|
100
|
+
{
|
|
101
|
+
package_id: "non-existent-id",
|
|
102
|
+
name: "updated-name",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
headers: {
|
|
106
|
+
Authorization: "Bearer 1234",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
throw new Error("Expected request to fail")
|
|
111
|
+
} catch (error: any) {
|
|
112
|
+
expect(error.status).toBe(404)
|
|
113
|
+
expect(error.data.error.error_code).toBe("package_not_found")
|
|
114
|
+
expect(error.data.error.message).toBe("Package not found")
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test("update package without permission", async () => {
|
|
119
|
+
const { axios, db } = await getTestServer()
|
|
120
|
+
|
|
121
|
+
db.addPackage({
|
|
122
|
+
name: "Package3",
|
|
123
|
+
unscoped_name: "Package3",
|
|
124
|
+
owner_github_username: "user1",
|
|
125
|
+
creator_account_id: "creator1",
|
|
126
|
+
created_at: "2023-01-03T00:00:00Z",
|
|
127
|
+
updated_at: "2023-01-03T00:00:00Z",
|
|
128
|
+
description: "Description 3",
|
|
129
|
+
ai_description: "AI Description 3",
|
|
130
|
+
owner_org_id: "org1",
|
|
131
|
+
latest_version: "1.0.0",
|
|
132
|
+
license: "MIT",
|
|
133
|
+
is_source_from_github: true,
|
|
134
|
+
star_count: 0,
|
|
135
|
+
} as any)
|
|
136
|
+
|
|
137
|
+
const packageId = db.packages[0].package_id
|
|
138
|
+
|
|
139
|
+
// Try to update with different user
|
|
140
|
+
try {
|
|
141
|
+
await axios.post(
|
|
142
|
+
"/api/packages/update",
|
|
143
|
+
{
|
|
144
|
+
package_id: packageId,
|
|
145
|
+
name: "stolen-package",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: "Bearer 5678", // Different user
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
throw new Error("Expected request to fail")
|
|
154
|
+
} catch (error: any) {
|
|
155
|
+
expect(error.status).toBe(403)
|
|
156
|
+
expect(error.data.error.error_code).toBe("forbidden")
|
|
157
|
+
expect(error.data.error.message).toBe(
|
|
158
|
+
"You don't have permission to update this package",
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
})
|