From 8d685a74a463282728e8f3061d02ec07bf33516a Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 18 Dec 2024 10:47:30 -0500 Subject: [PATCH] fix: correct usages of useEnterpriseFeatures --- src/components/app/data/hooks/useBFF.js | 2 +- src/components/app/data/hooks/useBFF.test.jsx | 8 ++------ src/components/app/data/hooks/useIsBFFEnabled.js | 2 +- src/components/app/data/hooks/useIsBFFEnabled.test.js | 6 +++--- src/components/app/data/hooks/useSubscriptions.test.jsx | 2 +- .../main-content/course-enrollments/CourseEnrollments.jsx | 2 +- .../course-enrollments/CourseEnrollmentsEmptyState.jsx | 2 +- .../course-enrollments/tests/CourseEnrollments.test.jsx | 4 ++-- src/components/search/tests/SearchSections.test.jsx | 2 +- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/components/app/data/hooks/useBFF.js b/src/components/app/data/hooks/useBFF.js index fd100e3a0a..fce0973429 100644 --- a/src/components/app/data/hooks/useBFF.js +++ b/src/components/app/data/hooks/useBFF.js @@ -20,7 +20,7 @@ export default function useBFF({ fallbackQueryConfig = null, }) { const { data: enterpriseCustomer } = useEnterpriseCustomer(); - const enterpriseFeatures = useEnterpriseFeatures(); + const { data: enterpriseFeatures } = useEnterpriseFeatures(); const { enterpriseSlug } = useParams(); const location = useLocation(); diff --git a/src/components/app/data/hooks/useBFF.test.jsx b/src/components/app/data/hooks/useBFF.test.jsx index 105c16d6be..989bc78bf4 100644 --- a/src/components/app/data/hooks/useBFF.test.jsx +++ b/src/components/app/data/hooks/useBFF.test.jsx @@ -138,9 +138,7 @@ describe('useBFF', () => { beforeEach(() => { jest.clearAllMocks(); useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer }); - useEnterpriseFeatures.mockReturnValue({ - enterpriseLearnerBFFEnabled: false, - }); + useEnterpriseFeatures.mockReturnValue({ data: { enterpriseLearnerBFFEnabled: false } }); fetchEnterpriseLearnerDashboard.mockResolvedValue(mockBFFDashboardData); useLocation.mockReturnValue({ pathname: '/test-enterprise' }); useParams.mockReturnValue({ enterpriseSlug: 'test-enterprise' }); @@ -209,9 +207,7 @@ describe('useBFF', () => { }); } if (isBFFEnabledForUser) { - useEnterpriseFeatures.mockReturnValue({ - enterpriseLearnerBFFEnabled: true, - }); + useEnterpriseFeatures.mockReturnValue({ data: { enterpriseLearnerBFFEnabled: true } }); } const isBFFEnabled = isBFFEnabledForCustomer || isBFFEnabledForUser; const mockFallbackData = { fallback: 'data' }; diff --git a/src/components/app/data/hooks/useIsBFFEnabled.js b/src/components/app/data/hooks/useIsBFFEnabled.js index dd1597428d..0749deed77 100644 --- a/src/components/app/data/hooks/useIsBFFEnabled.js +++ b/src/components/app/data/hooks/useIsBFFEnabled.js @@ -4,6 +4,6 @@ import useEnterpriseFeatures from './useEnterpriseFeatures'; export default function useIsBFFEnabled() { const { data: enterpriseCustomer } = useEnterpriseCustomer(); - const enterpriseFeatures = useEnterpriseFeatures(); + const { data: enterpriseFeatures } = useEnterpriseFeatures(); return isBFFEnabled(enterpriseCustomer.uuid, enterpriseFeatures); } diff --git a/src/components/app/data/hooks/useIsBFFEnabled.test.js b/src/components/app/data/hooks/useIsBFFEnabled.test.js index 4574966fb0..a1233659d8 100644 --- a/src/components/app/data/hooks/useIsBFFEnabled.test.js +++ b/src/components/app/data/hooks/useIsBFFEnabled.test.js @@ -23,13 +23,13 @@ describe('useIsBFFEnabled', () => { const mockEnterpriseFeatures = { featureX: true }; useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer }); - useEnterpriseFeatures.mockReturnValue(mockEnterpriseFeatures); + useEnterpriseFeatures.mockReturnValue({ data: mockEnterpriseFeatures }); isBFFEnabled.mockReturnValue(hasBFFEnabled); const { result } = renderHook(() => useIsBFFEnabled()); - expect(useEnterpriseCustomer).toHaveBeenCalled(); - expect(useEnterpriseFeatures).toHaveBeenCalled(); + expect(useEnterpriseCustomer).toHaveBeenCalledTimes(1); + expect(useEnterpriseFeatures).toHaveBeenCalledTimes(1); expect(isBFFEnabled).toHaveBeenCalledWith(mockEnterpriseCustomer.uuid, mockEnterpriseFeatures); expect(result.current).toBe(hasBFFEnabled); }); diff --git a/src/components/app/data/hooks/useSubscriptions.test.jsx b/src/components/app/data/hooks/useSubscriptions.test.jsx index 6fdcfe3a3d..f7cf08c767 100644 --- a/src/components/app/data/hooks/useSubscriptions.test.jsx +++ b/src/components/app/data/hooks/useSubscriptions.test.jsx @@ -52,7 +52,7 @@ describe('useSubscriptions', () => { beforeEach(() => { jest.clearAllMocks(); useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer }); - useEnterpriseFeatures.mockReturnValue(null); + useEnterpriseFeatures.mockReturnValue({ data: undefined }); fetchSubscriptions.mockResolvedValue(mockSubscriptionsData); useLocation.mockReturnValue({ pathname: '/test-enterprise' }); useParams.mockReturnValue({ enterpriseSlug: 'test-enterprise' }); diff --git a/src/components/dashboard/main-content/course-enrollments/CourseEnrollments.jsx b/src/components/dashboard/main-content/course-enrollments/CourseEnrollments.jsx index 4c21763065..5724533724 100644 --- a/src/components/dashboard/main-content/course-enrollments/CourseEnrollments.jsx +++ b/src/components/dashboard/main-content/course-enrollments/CourseEnrollments.jsx @@ -62,7 +62,7 @@ const CourseEnrollments = ({ children }) => { }, } = useEnterpriseCourseEnrollments(); - const enterpriseFeatures = useEnterpriseFeatures(); + const { data: enterpriseFeatures } = useEnterpriseFeatures(); const { hasCourseEnrollments, currentCourseEnrollments, diff --git a/src/components/dashboard/main-content/course-enrollments/CourseEnrollmentsEmptyState.jsx b/src/components/dashboard/main-content/course-enrollments/CourseEnrollmentsEmptyState.jsx index bcc55f62cd..bd67a5a0e4 100644 --- a/src/components/dashboard/main-content/course-enrollments/CourseEnrollmentsEmptyState.jsx +++ b/src/components/dashboard/main-content/course-enrollments/CourseEnrollmentsEmptyState.jsx @@ -11,7 +11,7 @@ import NewGroupAssignmentAlert from './NewGroupAssignmentAlert'; const CourseEnrollmentsEmptyState = () => { const { data: canOnlyViewHighlightSets } = useCanOnlyViewHighlights(); const { data: academies } = useAcademies(); - const enterpriseFeatures = useEnterpriseFeatures(); + const { data: enterpriseFeatures } = useEnterpriseFeatures(); const { showNewGroupAssociationAlert, dismissGroupAssociationAlert, diff --git a/src/components/dashboard/main-content/course-enrollments/tests/CourseEnrollments.test.jsx b/src/components/dashboard/main-content/course-enrollments/tests/CourseEnrollments.test.jsx index 33118e1128..34857f7995 100644 --- a/src/components/dashboard/main-content/course-enrollments/tests/CourseEnrollments.test.jsx +++ b/src/components/dashboard/main-content/course-enrollments/tests/CourseEnrollments.test.jsx @@ -152,7 +152,7 @@ describe('Course enrollments', () => { updateCourseCompleteStatusRequest.mockImplementation(() => ({ data: {} })); sortAssignmentsByAssignmentStatus.mockReturnValue([assignmentData]); - useEnterpriseFeatures.mockReturnValue({ enterpriseGroupsV1: false }); + useEnterpriseFeatures.mockReturnValue({ data: { enterpriseGroupsV1: false } }); useGroupAssociationsAlert.mockReturnValue({ showNewGroupAssociationAlert: true, dismissGroupAssociationAlert: mockDismissGroupAssociationAlert, @@ -277,7 +277,7 @@ describe('Course enrollments', () => { it( 'renders NewGroupAssignmentAlert when showNewGroupAssociationAlert is true', async () => { - useEnterpriseFeatures.mockReturnValue({ enterpriseGroupsV1: true }); + useEnterpriseFeatures.mockReturnValue({ data: { enterpriseGroupsV1: true } }); useGroupAssociationsAlert.mockReturnValue({ showNewGroupAssociationAlert: true, dismissGroupAssociationAlert: mockDismissGroupAssociationAlert, diff --git a/src/components/search/tests/SearchSections.test.jsx b/src/components/search/tests/SearchSections.test.jsx index 6e060b37ab..18a556072e 100644 --- a/src/components/search/tests/SearchSections.test.jsx +++ b/src/components/search/tests/SearchSections.test.jsx @@ -26,7 +26,7 @@ jest.mock('../../app/data', () => ({ useContentHighlightsConfiguration: jest.fn(() => ({ data: {} })), useCanOnlyViewHighlights: jest.fn(() => ({ data: {} })), useIsAssignmentsOnlyLearner: jest.fn().mockReturnValue(false), - useEnterpriseFeatures: jest.fn(), + useEnterpriseFeatures: jest.fn().mockReturnValue({ data: undefined }), useDefaultSearchFilters: jest.fn(), }));