diff --git a/src/components/Admin/AdminSearchForm.jsx b/src/components/Admin/AdminSearchForm.jsx
index a07623befb..ac4049d765 100644
--- a/src/components/Admin/AdminSearchForm.jsx
+++ b/src/components/Admin/AdminSearchForm.jsx
@@ -122,10 +122,10 @@ class AdminSearchForm extends React.Component {
{groups.map(group => (
))}
diff --git a/src/components/Admin/__snapshots__/Admin.test.jsx.snap b/src/components/Admin/__snapshots__/Admin.test.jsx.snap
index 37700509c6..d0894c2a1c 100644
--- a/src/components/Admin/__snapshots__/Admin.test.jsx.snap
+++ b/src/components/Admin/__snapshots__/Admin.test.jsx.snap
@@ -1686,11 +1686,7 @@ exports[` renders correctly with dashboard analytics data renders # cou
>
All Groups
-
+
@@ -3348,11 +3344,7 @@ exports[` renders correctly with dashboard analytics data renders # of
>
All Groups
-
+
@@ -5010,11 +5002,7 @@ exports[` renders correctly with dashboard analytics data renders # of
>
All Groups
-
+
@@ -6672,11 +6660,7 @@ exports[` renders correctly with dashboard analytics data renders colla
>
All Groups
-
+
@@ -8334,11 +8318,7 @@ exports[` renders correctly with dashboard analytics data renders full
>
All Groups
-
+
@@ -9996,11 +9976,7 @@ exports[` renders correctly with dashboard analytics data renders inact
>
All Groups
-
+
@@ -11658,11 +11634,7 @@ exports[` renders correctly with dashboard analytics data renders inact
>
All Groups
-
+
@@ -13320,11 +13292,7 @@ exports[` renders correctly with dashboard analytics data renders learn
>
All Groups
-
+
@@ -14982,11 +14950,7 @@ exports[` renders correctly with dashboard analytics data renders regis
>
All Groups
-
+
@@ -16644,11 +16608,7 @@ exports[` renders correctly with dashboard analytics data renders top a
>
All Groups
-
+
@@ -18355,11 +18315,7 @@ exports[` renders correctly with dashboard insights data renders dashbo
>
All Groups
-
+
@@ -20017,11 +19973,7 @@ exports[` renders correctly with enterprise budgets data renders budget
>
All Groups
-
+
@@ -21679,11 +21631,7 @@ exports[` renders correctly with enterprise groups data renders groups
>
All Groups
-
+
@@ -25153,11 +25101,7 @@ exports[` renders correctly with no dashboard insights data 1`] = `
>
All Groups
-
+
diff --git a/src/components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups.js b/src/components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups.js
index eb6e2f1f2b..a8af3d50a1 100644
--- a/src/components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups.js
+++ b/src/components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups.js
@@ -10,7 +10,7 @@ import { fetchPaginatedData } from '../../../../data/services/apiServiceUtils';
* @param {*} queryKey The queryKey from the associated `useQuery` call.
* @returns The enterprise group object
*/
-const getAllFlexEnterpriseGroups = async ({ enterpriseId }) => {
+export const getAllFlexEnterpriseGroups = async ({ enterpriseId }) => {
const { results } = await fetchPaginatedData(`${LmsApiService.enterpriseGroupListUrl}?enterprise_uuids=${enterpriseId}`);
const flexGroups = results.filter(result => result.groupType === 'flex');
return flexGroups;
diff --git a/src/data/actions/enterpriseGroups.js b/src/data/actions/enterpriseGroups.js
index a581520453..eddf2f9511 100644
--- a/src/data/actions/enterpriseGroups.js
+++ b/src/data/actions/enterpriseGroups.js
@@ -5,7 +5,7 @@ import {
FETCH_ENTERPRISE_GROUPS_FAILURE,
CLEAR_ENTERPRISE_GROUPS,
} from '../constants/enterpriseGroups';
-import EnterpriseDataApiService from '../services/EnterpriseDataApiService';
+import { getAllFlexEnterpriseGroups } from '../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups';
const fetchEnterpriseGroupsRequest = () => ({ type: FETCH_ENTERPRISE_GROUPS_REQUEST });
const fetchEnterpriseGroupsSuccess = data => ({
@@ -20,9 +20,9 @@ const fetchEnterpriseGroupsFailure = error => ({
const fetchEnterpriseGroups = enterpriseId => (
(dispatch) => {
dispatch(fetchEnterpriseGroupsRequest());
- return EnterpriseDataApiService.fetchEnterpriseGroups(enterpriseId)
+ return getAllFlexEnterpriseGroups({ enterpriseId })
.then((response) => {
- dispatch(fetchEnterpriseGroupsSuccess(response.data));
+ dispatch(fetchEnterpriseGroupsSuccess(response));
})
.catch((error) => {
logError(error);
diff --git a/src/data/actions/enterpriseGroups.test.js b/src/data/actions/enterpriseGroups.test.js
new file mode 100644
index 0000000000..79aad03685
--- /dev/null
+++ b/src/data/actions/enterpriseGroups.test.js
@@ -0,0 +1,62 @@
+import configureMockStore from 'redux-mock-store';
+import thunk from 'redux-thunk';
+import { fetchEnterpriseGroups, clearEnterpriseGroups } from './enterpriseGroups';
+import { getAllFlexEnterpriseGroups } from '../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups';
+import {
+ FETCH_ENTERPRISE_GROUPS_REQUEST,
+ FETCH_ENTERPRISE_GROUPS_SUCCESS,
+ FETCH_ENTERPRISE_GROUPS_FAILURE,
+ CLEAR_ENTERPRISE_GROUPS,
+} from '../constants/enterpriseGroups';
+import { axiosMock } from '../../setupTest';
+
+const middlewares = [thunk];
+const mockStore = configureMockStore(middlewares);
+
+jest.mock('../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups');
+
+describe('enterpriseGroups actions', () => {
+ afterEach(() => {
+ axiosMock.reset();
+ });
+
+ it('creates FETCH_ENTERPRISE_GROUPS_SUCCESS when fetching enterprise groups has been done', () => {
+ const enterpriseId = 'test-enterprise-id';
+ const mockResponse = { data: 'some data' };
+ getAllFlexEnterpriseGroups.mockResolvedValue(mockResponse);
+
+ const expectedActions = [
+ { type: FETCH_ENTERPRISE_GROUPS_REQUEST },
+ { type: FETCH_ENTERPRISE_GROUPS_SUCCESS, payload: { data: mockResponse } },
+ ];
+ const store = mockStore({});
+
+ return store.dispatch(fetchEnterpriseGroups(enterpriseId)).then(() => {
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+
+ it('creates FETCH_ENTERPRISE_GROUPS_FAILURE when fetching enterprise groups fails', () => {
+ const enterpriseId = 'test-enterprise-id';
+ const mockError = new Error('Failed to fetch');
+ getAllFlexEnterpriseGroups.mockRejectedValue(mockError);
+
+ const expectedActions = [
+ { type: FETCH_ENTERPRISE_GROUPS_REQUEST },
+ { type: FETCH_ENTERPRISE_GROUPS_FAILURE, payload: { error: mockError } },
+ ];
+ const store = mockStore({});
+
+ return store.dispatch(fetchEnterpriseGroups(enterpriseId)).then(() => {
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+
+ it('creates CLEAR_ENTERPRISE_GROUPS when clearing enterprise groups', () => {
+ const expectedAction = { type: CLEAR_ENTERPRISE_GROUPS };
+ const store = mockStore({});
+
+ store.dispatch(clearEnterpriseGroups());
+ expect(store.getActions()).toEqual([expectedAction]);
+ });
+});