|
|
|
|
@@ -536,9 +536,15 @@ describe("listGlobalItemsForAdmin", () => {
|
|
|
|
|
|
|
|
|
|
it("filters by query string (brand/model)", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db, "Salsa", "salsa");
|
|
|
|
|
await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Woodsmoke 700" });
|
|
|
|
|
await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Woodsmoke 700",
|
|
|
|
|
});
|
|
|
|
|
const mfr2 = await insertManufacturer(db, "Apidura", "apidura");
|
|
|
|
|
await insertGlobalItem(db, { manufacturerId: mfr2.id, model: "Racing Saddle Bag" });
|
|
|
|
|
await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr2.id,
|
|
|
|
|
model: "Racing Saddle Bag",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listGlobalItemsForAdmin(db, { query: "salsa" });
|
|
|
|
|
expect(result.items).toHaveLength(1);
|
|
|
|
|
@@ -547,7 +553,10 @@ describe("listGlobalItemsForAdmin", () => {
|
|
|
|
|
|
|
|
|
|
it("includes tags and ownerCount per item", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Test Item" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Test Item",
|
|
|
|
|
});
|
|
|
|
|
const tag = await insertTag(db, "bikepacking");
|
|
|
|
|
await tagGlobalItem(db, globalItem.id, tag.id!);
|
|
|
|
|
|
|
|
|
|
@@ -556,7 +565,9 @@ describe("listGlobalItemsForAdmin", () => {
|
|
|
|
|
.insert(schema.users)
|
|
|
|
|
.values({ logtoSub: "test-sub" })
|
|
|
|
|
.returning();
|
|
|
|
|
await insertItem(db, "My Test Item", user!.id, { globalItemId: globalItem.id });
|
|
|
|
|
await insertItem(db, "My Test Item", user!.id, {
|
|
|
|
|
globalItemId: globalItem.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listGlobalItemsForAdmin(db);
|
|
|
|
|
expect(result.items).toHaveLength(1);
|
|
|
|
|
@@ -579,7 +590,10 @@ describe("updateGlobalItemById", () => {
|
|
|
|
|
|
|
|
|
|
it("updates model field by id", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Original" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Original",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await updateGlobalItemById(db, globalItem.id, { model: "Updated" });
|
|
|
|
|
|
|
|
|
|
@@ -589,9 +603,14 @@ describe("updateGlobalItemById", () => {
|
|
|
|
|
|
|
|
|
|
it("syncs tags when tags array provided", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Tagged Item" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Tagged Item",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await updateGlobalItemById(db, globalItem.id, { tags: ["cycling", "gravel"] });
|
|
|
|
|
await updateGlobalItemById(db, globalItem.id, {
|
|
|
|
|
tags: ["cycling", "gravel"],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listGlobalItemsForAdmin(db);
|
|
|
|
|
const found = result.items.find((i) => i.id === globalItem.id);
|
|
|
|
|
@@ -614,7 +633,10 @@ describe("deleteGlobalItem", () => {
|
|
|
|
|
|
|
|
|
|
it("deletes item and returns true", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "To Delete" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "To Delete",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await deleteGlobalItem(db, globalItem.id);
|
|
|
|
|
expect(result).toBe(true);
|
|
|
|
|
@@ -625,12 +647,17 @@ describe("deleteGlobalItem", () => {
|
|
|
|
|
|
|
|
|
|
it("nullifies items.globalItemId before deleting", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Owned Item" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Owned Item",
|
|
|
|
|
});
|
|
|
|
|
const [user] = await db
|
|
|
|
|
.insert(schema.users)
|
|
|
|
|
.values({ logtoSub: "delete-test-sub" })
|
|
|
|
|
.returning();
|
|
|
|
|
const userItem = await insertItem(db, "User Item", user!.id, { globalItemId: globalItem.id });
|
|
|
|
|
const userItem = await insertItem(db, "User Item", user!.id, {
|
|
|
|
|
globalItemId: globalItem.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await deleteGlobalItem(db, globalItem.id);
|
|
|
|
|
|
|
|
|
|
@@ -643,7 +670,10 @@ describe("deleteGlobalItem", () => {
|
|
|
|
|
|
|
|
|
|
it("removes globalItemTags before deleting", async () => {
|
|
|
|
|
const mfr = await insertManufacturer(db);
|
|
|
|
|
const globalItem = await insertGlobalItem(db, { manufacturerId: mfr.id, model: "Tagged Delete" });
|
|
|
|
|
const globalItem = await insertGlobalItem(db, {
|
|
|
|
|
manufacturerId: mfr.id,
|
|
|
|
|
model: "Tagged Delete",
|
|
|
|
|
});
|
|
|
|
|
const tag = await insertTag(db, "delete-tag");
|
|
|
|
|
await tagGlobalItem(db, globalItem.id, tag.id!);
|
|
|
|
|
|
|
|
|
|
|