Skip to content

Commit

Permalink
fix: correct usages of useEnterpriseFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Dec 18, 2024
1 parent dd0cb8d commit 8d685a7
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/app/data/hooks/useBFF.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 2 additions & 6 deletions src/components/app/data/hooks/useBFF.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down Expand Up @@ -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' };
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/data/hooks/useIsBFFEnabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions src/components/app/data/hooks/useIsBFFEnabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/data/hooks/useSubscriptions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const CourseEnrollments = ({ children }) => {
},
} = useEnterpriseCourseEnrollments();

const enterpriseFeatures = useEnterpriseFeatures();
const { data: enterpriseFeatures } = useEnterpriseFeatures();
const {
hasCourseEnrollments,
currentCourseEnrollments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/search/tests/SearchSections.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}));

Expand Down

0 comments on commit 8d685a7

Please sign in to comment.