20225: Mock group contents service to squelch errors in unit tests
authorStephen Smith <stephen@curii.com>
Thu, 12 Oct 2023 20:07:57 +0000 (16:07 -0400)
committerStephen Smith <stephen@curii.com>
Thu, 12 Oct 2023 20:07:57 +0000 (16:07 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/store/tree-picker/tree-picker-actions.test.ts

index b1c42409ecc606fb307f67b3d72610a54f8a23cf..9622282c4fcb02414401006eb3e357b9b2569d22 100644 (file)
@@ -14,6 +14,8 @@ import { SHARED_PROJECT_ID, initProjectsTreePicker } from "./tree-picker-actions
 import { CollectionResource } from "models/collection";
 import { GroupResource } from "models/group";
 import { CollectionDirectory, CollectionFile, CollectionFileType } from "models/collection-file";
+import { GroupContentsResource } from "services/groups-service/groups-service";
+import { ListResults } from "services/common-service/common-service";
 
 describe('tree-picker-actions', () => {
     const axiosInst = Axios.create({ headers: {} });
@@ -123,6 +125,11 @@ describe('tree-picker-actions', () => {
             return fakeResources[uuid]?.files || [];
         });
 
+        services.groupsService.contents = jest.fn(async (uuid, args) => {
+            const items = Object.keys(fakeResources).map(uuid => ({...fakeResources[uuid], uuid})).filter(item => item.ownerUuid === uuid);
+            return {items: items as GroupContentsResource[], itemsAvailable: items.length} as ListResults<GroupContentsResource>;
+        });
+
         const pickerId = "pickerId";
 
         // When collection preselected