1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import Axios from "axios";
6 import { mockConfig } from "common/config";
7 import { createBrowserHistory } from "history";
8 import { dataExplorerActions } from "store/data-explorer/data-explorer-action";
9 import { GROUPS_PANEL_ID } from "./groups-panel-actions";
10 import { configureStore } from "store/store";
11 import { createServices } from "services/services";
12 import { getResource } from "store/resources/resources";
14 describe("GroupsPanelMiddlewareService", () => {
20 progressFn: (id, working) => { },
21 errorFn: (id, message) => { }
25 axiosInst = Axios.create({ headers: {} });
26 services = createServices(mockConfig({}), actions, axiosInst);
27 store = configureStore(createBrowserHistory(), services, config);
30 it("requests group member counts and updates resource store", async () => {
32 const fakeUuid = "zzzzz-j7d0g-000000000000000";
33 axiosInst.get = cy.spy((url) => {
34 if (url === '/groups') {
35 return Promise.resolve(
43 created_at: "2023-11-15T20:57:01.723043000Z",
46 etag: "0000000000000000000000000",
49 href: `/groups/${fakeUuid}`,
51 kind: "arvados#group",
52 modified_at: "2023-11-15T20:57:01.719986000Z",
53 modified_by_user_uuid: "zzzzz-tpzed-000000000000000",
55 owner_uuid: "zzzzz-tpzed-000000000000000",
60 "zzzzz-tpzed-000000000000000",
65 } else if (url === '/links') {
66 return Promise.resolve(
70 kind: "arvados#linkList",
75 return Promise.resolve(
81 await store.dispatch(dataExplorerActions.REQUEST_ITEMS({id: GROUPS_PANEL_ID}));
82 // Wait for async fetching of group count promises to resolve
83 await new Promise(setImmediate);
86 expect(axiosInst.get).toHaveBeenCalledTimes(3);
87 expect(axiosInst.get).toHaveBeenNthCalledWith(1, '/groups', {
88 params: expect.objectContaining({
92 expect(axiosInst.get).toHaveBeenNthCalledWith(2, '/groups', {
93 params: expect.objectContaining({
98 expect(axiosInst.get).toHaveBeenCalledWith('/links', expect.anything());
99 const group = getResource<GroupResource>(fakeUuid)(store.getState().resources);
100 expect(group?.memberCount).toBe(234);
103 it('requests group member count and stores null on failure', async () => {
105 const fakeUuid = "zzzzz-j7d0g-000000000000000";
106 axiosInst.get = cy.spy((url) => {
107 if (url === '/groups') {
108 return Promise.resolve(
116 created_at: "2023-11-15T20:57:01.723043000Z",
119 etag: "0000000000000000000000000",
120 frozen_by_uuid: null,
122 href: `/groups/${fakeUuid}`,
124 kind: "arvados#group",
125 modified_at: "2023-11-15T20:57:01.719986000Z",
126 modified_by_user_uuid: "zzzzz-tpzed-000000000000000",
128 owner_uuid: "zzzzz-tpzed-000000000000000",
133 "zzzzz-tpzed-000000000000000",
138 } else if (url === '/links') {
139 return Promise.reject();
141 return Promise.resolve({ data: {}});
146 await store.dispatch(dataExplorerActions.REQUEST_ITEMS({id: GROUPS_PANEL_ID}));
147 // Wait for async fetching of group count promises to resolve
148 await new Promise(setImmediate);
151 expect(axiosInst.get).toHaveBeenCalledTimes(3);
152 expect(axiosInst.get).toHaveBeenNthCalledWith(1, '/groups', {
153 params: expect.objectContaining({
157 expect(axiosInst.get).toHaveBeenNthCalledWith(2, '/groups', {
158 params: expect.objectContaining({
163 expect(axiosInst.get).toHaveBeenCalledWith('/links', expect.anything());
164 const group = getResource<GroupResource>(fakeUuid)(store.getState().resources);
165 expect(group?.memberCount).toBe(null);