Test - Updates ItemBaseClassService tests to inline with recent code changes
This commit is contained in:
parent
c123c034cf
commit
1cd4b055eb
@ -91,8 +91,9 @@ export class ItemBaseClassService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edge case, the cache is only generated for items with `_type === "Item"`, so return false for any other type
|
// The cache is only generated for item templates with `_type === "Item"`, so return false for any other type,
|
||||||
if (this.items[itemTpl]?._type !== "Item")
|
// including item templates that simply don't exist.
|
||||||
|
if (!this.cachedItemIsOfItemType(itemTpl))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -114,6 +115,16 @@ export class ItemBaseClassService
|
|||||||
return this.itemBaseClassesCache[itemTpl].some((x) => baseClasses.includes(x));
|
return this.itemBaseClassesCache[itemTpl].some((x) => baseClasses.includes(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if cached item template is of type Item
|
||||||
|
* @param itemTemplateId item to check
|
||||||
|
* @returns true if item is of type Item
|
||||||
|
*/
|
||||||
|
private cachedItemIsOfItemType(itemTemplateId: string): boolean
|
||||||
|
{
|
||||||
|
return this.items[itemTemplateId]?._type === "Item";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get base classes item inherits from
|
* Get base classes item inherits from
|
||||||
* @param itemTpl item to get base classes for
|
* @param itemTpl item to get base classes for
|
||||||
|
@ -42,23 +42,23 @@ describe("ItemBaseClassService", () =>
|
|||||||
it("should return false when the base item type is passed in", () =>
|
it("should return false when the base item type is passed in", () =>
|
||||||
{
|
{
|
||||||
// Remove item from base cache
|
// Remove item from base cache
|
||||||
const result = itemBaseClassService.itemHasBaseClass("54009119af1c881c07000029", []); // "Base item"
|
const result = itemBaseClassService.itemHasBaseClass("54009119af1c881c07000029", []);
|
||||||
|
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return true when an item is passed in", () =>
|
it("should return true when a med item is passed in with the meds base class", () =>
|
||||||
{
|
{
|
||||||
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
||||||
|
|
||||||
// Remove item from base cache
|
// Remove item from base cache
|
||||||
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
||||||
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]); // "Meds" type
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return true when an item and 2 matching base classes are passed in", () =>
|
it("should return true when an item and two matching base classes are passed in", () =>
|
||||||
{
|
{
|
||||||
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ describe("ItemBaseClassService", () =>
|
|||||||
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, [
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, [
|
||||||
"543be5664bdc2dd4348b4569",
|
"543be5664bdc2dd4348b4569",
|
||||||
"54009119af1c881c07000029",
|
"54009119af1c881c07000029",
|
||||||
]); // "Meds" and "Item" type
|
]); // "Meds" and "Item" base classes
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
@ -84,15 +84,28 @@ describe("ItemBaseClassService", () =>
|
|||||||
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
||||||
|
|
||||||
// Perform check
|
// Perform check
|
||||||
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]); // "Meds" type
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(hydrateItemBaseClassCacheSpy).toHaveBeenCalled();
|
expect(hydrateItemBaseClassCacheSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an exception when an invalid item is passed in", () =>
|
it("should return false for any item template ID that does not exist", () =>
|
||||||
{
|
{
|
||||||
expect(() => itemBaseClassService.itemHasBaseClass("fakeTpl", ["543be5664bdc2dd4348b4569"])).toThrowError();
|
const result = itemBaseClassService.itemHasBaseClass("not-a-valid-template-id", [
|
||||||
|
"543be5664bdc2dd4348b4569",
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false for any item template ID without the Item type ", () =>
|
||||||
|
{
|
||||||
|
const result = itemBaseClassService.itemHasBaseClass("54009119af1c881c07000029", [
|
||||||
|
"543be5664bdc2dd4348b4569",
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user