注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
createUser を使用して、ユーザーの部分的なモックを作成できます。id と username 以外のすべてのプロパティは任意です。"@foundry/functions-testing-lib" から { createUser } をインポートする必要があります。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17import { MyFunctions } from ".." import { verifyOntologyEditFunction, createGroup, createUser } from "@foundry/functions-testing-lib"; describe("example test suite", () => { const myFunctions = new MyFunctions(); test("test users and groups", async () => { const group = createGroup({ id: "groupId", }); const user = createUser({ id: "userId", username: "username", }); await expect(myFunctions.searchUsers("userId", "groupId")).resolves.toEqual([user, group]); }); });
これを使用して、次の関数をテストできます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12import { Function, OntologyEditFunction, Users, Group, Principal } from "@foundry/functions-api"; export class MyFunctions { @Function() public async searchUsers(userId: string, groupId: string): Promise<Principal[]> { const existingPrincipals = await Promise.all([ Users.getUserByIdAsync(userId), Users.getGroupByIdAsync(groupId), ]); return existingPrincipals.filter(r => !!r).map(r => r!); } }
createGroup を使用して、グループの部分的なモックも作成できます。id 以外のすべてのプロパティは任意です。"@foundry/functions-testing-lib" から { createGroup } をインポートする必要があります。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13import { MyFunctions } from ".." import { verifyOntologyEditFunction, createGroup } from "@foundry/functions-testing-lib"; describe("example test suite", () => { const myFunctions = new MyFunctions(); test("test groups", async () => { const group = createGroup({ id: "groupId", }); await expect(myFunctions.searchGroups("groupId")).resolves.toEqual([group]); }); });
これを使用して、次の関数をテストできます。
Copied!1 2 3 4 5 6 7 8 9 10 11import { Function, OntologyEditFunction, Users, Group, Principal } from "@foundry/functions-api"; export class MyFunctions { @Function() public async searchGroups(groupId: string): Promise<Principal[]> { const existingPrincipals = await Promise.all([ Users.getGroupByIdAsync(groupId), ]); return existingPrincipals.filter(r => !!r).map(r => r!); } }