21221: Add unit test for failed group member count request 21221-groups-panel-member-count
authorStephen Smith <stephen@curii.com>
Fri, 1 Mar 2024 20:17:07 +0000 (15:17 -0500)
committerStephen Smith <stephen@curii.com>
Fri, 1 Mar 2024 20:17:07 +0000 (15:17 -0500)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

services/workbench2/src/store/groups-panel/groups-panel-middleware-service.test.ts

index 810bc74bdf99e7416112e20b80dcf94bd86eef15..42d88a9a8eb441f09f25b33c9556503a048df85d 100644 (file)
@@ -101,4 +101,60 @@ describe("GroupsPanelMiddlewareService", () => {
         expect(group?.memberCount).toBe(234);
     });
 
+    it('requests group member count and stores null on failure', async () => {
+        // Given
+        const fakeUuid = "zzzzz-j7d0g-000000000000000";
+        axiosInst.get = jest.fn((url: string) => {
+            if (url === '/groups') {
+                return Promise.resolve(
+                    { data: {
+                        kind: "",
+                        offset: 0,
+                        limit: 100,
+                        items: [{
+                            can_manage: true,
+                            can_write: true,
+                            created_at: "2023-11-15T20:57:01.723043000Z",
+                            delete_at: null,
+                            description: null,
+                            etag: "0000000000000000000000000",
+                            frozen_by_uuid: null,
+                            group_class: "role",
+                            href: `/groups/${fakeUuid}`,
+                            is_trashed: false,
+                            kind: "arvados#group",
+                            modified_at: "2023-11-15T20:57:01.719986000Z",
+                            modified_by_client_uuid: null,
+                            modified_by_user_uuid: "zzzzz-tpzed-000000000000000",
+                            name: "Test Group",
+                            owner_uuid: "zzzzz-tpzed-000000000000000",
+                            properties: {},
+                            trash_at: null,
+                            uuid: fakeUuid,
+                            writable_by: [
+                                "zzzzz-tpzed-000000000000000",
+                            ]
+                        }],
+                        items_available: 1,
+                    }} as AxiosResponse);
+            } else if (url === '/links') {
+                return Promise.reject();
+            } else {
+                return Promise.resolve({ data: {}} as AxiosResponse);
+            }
+        });
+
+        // When
+        await store.dispatch(dataExplorerActions.REQUEST_ITEMS({id: GROUPS_PANEL_ID}));
+        // Wait for async fetching of group count promises to resolve
+        await new Promise(setImmediate);
+
+        // Expect
+        expect(axiosInst.get).toHaveBeenCalledTimes(2);
+        expect(axiosInst.get).toHaveBeenCalledWith('/groups', expect.anything());
+        expect(axiosInst.get).toHaveBeenCalledWith('/links', expect.anything());
+        const group = getResource<GroupResource>(fakeUuid)(store.getState().resources);
+        expect(group?.memberCount).toBe(null);
+    });
+
 });