-
Notifications
You must be signed in to change notification settings - Fork 47
Add is_extended_promotional filter to components and search #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ test("GET /api/search with search query 'STM32F401RCT6' returns expected compone | |
| expect(component).toHaveProperty("package") | ||
| expect(component).toHaveProperty("price") | ||
| expect(component).toHaveProperty("stock") | ||
| expect(component).toHaveProperty("is_extended_promotional") | ||
| }) | ||
|
|
||
| test("GET /api/search with search query '555 Timer' returns expected components", async () => { | ||
|
|
@@ -107,3 +108,33 @@ test("GET /api/search supports '0402 LED'", async () => { | |
| expect(res.data.components.every((c: any) => c.package === "0402")).toBe(true) | ||
| expect(res.data.components.some((c: any) => c.lcsc === 965793)).toBe(true) | ||
| }) | ||
|
|
||
| test("GET /api/search supports is_extended_promotional filter", async () => { | ||
| const { axios } = await getTestServer() | ||
| const allRes = await axios.get("/api/search?full=true&limit=200") | ||
| const filteredRes = await axios.get( | ||
| "/api/search?full=true&limit=200&is_extended_promotional=true", | ||
| ) | ||
|
|
||
| const allComponents = allRes.data.components as Array<{ | ||
| basic: number | ||
| preferred: number | ||
| is_extended_promotional: number | ||
| }> | ||
| const filteredComponents = filteredRes.data.components as Array<{ | ||
| basic: number | ||
| preferred: number | ||
| is_extended_promotional: number | ||
| }> | ||
|
|
||
| for (const component of allComponents) { | ||
| const expected = component.preferred === 1 && component.basic === 0 ? 1 : 0 | ||
| expect(component.is_extended_promotional).toBe(expected) | ||
| } | ||
|
|
||
| for (const component of filteredComponents) { | ||
| expect(component.is_extended_promotional).toBe(1) | ||
| expect(component.preferred).toBe(1) | ||
| expect(component.basic).toBe(0) | ||
| } | ||
| }) | ||
|
Comment on lines
+112
to
+140
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test file violates the rule that a *.test.ts file may have AT MOST one test(...) function. The file already contains multiple test functions, and this modification adds another test function starting at line 112. According to the rule, after the first test, additional tests should be split into multiple, numbered files (e.g., search1.test.ts, search2.test.ts). To fix this, create a new file like search2.test.ts and move this new test function there. Spotted by Graphite (based on custom rule: Custom rule) |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { test, expect } from "bun:test" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { expect, test } from "bun:test" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getTestServer } from "tests/fixtures/get-test-server" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test("GET /components/list with json param returns component data", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { axios } = await getTestServer() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const res = await axios.get("/components/list?json=true") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(res.data).toHaveProperty("components") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(Array.isArray(res.data.components)).toBe(true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (res.data.components.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(res.data.components[0]).toHaveProperty("is_extended_promotional") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof res.data.components[0].is_extended_promotional).toBe( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "boolean", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test("GET /components/list supports is_extended_promotional filter", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { axios } = await getTestServer() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const allRes = await axios.get("/components/list?json=true&full=true") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filteredRes = await axios.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/components/list?json=true&full=true&is_extended_promotional=true", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const allComponents = allRes.data.components as Array<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| basic: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| preferred: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_extended_promotional: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filteredComponents = filteredRes.data.components as Array<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| basic: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| preferred: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_extended_promotional: number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const component of allComponents) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const expected = component.preferred === 1 && component.basic === 0 ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(component.is_extended_promotional).toBe(expected) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const component of filteredComponents) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(component.is_extended_promotional).toBe(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(component.preferred).toBe(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(component.basic).toBe(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type mismatch: tests expect numeric values (0/1) but API returns booleans. The route transforms all flags with // Current (broken):
component.preferred === 1 // false === 1 → false
component.basic === 0 // true === 0 → false
// Should be:
component.preferred === true
component.basic === false
component.is_extended_promotional === true
// And type should be:
type Component = {
basic: boolean
preferred: boolean
is_extended_promotional: boolean
}
Suggested change
Spotted by Graphite This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch: tests expect numeric values (0/1) but API returns booleans. The route transforms all flags with
Boolean()(line 81-93 in search.tsx), sois_extended_promotional,basic, andpreferredwill betrue/falsein responses, not0/1. This causes test failures:Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.
This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.