Guard source gear namespaces and retain recoverable legacy records (#9)
This commit is contained in:
1 parent
ab37006932
commit
e567910c04
23 files changed
+1203
-66
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EMPTY_ITEM_STATS } from "./itemStats";
|
||||
import { inventoryItemMatchesCategory, inventoryItemUsableForCategory, normalizeInventory } from "./lootTypes";
|
||||
|
||||
function savedItem(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return {
|
||||
instanceId: "gear:1",
|
||||
itemId: 1,
|
||||
itemKey: "gear-1",
|
||||
name: "Saved Gear",
|
||||
quality: "rare",
|
||||
inventorySlot: "back",
|
||||
armorType: null,
|
||||
weaponType: null,
|
||||
itemLevel: 20,
|
||||
sourceItemLevel: 20,
|
||||
stats: EMPTY_ITEM_STATS,
|
||||
quantity: 1,
|
||||
sourceBossKey: "source-boss",
|
||||
sourceBossName: "Source Boss",
|
||||
acquiredAt: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("inventory item game-category metadata", () => {
|
||||
it("migrates only category-less WoW-owned legacy records", () => {
|
||||
expect(normalizeInventory([savedItem()], { ownerCategory: "wow" })[0].contentCategory).toBe("wow");
|
||||
expect(normalizeInventory([savedItem()], { ownerCategory: "rom" })[0].contentCategory).toBeNull();
|
||||
expect(normalizeInventory([savedItem()], { ownerCategory: "coa" })[0].contentCategory).toBeNull();
|
||||
expect(normalizeInventory([savedItem()])[0].contentCategory).toBeNull();
|
||||
});
|
||||
|
||||
it("preserves explicit category identity, including mismatches and unresolved null", () => {
|
||||
expect(normalizeInventory([savedItem({ contentCategory: "rom" })], { ownerCategory: "wow" })[0].contentCategory)
|
||||
.toBe("rom");
|
||||
expect(normalizeInventory([savedItem({ contentCategory: "coa" })], { ownerCategory: "rom" })[0].contentCategory)
|
||||
.toBe("coa");
|
||||
expect(normalizeInventory([savedItem({ contentCategory: null })], { ownerCategory: "wow" })[0].contentCategory)
|
||||
.toBeNull();
|
||||
});
|
||||
|
||||
it("requires an explicit category and validated native payload for usable RoM gear", () => {
|
||||
const romNative = normalizeInventory([savedItem({
|
||||
contentCategory: "rom",
|
||||
stats: { ...EMPTY_ITEM_STATS, romNative: { strength: 7 } },
|
||||
})])[0];
|
||||
const romWithoutNative = normalizeInventory([savedItem({ contentCategory: "rom" })])[0];
|
||||
expect(inventoryItemMatchesCategory(romNative, "rom")).toBe(true);
|
||||
expect(inventoryItemMatchesCategory(romNative, undefined)).toBe(false);
|
||||
expect(inventoryItemUsableForCategory(romNative, "rom")).toBe(true);
|
||||
expect(inventoryItemUsableForCategory(romWithoutNative, "rom")).toBe(false);
|
||||
expect(inventoryItemUsableForCategory(romNative, "wow")).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user