imrishabh18/rp2040-motor-controller
This circuit incorporates a USB-C Power Delivery (PD) interface with a CH224K controller, a WJ500V-5.08-04P motor output connector, multiple power conditioning components including capacitors, resistors, diodes, and an RP2040 microcontroller, to manage motor control, signal routing, and power management for a USB-powered stepper motor system.
- Version
- 1.0.14
- License
- unset
- Stars
- 0
tests/jlcpcb-stock-audit.test.ts
import { expect, test } from "bun:test";
import { parseJlcProduct } from "../scripts/audit-jlcpcb-stock.mjs";
const product = {
componentCode: "C42377749",
componentModelEn: "WJ500V-5.08-04P-14-00A",
componentBrandEn: "Ningbo Kangnex Elec",
componentSpecificationEn: "Plugin,P=5.08mm",
overseasStockCount: 150,
canPresaleNumber: 0,
isBuyComponent: "1",
preMinPurchaseNum: 28,
};
const page = (chunks: string[]) =>
chunks.map((chunk) => `<script>self.__next_f.push(${JSON.stringify([1, chunk])})</script>`).join("");
test("keeps displayed stock separate from available order quantity", () => {
const result = parseJlcProduct(page([`73:${JSON.stringify(product)}\n`]), "C42377749");
expect(result.displayedStock).toBe(150);
expect(result.orderableStock).toBe(0);
expect(result.preorderMinimum).toBe(28);
});
test("ignores price records and other suggested components", () => {
const stream = `1:${JSON.stringify({ componentCode: "C42377749", productPrice: 0.3 })}\n` +
`2:${JSON.stringify({ ...product, componentCode: "C123", canPresaleNumber: 1000 })}\n` +
`3:${JSON.stringify(product)}\n`;
expect(parseJlcProduct(page([stream]), "C42377749").orderableStock).toBe(0);
});
test("reassembles records split between script chunks", () => {
const stream = `73:${JSON.stringify(product)}\n`;
expect(parseJlcProduct(page([stream.slice(0, 80), stream.slice(80)]), "C42377749").displayedStock).toBe(150);
});
test("fails closed instead of assuming missing stock means available", () => {
expect(() => parseJlcProduct(page([`73:${JSON.stringify(product)}\n`]), "C2040")).toThrow();
expect(() => parseJlcProduct("<html>Service unavailable</html>", "C2040")).toThrow();
});