@tscircuit/fake-snippets 0.0.92 → 0.0.94

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.
@@ -160,18 +160,35 @@ async function handleCustomPackageHtml(req, res) {
160
160
  throw new Error("Invalid author/package URL")
161
161
  }
162
162
 
163
- const { package: packageInfo } = await ky
163
+ const packageNotFoundHtml = getHtmlWithModifiedSeoTags({
164
+ title: "Package Not Found - tscircuit",
165
+ description: `The package ${author}/${unscopedPackageName} could not be found.`,
166
+ canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(unscopedPackageName)}`,
167
+ })
168
+ const packageDetails = await ky
164
169
  .get(`${REGISTRY_URL}/packages/get`, {
165
170
  searchParams: {
166
171
  name: `${author}/${unscopedPackageName}`,
167
172
  },
168
173
  })
169
174
  .json()
175
+ .catch((e) => {
176
+ if (String(e).includes("404")) {
177
+ return null
178
+ }
179
+ throw e
180
+ })
170
181
 
171
- if (!packageInfo) {
172
- throw new Error("Package not found")
182
+ if (!packageDetails) {
183
+ res.setHeader("Content-Type", "text/html; charset=utf-8")
184
+ res.setHeader("Cache-Control", cacheControlHeader)
185
+ res.setHeader("Vary", "Accept-Encoding")
186
+ res.status(404).send(packageNotFoundHtml)
187
+ return
173
188
  }
174
189
 
190
+ const { package: packageInfo } = packageDetails
191
+
175
192
  let packageRelease = null
176
193
  let packageFiles = null
177
194
  try {
@@ -15,3 +15,28 @@ test("get datasheet", async () => {
15
15
  expect(res.status).toBe(200)
16
16
  expect(res.data.datasheet.datasheet_id).toBe(id)
17
17
  })
18
+
19
+ test("get datasheet by chip name", async () => {
20
+ const { axios } = await getTestServer()
21
+ const create = await axios.post("/api/datasheets/create", {
22
+ chip_name: "Chip1",
23
+ })
24
+
25
+ const res = await axios.get("/api/datasheets/get", {
26
+ params: { chip_name: "Chip1" },
27
+ })
28
+
29
+ expect(res.status).toBe(200)
30
+ expect(res.data.datasheet.datasheet_id).toBe(
31
+ create.data.datasheet.datasheet_id,
32
+ )
33
+ })
34
+
35
+ test("get datasheet by chip name 404", async () => {
36
+ const { axios } = await getTestServer()
37
+ const res = await axios.get("/api/datasheets/get", {
38
+ params: { chip_name: "Missing" },
39
+ validateStatus: () => true,
40
+ })
41
+ expect(res.status).toBe(404)
42
+ })
@@ -0,0 +1,49 @@
1
+ import { getTestServer } from "bun-tests/fake-snippets-api/fixtures/get-test-server"
2
+ import { test, expect } from "bun:test"
3
+
4
+ // Test listing datasheets by chip name
5
+
6
+ test("list datasheets", async () => {
7
+ const { axios } = await getTestServer()
8
+
9
+ await axios.post("/api/datasheets/create", { chip_name: "Chip" })
10
+ await axios.post("/api/datasheets/create", { chip_name: "Chip" })
11
+ await axios.post("/api/datasheets/create", { chip_name: "Other" })
12
+
13
+ const res = await axios.get("/api/datasheets/list", {
14
+ params: { chip_name: "Chip" },
15
+ })
16
+
17
+ expect(res.status).toBe(200)
18
+ expect(res.data.datasheets).toHaveLength(2)
19
+ expect(res.data.datasheets.every((d: any) => d.chip_name === "Chip")).toBe(
20
+ true,
21
+ )
22
+ })
23
+
24
+ test("list datasheets is_popular returns all", async () => {
25
+ const { axios } = await getTestServer()
26
+
27
+ await axios.post("/api/datasheets/create", { chip_name: "Chip" })
28
+ await axios.post("/api/datasheets/create", { chip_name: "Other" })
29
+
30
+ const res = await axios.get("/api/datasheets/list", {
31
+ params: { is_popular: true },
32
+ })
33
+
34
+ expect(res.status).toBe(200)
35
+ expect(res.data.datasheets).toHaveLength(2)
36
+ })
37
+
38
+ test("list datasheets empty", async () => {
39
+ const { axios } = await getTestServer()
40
+
41
+ await axios.post("/api/datasheets/create", { chip_name: "Other" })
42
+
43
+ const res = await axios.get("/api/datasheets/list", {
44
+ params: { chip_name: "Chip" },
45
+ })
46
+
47
+ expect(res.status).toBe(200)
48
+ expect(res.data.datasheets).toHaveLength(0)
49
+ })