@tscircuit/fake-snippets 0.0.11 → 0.0.13
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/packages/create.test.ts +16 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list.test.ts +138 -6
- package/bun.lock +457 -796
- package/dist/bundle.js +78 -23
- package/fake-snippets-api/lib/public-mapping/public-map-package.ts +18 -14
- package/fake-snippets-api/routes/api/packages/create.ts +6 -1
- package/fake-snippets-api/routes/api/snippets/list.ts +75 -12
- package/package.json +4 -3
- package/playwright-tests/editor-page.spec.ts +2 -2
- package/playwright-tests/footprint-dialog/footprint-dialog.spec.ts +1 -1
- package/playwright-tests/footprint-dialog/footprint-insertion.spec.ts +1 -1
- package/playwright-tests/footprint-dialog/footprint-preview.spec.ts +1 -1
- package/playwright-tests/footprint-dialog/footprint-selection.spec.ts +1 -1
- package/playwright-tests/profile-page.spec.ts +50 -1
- package/playwright-tests/snapshots/editor-page.spec.ts-editor-with-snippet.png +0 -0
- package/playwright-tests/snapshots/profile-page.spec.ts-profile-page-snippets-tab.png +0 -0
- package/playwright-tests/snapshots/profile-page.spec.ts-profile-page-starred-tab.png +0 -0
- package/playwright-tests/snapshots/profile-page.spec.ts-snippet-page-open-after-star-click.png +0 -0
- package/src/components/CodeAndPreview.tsx +35 -6
- package/src/components/EditorNav.tsx +102 -92
- package/src/components/Header2.tsx +1 -18
- package/src/components/PreviewContent.tsx +2 -2
- package/src/components/dialogs/package-visibility-settings-dialog.tsx +85 -0
- package/src/hooks/use-create-snippet-mutation.ts +3 -0
- package/src/lib/download-fns/download-kicad-files.ts +2 -2
- package/src/pages/user-profile.tsx +50 -15
|
@@ -23,4 +23,20 @@ test("create package", async () => {
|
|
|
23
23
|
expect(response.data.package.owner_github_username).toBe("testuser")
|
|
24
24
|
expect(response.data.package.description).toBe("Test Description")
|
|
25
25
|
expect(response.data.package.latest_package_release_id).toBeDefined()
|
|
26
|
+
expect(response.data.package.is_private).toBe(false)
|
|
27
|
+
expect(response.data.package.is_public).toBe(true)
|
|
28
|
+
expect(response.data.package.is_unlisted).toBe(false)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test("create package with private flag", async () => {
|
|
32
|
+
const { axios } = await getTestServer()
|
|
33
|
+
|
|
34
|
+
const response = await axios.post("/api/packages/create", {
|
|
35
|
+
name: "TestPackage",
|
|
36
|
+
description: "Test Description",
|
|
37
|
+
is_private: true,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
expect(response.status).toBe(200)
|
|
41
|
+
expect(response.data.package.is_private).toBe(true)
|
|
26
42
|
})
|
|
@@ -8,11 +8,11 @@ test("list snippets", async () => {
|
|
|
8
8
|
const snippets = [
|
|
9
9
|
{
|
|
10
10
|
unscoped_name: "Snippet1",
|
|
11
|
-
owner_name: "
|
|
11
|
+
owner_name: "testuser",
|
|
12
12
|
code: "Content1",
|
|
13
13
|
created_at: "2023-01-01T00:00:00Z",
|
|
14
14
|
updated_at: "2023-01-01T00:00:00Z",
|
|
15
|
-
name: "
|
|
15
|
+
name: "testuser/Snippet1",
|
|
16
16
|
snippet_type: "board",
|
|
17
17
|
},
|
|
18
18
|
{
|
|
@@ -26,11 +26,11 @@ test("list snippets", async () => {
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
unscoped_name: "Snippet3",
|
|
29
|
-
owner_name: "
|
|
29
|
+
owner_name: "testuser",
|
|
30
30
|
code: "Content3",
|
|
31
31
|
created_at: "2023-01-03T00:00:00Z",
|
|
32
32
|
updated_at: "2023-01-03T00:00:00Z",
|
|
33
|
-
name: "
|
|
33
|
+
name: "testuser/Snippet3",
|
|
34
34
|
snippet_type: "model",
|
|
35
35
|
},
|
|
36
36
|
]
|
|
@@ -45,12 +45,12 @@ test("list snippets", async () => {
|
|
|
45
45
|
|
|
46
46
|
// Test with owner_name parameter
|
|
47
47
|
const { data: user1Data } = await axios.get("/api/snippets/list", {
|
|
48
|
-
params: { owner_name: "
|
|
48
|
+
params: { owner_name: "testuser" },
|
|
49
49
|
})
|
|
50
50
|
expect(user1Data.snippets).toHaveLength(2)
|
|
51
51
|
expect(
|
|
52
52
|
user1Data.snippets.every(
|
|
53
|
-
(snippet: { owner_name: string }) => snippet.owner_name === "
|
|
53
|
+
(snippet: { owner_name: string }) => snippet.owner_name === "testuser",
|
|
54
54
|
),
|
|
55
55
|
).toBe(true)
|
|
56
56
|
|
|
@@ -60,3 +60,135 @@ test("list snippets", async () => {
|
|
|
60
60
|
})
|
|
61
61
|
expect(nonExistentData.snippets).toHaveLength(0)
|
|
62
62
|
})
|
|
63
|
+
|
|
64
|
+
test("list snippets by owner", async () => {
|
|
65
|
+
const { axios, db } = await getTestServer()
|
|
66
|
+
|
|
67
|
+
// Create some test snippets
|
|
68
|
+
const snippets = [
|
|
69
|
+
{
|
|
70
|
+
unscoped_name: "Snippet1",
|
|
71
|
+
owner_name: "testuser",
|
|
72
|
+
code: "Content1",
|
|
73
|
+
created_at: "2023-01-01T00:00:00Z",
|
|
74
|
+
updated_at: "2023-01-01T00:00:00Z",
|
|
75
|
+
name: "testuser/Snippet1",
|
|
76
|
+
snippet_type: "board",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
unscoped_name: "Snippet2",
|
|
80
|
+
owner_name: "otheruser",
|
|
81
|
+
code: "Content2",
|
|
82
|
+
created_at: "2023-01-02T00:00:00Z",
|
|
83
|
+
updated_at: "2023-01-02T00:00:00Z",
|
|
84
|
+
name: "otheruser/Snippet2",
|
|
85
|
+
snippet_type: "package",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
for (const snippet of snippets) {
|
|
90
|
+
db.addSnippet(snippet as any)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// List snippets by owner
|
|
94
|
+
const response = await axios.get("/api/snippets/list?owner_name=testuser")
|
|
95
|
+
expect(response.status).toBe(200)
|
|
96
|
+
expect(response.data.snippets).toHaveLength(1)
|
|
97
|
+
expect(response.data.snippets[0].unscoped_name).toBe("Snippet1")
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test("list starred snippets", async () => {
|
|
101
|
+
const { axios, db } = await getTestServer()
|
|
102
|
+
|
|
103
|
+
// Create some test snippets
|
|
104
|
+
const snippets = [
|
|
105
|
+
{
|
|
106
|
+
unscoped_name: "Snippet1",
|
|
107
|
+
owner_name: "testuser",
|
|
108
|
+
code: "Content1",
|
|
109
|
+
created_at: "2023-01-01T00:00:00Z",
|
|
110
|
+
updated_at: "2023-01-01T00:00:00Z",
|
|
111
|
+
name: "testuser/Snippet1",
|
|
112
|
+
snippet_type: "board",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
unscoped_name: "Snippet2",
|
|
116
|
+
owner_name: "otheruser",
|
|
117
|
+
code: "Content2",
|
|
118
|
+
created_at: "2023-01-02T00:00:00Z",
|
|
119
|
+
updated_at: "2023-01-02T00:00:00Z",
|
|
120
|
+
name: "otheruser/Snippet2",
|
|
121
|
+
snippet_type: "package",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
unscoped_name: "Snippet3",
|
|
125
|
+
owner_name: "thirduser",
|
|
126
|
+
code: "Content3",
|
|
127
|
+
created_at: "2023-01-03T00:00:00Z",
|
|
128
|
+
updated_at: "2023-01-03T00:00:00Z",
|
|
129
|
+
name: "thirduser/Snippet3",
|
|
130
|
+
snippet_type: "board",
|
|
131
|
+
},
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
const createdSnippets = []
|
|
135
|
+
for (const snippet of snippets) {
|
|
136
|
+
db.addSnippet(snippet as any)
|
|
137
|
+
// Get the snippet from the database to get its ID
|
|
138
|
+
const createdSnippet = db.packages.find(
|
|
139
|
+
(p) => p.unscoped_name === snippet.unscoped_name,
|
|
140
|
+
)
|
|
141
|
+
if (!createdSnippet) throw new Error("Failed to create snippet")
|
|
142
|
+
createdSnippets.push(createdSnippet)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Add stars for testuser
|
|
146
|
+
const testUserAccount = db.accounts.find(
|
|
147
|
+
(acc) => acc.github_username === "testuser",
|
|
148
|
+
)
|
|
149
|
+
if (!testUserAccount) throw new Error("testuser account not found")
|
|
150
|
+
|
|
151
|
+
// testuser stars Snippet2 and Snippet3
|
|
152
|
+
db.addStar(testUserAccount.account_id, createdSnippets[1].package_id) // Snippet2
|
|
153
|
+
db.addStar(testUserAccount.account_id, createdSnippets[2].package_id) // Snippet3
|
|
154
|
+
|
|
155
|
+
// Create a different user for the Authorization header
|
|
156
|
+
const otherUserAccount = db.addAccount({
|
|
157
|
+
github_username: "otheruser",
|
|
158
|
+
shippingInfo: {
|
|
159
|
+
firstName: "Other",
|
|
160
|
+
lastName: "User",
|
|
161
|
+
companyName: "Other Company",
|
|
162
|
+
address: "456 Other St",
|
|
163
|
+
apartment: "Apt 7C",
|
|
164
|
+
city: "Otherville",
|
|
165
|
+
state: "CA",
|
|
166
|
+
zipCode: "90001",
|
|
167
|
+
country: "United States of America",
|
|
168
|
+
phone: "555-987-6543",
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// List starred snippets for testuser
|
|
173
|
+
const response = await axios.get("/api/snippets/list?starred_by=testuser", {
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: `Bearer ${otherUserAccount.account_id}`,
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
expect(response.status).toBe(200)
|
|
179
|
+
expect(response.data.snippets).toHaveLength(2)
|
|
180
|
+
expect(
|
|
181
|
+
response.data.snippets
|
|
182
|
+
.map((s: { unscoped_name: string }) => s.unscoped_name)
|
|
183
|
+
.sort(),
|
|
184
|
+
).toEqual(["Snippet2", "Snippet3"])
|
|
185
|
+
|
|
186
|
+
// Verify star counts and is_starred flags
|
|
187
|
+
for (const snippet of response.data.snippets as Array<{
|
|
188
|
+
star_count: number
|
|
189
|
+
is_starred: boolean
|
|
190
|
+
}>) {
|
|
191
|
+
expect(snippet.star_count).toBe(1)
|
|
192
|
+
expect(snippet.is_starred).toBe(false) // Should be false because we're using otherUserAccount
|
|
193
|
+
}
|
|
194
|
+
})
|