Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dovrosenberg committed Dec 10, 2024
1 parent a44e98f commit 3d4e023
Showing 1 changed file with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { expectTypeOf } from "vitest";
import type { DeepPartial } from "../../../../../src/types/utils.d.mts";
// import type Document from "../../../../../src/foundry/common/abstract/document.d.mts";
import "../../../../../src/foundry/client/data/collections/compendium-collection.d.mts";
import "../../../../../src/foundry/client/data/abstract/document-collection.d.mts";
import "../../../../../src/foundry/client/data/documents/journal-entry.d.mts";
import "../../../../../src/foundry/client/data/documents/item.d.mts";

import type Document from "../../../../../src/foundry/common/abstract/document.d.mts";

const compendiumCollection = await CompendiumCollection.createCompendium({
type: "JournalEntry" as const,
Expand Down Expand Up @@ -43,7 +38,7 @@ const compendium2 = new CompendiumCollection(constructorMetadata);
expectTypeOf(compendium2).toEqualTypeOf<CompendiumCollection<CompendiumCollection.Metadata>>();
expectTypeOf(compendium2.metadata).toEqualTypeOf<CompendiumCollection.Metadata>();

// expectTypeOf(compendiumCollection.get("", { strict: true })).toEqualTypeOf<Document.Stored<JournalEntry>>();
expectTypeOf(compendiumCollection.get("", { strict: true })).toEqualTypeOf<Document.Stored<JournalEntry>>();
// expectTypeOf(compendiumCollection.toJSON()).toEqualTypeOf<
// Array<Document.Stored<foundry.documents.BaseJournalEntry>["_source"]>
// >();
Expand All @@ -65,22 +60,22 @@ expectTypeOf((await compendiumCollection.getIndex()).get("some id", { strict: tr

expectTypeOf(compendiumCollection.documentClass).toEqualTypeOf<typeof JournalEntry>();

// const itemCollection = new CompendiumCollection({
// ...metadata,
// type: "Item" as const,
// index: new foundry.utils.Collection(),
// folders: [],
// });
// expectTypeOf((await itemCollection.getIndex()).get("some id", { strict: true })).toEqualTypeOf<
// { _id: string; uuid: string } & DeepPartial<foundry.documents.BaseItem["_source"]>
// >();
// expectTypeOf(
// (await itemCollection.getIndex({ fields: ["name", "effects", "system"] })).get("some id", { strict: true }),
// ).toEqualTypeOf<{ _id: string; uuid: string } & DeepPartial<foundry.documents.BaseItem["_source"]>>();
const itemCollection = new CompendiumCollection({
...metadata,
type: "Item" as const,
index: new foundry.utils.Collection(),
folders: [],
});
expectTypeOf((await itemCollection.getIndex()).get("some id", { strict: true })).toEqualTypeOf<
{ _id: string; uuid: string } & DeepPartial<foundry.documents.BaseItem["_source"]>
>();
expectTypeOf(
(await itemCollection.getIndex({ fields: ["name", "effects", "system"] })).get("some id", { strict: true }),
).toEqualTypeOf<{ _id: string; uuid: string } & DeepPartial<foundry.documents.BaseItem["_source"]>>();

// expectTypeOf(await itemCollection.getDocuments()).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items
// expectTypeOf(await itemCollection.getDocuments({})).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items
// expectTypeOf(await itemCollection.getDocuments({ name: "foo" })).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items called "foo"
// expectTypeOf(
// await itemCollection.getDocuments({ $or: [{ name: "baz" }, { name: "bar" }], effects: { $size: 2 } }), // only get items called "baz" or "bar" that have exactly 2 effects
// ).toEqualTypeOf<Document.Stored<Item>[]>();
expectTypeOf(await itemCollection.getDocuments()).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items
expectTypeOf(await itemCollection.getDocuments({})).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items
expectTypeOf(await itemCollection.getDocuments({ name: "foo" })).toEqualTypeOf<Document.Stored<Item>[]>(); // get all items called "foo"
expectTypeOf(
await itemCollection.getDocuments({ $or: [{ name: "baz" }, { name: "bar" }], effects: { $size: 2 } }), // only get items called "baz" or "bar" that have exactly 2 effects
).toEqualTypeOf<Document.Stored<Item>[]>();

0 comments on commit 3d4e023

Please sign in to comment.