chore(25-02): apply biome formatter to task 1 and 2 files

This commit is contained in:
2026-04-10 11:06:11 +02:00
parent e4a65314bd
commit fc9a9134e8
5 changed files with 195 additions and 151 deletions

View File

@@ -302,12 +302,17 @@ describe("MCP Catalog Tools", () => {
model: "PocketRocket 2",
sourceUrl: "https://www.cascadedesigns.com/msr/pocket-rocket-2",
imageCredit: "MSR Photography",
imageSourceUrl: "https://cdn.cascadedesigns.com/images/pocket-rocket-2.jpg",
imageSourceUrl:
"https://cdn.cascadedesigns.com/images/pocket-rocket-2.jpg",
});
const data = parseResult(result);
expect(data.sourceUrl).toBe("https://www.cascadedesigns.com/msr/pocket-rocket-2");
expect(data.sourceUrl).toBe(
"https://www.cascadedesigns.com/msr/pocket-rocket-2",
);
expect(data.imageCredit).toBe("MSR Photography");
expect(data.imageSourceUrl).toBe("https://cdn.cascadedesigns.com/images/pocket-rocket-2.jpg");
expect(data.imageSourceUrl).toBe(
"https://cdn.cascadedesigns.com/images/pocket-rocket-2.jpg",
);
});
test("bulk_upsert_catalog processes array and returns created/updated counts", async () => {
@@ -333,7 +338,10 @@ describe("MCP Catalog Tools", () => {
const tools = registerCatalogTools(db);
// Pre-create one item
await tools.upsert_catalog_item({ brand: "Revelate Designs", model: "Terrapin System" });
await tools.upsert_catalog_item({
brand: "Revelate Designs",
model: "Terrapin System",
});
const result = await tools.bulk_upsert_catalog({
items: [
@@ -348,7 +356,9 @@ describe("MCP Catalog Tools", () => {
});
test("catalog tool definitions include attribution fields in inputSchema", () => {
const { catalogToolDefinitions } = require("../../src/server/mcp/tools/catalog.ts");
const {
catalogToolDefinitions,
} = require("../../src/server/mcp/tools/catalog.ts");
const upsertDef = catalogToolDefinitions.find(
(d: { name: string }) => d.name === "upsert_catalog_item",
);

View File

@@ -112,136 +112,139 @@ describe("Global Item Routes", () => {
});
describe("POST /api/global-items", () => {
it("returns 200 with item and created=true on new item", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ brand: "Revelate Designs", model: "Terrapin System" }),
});
expect(res.status).toBe(200);
it("returns 200 with item and created=true on new item", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
brand: "Revelate Designs",
model: "Terrapin System",
}),
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.item.brand).toBe("Revelate Designs");
expect(body.item.model).toBe("Terrapin System");
expect(body.created).toBe(true);
const body = await res.json();
expect(body.item.brand).toBe("Revelate Designs");
expect(body.item.model).toBe("Terrapin System");
expect(body.created).toBe(true);
});
it("returns 200 with created=false when upserting existing item", async () => {
await insertGlobalItem(db, "Revelate Designs", "Terrapin System");
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
brand: "Revelate Designs",
model: "Terrapin System",
description: "Updated description",
}),
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.created).toBe(false);
expect(body.item.description).toBe("Updated description");
});
it("returns 400 when brand is missing", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: "Terrapin System" }),
});
expect(res.status).toBe(400);
});
it("returns 400 when model is missing", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ brand: "Revelate Designs" }),
});
expect(res.status).toBe(400);
});
});
it("returns 200 with created=false when upserting existing item", async () => {
await insertGlobalItem(db, "Revelate Designs", "Terrapin System");
describe("POST /api/global-items/bulk", () => {
it("returns 200 with created/updated counts", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ brand: "Apidura", model: "Handlebar Pack" },
],
}),
});
expect(res.status).toBe(200);
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
brand: "Revelate Designs",
model: "Terrapin System",
description: "Updated description",
}),
const body = await res.json();
expect(body.created).toBe(2);
expect(body.updated).toBe(0);
expect(body.items).toHaveLength(2);
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.created).toBe(false);
expect(body.item.description).toBe("Updated description");
it("returns correct counts for mix of new and existing items", async () => {
await insertGlobalItem(db, "Revelate Designs", "Terrapin System");
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ brand: "Apidura", model: "Handlebar Pack" },
],
}),
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.created).toBe(1);
expect(body.updated).toBe(1);
});
it("returns 400 when items array is empty", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items: [] }),
});
expect(res.status).toBe(400);
});
it("returns 400 when items array exceeds 100", async () => {
const items = Array.from({ length: 101 }, (_, i) => ({
brand: `Brand${i}`,
model: `Model${i}`,
}));
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
});
expect(res.status).toBe(400);
});
it("returns 400 for invalid item in array (missing brand)", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ model: "Invalid Item without brand" },
],
}),
});
expect(res.status).toBe(400);
});
});
it("returns 400 when brand is missing", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: "Terrapin System" }),
});
expect(res.status).toBe(400);
});
it("returns 400 when model is missing", async () => {
const res = await app.request("/api/global-items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ brand: "Revelate Designs" }),
});
expect(res.status).toBe(400);
});
});
describe("POST /api/global-items/bulk", () => {
it("returns 200 with created/updated counts", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ brand: "Apidura", model: "Handlebar Pack" },
],
}),
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.created).toBe(2);
expect(body.updated).toBe(0);
expect(body.items).toHaveLength(2);
});
it("returns correct counts for mix of new and existing items", async () => {
await insertGlobalItem(db, "Revelate Designs", "Terrapin System");
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ brand: "Apidura", model: "Handlebar Pack" },
],
}),
});
expect(res.status).toBe(200);
const body = await res.json();
expect(body.created).toBe(1);
expect(body.updated).toBe(1);
});
it("returns 400 when items array is empty", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items: [] }),
});
expect(res.status).toBe(400);
});
it("returns 400 when items array exceeds 100", async () => {
const items = Array.from({ length: 101 }, (_, i) => ({
brand: `Brand${i}`,
model: `Model${i}`,
}));
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
});
expect(res.status).toBe(400);
});
it("returns 400 for invalid item in array (missing brand)", async () => {
const res = await app.request("/api/global-items/bulk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
items: [
{ brand: "Revelate Designs", model: "Terrapin System" },
{ model: "Invalid Item without brand" },
],
}),
});
expect(res.status).toBe(400);
});
});
describe("GET /api/global-items/:id", () => {
describe("GET /api/global-items/:id", () => {
it("returns item with ownerCount", async () => {
const gi = await insertGlobalItem(db, "MSR", "PocketRocket 2");