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",
50 kind: "arvados#group",
51 modified_at: "2023-11-15T20:57:01.719986000Z",
52 modified_by_user_uuid: "zzzzz-tpzed-000000000000000",
54 owner_uuid: "zzzzz-tpzed-000000000000000",
59 "zzzzz-tpzed-000000000000000",
64 } else if (url === '/links') {
65 return Promise.resolve(
69 kind: "arvados#linkList",
74 return Promise.resolve(
80 await store.dispatch(dataExplorerActions.REQUEST_ITEMS({id: GROUPS_PANEL_ID}));
81 // Wait for async fetching of group count promises to resolve
82 await new Promise(setImmediate);
85 expect(axiosInst.get).to.be.calledThrice;
86 expect(axiosInst.get.getCall(0).args[0]).to.equal('/groups');
87 expect(axiosInst.get.getCall(0).args[1].params).to.deep.include({count: 'none'});
88 expect(axiosInst.get.getCall(1).args[0]).to.equal('/groups');
89 expect(axiosInst.get.getCall(1).args[1].params).to.deep.include({count: 'exact', limit: 0});
90 expect(axiosInst.get.getCall(2).args[0]).to.equal('/links');
91 const group = getResource(fakeUuid)(store.getState().resources);
92 expect(group?.memberCount).to.equal(234);
95 it('requests group member count and stores null on failure', async () => {
97 const fakeUuid = "zzzzz-j7d0g-000000000000000";
98 axiosInst.get = cy.spy((url) => {
99 if (url === '/groups') {
100 return Promise.resolve(
108 created_at: "2023-11-15T20:57:01.723043000Z",
111 etag: "0000000000000000000000000",
112 frozen_by_uuid: null,
115 kind: "arvados#group",
116 modified_at: "2023-11-15T20:57:01.719986000Z",
117 modified_by_user_uuid: "zzzzz-tpzed-000000000000000",
119 owner_uuid: "zzzzz-tpzed-000000000000000",
124 "zzzzz-tpzed-000000000000000",
129 } else if (url === '/links') {
130 return Promise.reject();
132 return Promise.resolve({ data: {}});
137 await store.dispatch(dataExplorerActions.REQUEST_ITEMS({id: GROUPS_PANEL_ID}));
138 // Wait for async fetching of group count promises to resolve
139 await new Promise(setImmediate);
142 expect(axiosInst.get).to.be.calledThrice;
143 expect(axiosInst.get.getCall(0).args[0]).to.equal('/groups');
144 expect(axiosInst.get.getCall(0).args[1].params).to.deep.include({count: 'none'});
145 expect(axiosInst.get.getCall(1).args[0]).to.equal('/groups');
146 expect(axiosInst.get.getCall(1).args[1].params).to.deep.include({count: 'exact', limit: 0});
147 expect(axiosInst.get.getCall(2).args[0]).to.equal('/links');
148 const group = getResource(fakeUuid)(store.getState().resources);
149 expect(group?.memberCount).to.equal(null);