From e51d9f2c04586276558abed94bc62903d5721055 Mon Sep 17 00:00:00 2001 From: Hamzah Ullah Date: Tue, 25 Feb 2025 09:14:32 -0500 Subject: [PATCH] chore: PR feedback --- src/components/app/data/hooks/useBFF.test.jsx | 20 ++--- .../app/data/hooks/useEnterpriseCustomer.js | 2 +- .../data/hooks/useEnterpriseCustomer.test.jsx | 16 ++-- .../app/data/hooks/useEnterpriseFeatures.js | 2 +- .../data/hooks/useEnterpriseFeatures.test.jsx | 16 ++-- .../app/data/hooks/useEnterpriseLearner.js | 3 + .../data/hooks/useEnterpriseLearner.test.jsx | 16 ++-- .../app/data/hooks/useIsBFFEnabled.test.jsx | 9 +- .../queries/extractEnterpriseCustomer.test.js | 82 ++++++++++++++++--- .../data/queries/extractEnterpriseCustomer.ts | 2 - src/components/app/data/queries/utils.js | 1 - .../data/services/enterpriseCustomerUser.ts | 2 +- src/components/app/routes/data/utils.js | 2 +- .../routes/loaders/tests/rootLoader.test.jsx | 32 ++++---- 14 files changed, 131 insertions(+), 74 deletions(-) diff --git a/src/components/app/data/hooks/useBFF.test.jsx b/src/components/app/data/hooks/useBFF.test.jsx index db8068328a..dd77751467 100644 --- a/src/components/app/data/hooks/useBFF.test.jsx +++ b/src/components/app/data/hooks/useBFF.test.jsx @@ -136,32 +136,32 @@ describe('useBFF', () => { it.each([ // BFF disabled route (without query options) { - isMatchedRoute: false, + isMatchedBFFRoute: false, hasQueryOptions: false, }, // BFF enabled route (without query options) { - isMatchedRoute: true, + isMatchedBFFRoute: true, hasQueryOptions: false, }, // BFF enabled route (with query options) { - isMatchedRoute: true, + isMatchedBFFRoute: true, hasQueryOptions: true, }, // BFF disabled route(with query options) { - isMatchedRoute: false, + isMatchedBFFRoute: false, hasQueryOptions: true, }, ])('should handle resolved value correctly for based on route (%s)', async ({ - isMatchedRoute, + isMatchedBFFRoute, hasQueryOptions, }) => { const mockFallbackData = { fallback: 'data' }; const mockSelect = jest.fn(() => { - if (isMatchedRoute) { + if (isMatchedBFFRoute) { return mockBFFDashboardData; } return mockFallbackData; @@ -176,7 +176,7 @@ describe('useBFF', () => { mockBFFQueryOptions.select = mockSelect; mockFallbackQueryConfig.select = mockSelect; } - const initialEntries = isMatchedRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; + const initialEntries = isMatchedBFFRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; const { result, waitForNextUpdate } = renderHook( () => useBFF({ bffQueryOptions: { @@ -194,7 +194,7 @@ describe('useBFF', () => { ); await waitForNextUpdate(); - const expectedData = isMatchedRoute ? mockBFFDashboardData : mockFallbackData; + const expectedData = isMatchedBFFRoute ? mockBFFDashboardData : mockFallbackData; expect(result.current).toEqual( expect.objectContaining({ data: expectedData, @@ -205,7 +205,7 @@ describe('useBFF', () => { if (hasQueryOptions) { expect(mockSelect).toHaveBeenCalledTimes(1); - if (isMatchedRoute) { + if (isMatchedBFFRoute) { // Expects the select function to be called with the resolved BFF data expect(mockSelect).toHaveBeenCalledWith(mockBFFDashboardData); } else { @@ -214,7 +214,7 @@ describe('useBFF', () => { } } - if (isMatchedRoute) { + if (isMatchedBFFRoute) { expect(fetchEnterpriseLearnerDashboard).toHaveBeenCalledTimes(1); expect(fetchEnterpriseLearnerDashboard).toHaveBeenCalledWith( expect.objectContaining({ diff --git a/src/components/app/data/hooks/useEnterpriseCustomer.js b/src/components/app/data/hooks/useEnterpriseCustomer.js index e5292f708d..2c697c5eb2 100644 --- a/src/components/app/data/hooks/useEnterpriseCustomer.js +++ b/src/components/app/data/hooks/useEnterpriseCustomer.js @@ -13,7 +13,7 @@ export default function useEnterpriseCustomer(queryOptions = {}) { const transformedData = data.transformed.enterpriseCustomer; if (select) { return select({ - original: data, + original: data.original, transformed: transformedData, }); } diff --git a/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx b/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx index 4491179ee9..e01fa3e1f3 100644 --- a/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx @@ -53,7 +53,7 @@ const mockBFFDashboardData = { warnings: [], }; -const mockExpectedEnterpriseCustomers = (isMatchedRoute) => (isMatchedRoute +const mockExpectedEnterpriseCustomers = (isMatchedBFFRoute) => (isMatchedBFFRoute ? mockBFFDashboardData.enterpriseCustomer : mockEnterpriseLearnerData.enterpriseCustomer); @@ -77,14 +77,14 @@ describe('useEnterpriseCustomer', () => { fetchEnterpriseLearnerDashboard.mockResolvedValue(mockBFFDashboardData); }); it.each([ - { isMatchedRoute: false }, - { isMatchedRoute: true }, - ])('should return enterprise customers correctly (%s)', async ({ isMatchedRoute }) => { + { isMatchedBFFRoute: false }, + { isMatchedBFFRoute: true }, + ])('should return enterprise customers correctly (%s)', async ({ isMatchedBFFRoute }) => { const mockSelect = jest.fn(data => data.transformed); - const initialEntries = isMatchedRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; + const initialEntries = isMatchedBFFRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; const { result, waitForNextUpdate } = renderHook( () => { - if (isMatchedRoute) { + if (isMatchedBFFRoute) { return useEnterpriseCustomer({ select: mockSelect }); } return useEnterpriseCustomer(); @@ -98,13 +98,13 @@ describe('useEnterpriseCustomer', () => { }, ); await waitForNextUpdate(); - if (isMatchedRoute) { + if (isMatchedBFFRoute) { expect(mockSelect).toHaveBeenCalledTimes(4); } else { expect(mockSelect).toHaveBeenCalledTimes(0); } const actualEnterpriseFeatures = result.current.data; - expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseCustomers(isMatchedRoute)); + expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseCustomers(isMatchedBFFRoute)); }); }); diff --git a/src/components/app/data/hooks/useEnterpriseFeatures.js b/src/components/app/data/hooks/useEnterpriseFeatures.js index 7988fc5218..f11c0c1b60 100644 --- a/src/components/app/data/hooks/useEnterpriseFeatures.js +++ b/src/components/app/data/hooks/useEnterpriseFeatures.js @@ -8,7 +8,7 @@ export default function useEnterpriseFeatures(queryOptions = {}) { const transformedData = data.transformed.enterpriseFeatures; if (select) { return select({ - original: data, + original: data.original, transformed: transformedData, }); } diff --git a/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx b/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx index a688ece8b6..8a6f4eeab5 100644 --- a/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx @@ -51,7 +51,7 @@ const mockBFFDashboardData = { warnings: [], }; -const mockExpectedEnterpriseFeatures = (isMatchedRoute) => (isMatchedRoute +const mockExpectedEnterpriseFeatures = (isMatchedBFFRoute) => (isMatchedBFFRoute ? mockBFFDashboardData.enterpriseFeatures : mockEnterpriseLearnerData.enterpriseFeatures); describe('useEnterpriseFeatures', () => { @@ -76,14 +76,14 @@ describe('useEnterpriseFeatures', () => { }); it.each([ - { isMatchedRoute: false }, - { isMatchedRoute: true }, - ])('should return enterprise features correctly (%s)', async ({ isMatchedRoute }) => { + { isMatchedBFFRoute: false }, + { isMatchedBFFRoute: true }, + ])('should return enterprise features correctly (%s)', async ({ isMatchedBFFRoute }) => { const mockSelect = jest.fn(data => data.transformed); - const initialEntries = isMatchedRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; + const initialEntries = isMatchedBFFRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; const { result, waitForNextUpdate } = renderHook( () => { - if (isMatchedRoute) { + if (isMatchedBFFRoute) { return useEnterpriseFeatures({ select: mockSelect }); } return useEnterpriseFeatures(); @@ -97,13 +97,13 @@ describe('useEnterpriseFeatures', () => { }, ); await waitForNextUpdate(); - if (isMatchedRoute) { + if (isMatchedBFFRoute) { expect(mockSelect).toHaveBeenCalledTimes(4); } else { expect(mockSelect).toHaveBeenCalledTimes(0); } const actualEnterpriseFeatures = result.current.data; - expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseFeatures(isMatchedRoute)); + expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseFeatures(isMatchedBFFRoute)); }); }); diff --git a/src/components/app/data/hooks/useEnterpriseLearner.js b/src/components/app/data/hooks/useEnterpriseLearner.js index 29f3c7fac9..d8858fc84e 100644 --- a/src/components/app/data/hooks/useEnterpriseLearner.js +++ b/src/components/app/data/hooks/useEnterpriseLearner.js @@ -39,6 +39,9 @@ export default function useEnterpriseLearner(queryOptions = {}) { ...queryEnterpriseLearner(authenticatedUser.username, enterpriseSlug), ...queryOptions, select: (data) => { + // To maintain parity with BFF-enabled routes in the function signature passed to the custom `select` + // function, the legacy `queryEnterpriseLearner` also passes its `data` to the custom `select` function + // as both the `original` and `transformed` properties, since no data transformations occur here. if (select) { return select({ original: data, diff --git a/src/components/app/data/hooks/useEnterpriseLearner.test.jsx b/src/components/app/data/hooks/useEnterpriseLearner.test.jsx index ee63e6a800..5f7e5ab5eb 100644 --- a/src/components/app/data/hooks/useEnterpriseLearner.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseLearner.test.jsx @@ -55,7 +55,7 @@ const mockBFFDashboardData = { warnings: [], }; -const mockExpectedEnterpriseLearner = (isMatchedRoute) => (isMatchedRoute +const mockExpectedEnterpriseLearner = (isMatchedBFFRoute) => (isMatchedBFFRoute ? { enterpriseCustomer: mockBFFDashboardData.enterpriseCustomer, allLinkedEnterpriseCustomerUsers: mockBFFDashboardData.allLinkedEnterpriseCustomerUsers, @@ -80,32 +80,32 @@ describe('useEnterpriseLearner', () => { useParams.mockReturnValue({ enterpriseSlug: mockEnterpriseCustomer.slug }); }); it.each([ - { isMatchedRoute: false }, - { isMatchedRoute: true }, - ])('should return enterprise learners correctly (%s)', async ({ isMatchedRoute }) => { + { isMatchedBFFRoute: false }, + { isMatchedBFFRoute: true }, + ])('should return enterprise learners correctly (%s)', async ({ isMatchedBFFRoute }) => { const mockSelect = jest.fn(data => data.transformed); const { result, waitForNextUpdate } = renderHook( () => { - if (isMatchedRoute) { + if (isMatchedBFFRoute) { return useEnterpriseLearner({ select: mockSelect }); } return useEnterpriseLearner(); }, { wrapper: ({ children }) => Wrapper({ - routes: isMatchedRoute ? '/test-enterprise' : 'test-enterprise/search', + routes: isMatchedBFFRoute ? '/test-enterprise' : 'test-enterprise/search', children, }), }, ); await waitForNextUpdate(); - if (isMatchedRoute) { + if (isMatchedBFFRoute) { expect(mockSelect).toHaveBeenCalledTimes(2); } else { expect(mockSelect).toHaveBeenCalledTimes(0); } const actualEnterpriseFeatures = result.current.data; - expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseLearner(isMatchedRoute)); + expect(actualEnterpriseFeatures).toEqual(mockExpectedEnterpriseLearner(isMatchedBFFRoute)); }); }); diff --git a/src/components/app/data/hooks/useIsBFFEnabled.test.jsx b/src/components/app/data/hooks/useIsBFFEnabled.test.jsx index 15d643850a..2a06c0652d 100644 --- a/src/components/app/data/hooks/useIsBFFEnabled.test.jsx +++ b/src/components/app/data/hooks/useIsBFFEnabled.test.jsx @@ -1,6 +1,6 @@ import { renderHook } from '@testing-library/react-hooks'; import { QueryClientProvider } from '@tanstack/react-query'; -import { MemoryRouter, useLocation } from 'react-router-dom'; +import { MemoryRouter } from 'react-router-dom'; import { AppContext } from '@edx/frontend-platform/react'; import useIsBFFEnabled from './useIsBFFEnabled'; import { queryEnterpriseLearnerDashboardBFF, resolveBFFQuery } from '../queries'; @@ -11,10 +11,7 @@ jest.mock('../queries', () => ({ ...jest.requireActual('../queries'), resolveBFFQuery: jest.fn(), })); -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useLocation: jest.fn(), -})); + const mockAuthenticatedUser = authenticatedUserFactory(); describe('useIsBFFEnabled', () => { @@ -29,7 +26,6 @@ describe('useIsBFFEnabled', () => { ); beforeEach(() => { jest.clearAllMocks(); - useLocation.mockReturnValue({ pathname: '/test-enterprise' }); }); it.each([ @@ -39,7 +35,6 @@ describe('useIsBFFEnabled', () => { const route = hasBFFEnabled ? '/test-enterprise' : 'test-enterprise/search'; resolveBFFQuery.mockReturnValue(hasBFFEnabled ? queryEnterpriseLearnerDashboardBFF : null); - useLocation.mockReturnValue({ pathname: route }); const { result } = renderHook(() => useIsBFFEnabled(), { wrapper: ({ children }) => Wrapper({ diff --git a/src/components/app/data/queries/extractEnterpriseCustomer.test.js b/src/components/app/data/queries/extractEnterpriseCustomer.test.js index c2b80059e1..51bf63252a 100644 --- a/src/components/app/data/queries/extractEnterpriseCustomer.test.js +++ b/src/components/app/data/queries/extractEnterpriseCustomer.test.js @@ -5,7 +5,7 @@ import { enterpriseCustomerUserFactory, } from '../services/data/__factories__'; import extractEnterpriseCustomer from './extractEnterpriseCustomer'; -import { queryEnterpriseLearner } from './queries'; +import { queryEnterpriseLearner, queryEnterpriseLearnerDashboardBFF } from './queries'; const mockEnsureQueryData = jest.fn(); @@ -15,11 +15,13 @@ const mockQueryClient = { const mockAuthenticatedUser = authenticatedUserFactory(); const mockEnterpriseCustomer = enterpriseCustomerFactory(); const mockEnterpriseCustomerUser = enterpriseCustomerUserFactory({ - enterprise_customer: mockEnterpriseCustomer, + enterprise_customer: { + ...mockEnterpriseCustomer, + slug: mockEnterpriseCustomer.slug, + }, }); -const mockRequestUrl = { - pathname: mockEnterpriseCustomer.slug, -}; +const mockBFFRequestUrl = new URL(`/${mockEnterpriseCustomer.slug}`, 'https://example.com'); +const mockNonBFFRequestUrl = new URL(`/${mockEnterpriseCustomer.slug}/search`, 'https://example.com'); const getQueryEnterpriseLearner = ({ hasEnterpriseSlug = true } = {}) => queryEnterpriseLearner( mockAuthenticatedUser.username, hasEnterpriseSlug ? mockEnterpriseCustomer.slug : undefined, @@ -37,67 +39,127 @@ describe('extractEnterpriseCustomer', () => { enterpriseCustomerUser: mockEnterpriseCustomerUser, staffEnterpriseCustomer: undefined, expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: mockEnterpriseCustomer.slug, + enterpriseCustomerUser: undefined, + staffEnterpriseCustomer: mockEnterpriseCustomer, + expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: mockEnterpriseCustomer.slug, + enterpriseCustomerUser: mockEnterpriseCustomerUser, + staffEnterpriseCustomer: mockEnterpriseCustomer, + expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: undefined, + enterpriseCustomerUser: mockEnterpriseCustomerUser, + staffEnterpriseCustomer: undefined, + expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: undefined, + enterpriseCustomerUser: undefined, + staffEnterpriseCustomer: mockEnterpriseCustomer, + expectedEnterpriseCustomer: undefined, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: undefined, + enterpriseCustomerUser: mockEnterpriseCustomerUser, + staffEnterpriseCustomer: mockEnterpriseCustomer, + expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: true, + }, + { + routeEnterpriseSlug: mockEnterpriseCustomer.slug, + enterpriseCustomerUser: undefined, + staffEnterpriseCustomer: undefined, + expectedEnterpriseCustomer: undefined, + isBFFRoute: true, + }, + // iaBFFRoute false + { + routeEnterpriseSlug: mockEnterpriseCustomer.slug, + enterpriseCustomerUser: mockEnterpriseCustomerUser, + staffEnterpriseCustomer: undefined, + expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: false, }, { routeEnterpriseSlug: mockEnterpriseCustomer.slug, enterpriseCustomerUser: undefined, staffEnterpriseCustomer: mockEnterpriseCustomer, expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: false, }, { routeEnterpriseSlug: mockEnterpriseCustomer.slug, enterpriseCustomerUser: mockEnterpriseCustomerUser, staffEnterpriseCustomer: mockEnterpriseCustomer, expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: false, }, { routeEnterpriseSlug: undefined, enterpriseCustomerUser: mockEnterpriseCustomerUser, staffEnterpriseCustomer: undefined, expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: false, }, { routeEnterpriseSlug: undefined, enterpriseCustomerUser: undefined, staffEnterpriseCustomer: mockEnterpriseCustomer, expectedEnterpriseCustomer: undefined, + isBFFRoute: false, }, { routeEnterpriseSlug: undefined, enterpriseCustomerUser: mockEnterpriseCustomerUser, staffEnterpriseCustomer: mockEnterpriseCustomer, expectedEnterpriseCustomer: mockEnterpriseCustomer, + isBFFRoute: false, }, { routeEnterpriseSlug: mockEnterpriseCustomer.slug, enterpriseCustomerUser: undefined, staffEnterpriseCustomer: undefined, expectedEnterpriseCustomer: undefined, + isBFFRoute: false, }, ])('should return or throw error as expected (%s)', async ({ routeEnterpriseSlug, enterpriseCustomerUser, staffEnterpriseCustomer, expectedEnterpriseCustomer, + isBFFRoute, }) => { const args = { - requestUrl: mockRequestUrl, + requestUrl: isBFFRoute ? mockBFFRequestUrl : mockNonBFFRequestUrl, queryClient: mockQueryClient, authenticatedUser: mockAuthenticatedUser, enterpriseSlug: routeEnterpriseSlug, }; const queryEnterpriseLearnerResult = { + enterpriseCustomer: expectedEnterpriseCustomer, activeEnterpriseCustomer: enterpriseCustomerUser?.enterpriseCustomer, allLinkedEnterpriseCustomerUsers: enterpriseCustomerUser ? [enterpriseCustomerUser] : [], staffEnterpriseCustomer, + enterpriseFeatures: { something: true }, + shouldUpdateActiveEnterpriseCustomerUser: false, }; - const queryEnterpriseLearnerQueryKey = getQueryEnterpriseLearner({ - hasEnterpriseSlug: !!routeEnterpriseSlug, - }).queryKey; when(mockEnsureQueryData) .calledWith( expect.objectContaining({ - queryKey: queryEnterpriseLearnerQueryKey, + queryKey: isBFFRoute + ? queryEnterpriseLearnerDashboardBFF({ enterpriseSlug: routeEnterpriseSlug }).queryKey + : getQueryEnterpriseLearner({ hasEnterpriseSlug: !!routeEnterpriseSlug }).queryKey, }), ) .mockResolvedValue(queryEnterpriseLearnerResult); diff --git a/src/components/app/data/queries/extractEnterpriseCustomer.ts b/src/components/app/data/queries/extractEnterpriseCustomer.ts index 90819f02cd..4fdaf9d82f 100644 --- a/src/components/app/data/queries/extractEnterpriseCustomer.ts +++ b/src/components/app/data/queries/extractEnterpriseCustomer.ts @@ -24,13 +24,11 @@ async function extractEnterpriseCustomer({ authenticatedUser, enterpriseSlug, }); - const { activeEnterpriseCustomer, allLinkedEnterpriseCustomerUsers, staffEnterpriseCustomer, } = enterpriseLearnerData; - // If there is no slug provided (i.e., on the root page route `/`), use // the currently active enterprise customer user. if (!enterpriseSlug) { diff --git a/src/components/app/data/queries/utils.js b/src/components/app/data/queries/utils.js index 44350220f4..5fbcad5dda 100644 --- a/src/components/app/data/queries/utils.js +++ b/src/components/app/data/queries/utils.js @@ -58,7 +58,6 @@ export async function getEnterpriseLearnerQueryData({ // or fetch from the server if not available. let enterpriseLearnerData; const matchedBFFQuery = resolveBFFQuery(requestUrl.pathname); - if (matchedBFFQuery) { const bffResponse = await queryClient.ensureQueryData( matchedBFFQuery({ enterpriseSlug }), diff --git a/src/components/app/data/services/enterpriseCustomerUser.ts b/src/components/app/data/services/enterpriseCustomerUser.ts index 33ee79456f..d5991d25ad 100644 --- a/src/components/app/data/services/enterpriseCustomerUser.ts +++ b/src/components/app/data/services/enterpriseCustomerUser.ts @@ -151,7 +151,7 @@ export async function fetchEnterpriseCourseEnrollments(enterpriseId, options = { const response = await getAuthenticatedHttpClient().get(url); return camelCaseObject(response.data); } catch (error) { - if (getErrorResponseStatusCode(error as Error) !== 404) { + if (error instanceof Error && getErrorResponseStatusCode(error as Error) !== 404) { logError(error as Error); } return []; diff --git a/src/components/app/routes/data/utils.js b/src/components/app/routes/data/utils.js index 8ebb158552..d7ba9094b0 100644 --- a/src/components/app/routes/data/utils.js +++ b/src/components/app/routes/data/utils.js @@ -350,7 +350,7 @@ export async function ensureActiveEnterpriseCustomerUser({ }; } - // If the active enterprise customer user was not updated or enterpriseSlug is missing, return null. + // Given the user has an active ECU, but the current route has no slug, redirect to the slug of the active ECU. if (activeEnterpriseCustomer && !enterpriseSlug) { throw redirect(generatePath('/:enterpriseSlug/*', { enterpriseSlug: activeEnterpriseCustomer.slug, diff --git a/src/components/app/routes/loaders/tests/rootLoader.test.jsx b/src/components/app/routes/loaders/tests/rootLoader.test.jsx index d3655485b4..d197c3a287 100644 --- a/src/components/app/routes/loaders/tests/rootLoader.test.jsx +++ b/src/components/app/routes/loaders/tests/rootLoader.test.jsx @@ -120,9 +120,9 @@ describe('rootLoader', () => { }); it.each([ - { isMatchedRoute: false }, - { isMatchedRoute: true }, - ])('ensures only the enterprise-learner query is called if there is no active enterprise customer user, (%s)', async ({ isMatchedRoute }) => { + { isMatchedBFFRoute: false }, + { isMatchedBFFRoute: true }, + ])('ensures only the enterprise-learner query is called if there is no active enterprise customer user, (%s)', async ({ isMatchedBFFRoute }) => { const enterpriseLearnerQuery = queryEnterpriseLearner(mockAuthenticatedUser.username, mockEnterpriseCustomer.slug); const enterpriseBFFQuery = queryEnterpriseLearnerDashboardBFF({ enterpriseSlug: mockEnterpriseCustomer.slug }); @@ -146,7 +146,7 @@ describe('rootLoader', () => { shouldUpdateActiveEnterpriseCustomerUser: false, }); - const routeMetadata = isMatchedRoute + const routeMetadata = isMatchedBFFRoute ? { path: '/:enterpriseSlug', initialEntries: [`/${mockEnterpriseCustomer.slug}`] } : { path: '/:enterpriseSlug/search', initialEntries: [`/${mockEnterpriseCustomer.slug}/search`] }; renderWithRouterProvider({ @@ -177,7 +177,7 @@ describe('rootLoader', () => { ], isStaffUser: false, shouldActivateSubscriptionLicense: false, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF disabled, non-staff user is linked to requested customer, resolves // requested customer, does not need to update active enterprise, needs @@ -192,7 +192,7 @@ describe('rootLoader', () => { ], isStaffUser: false, shouldActivateSubscriptionLicense: true, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF disabled, non-staff user is linked to requested customer, resolves // requested customer, needs update to active enterprise, does not @@ -207,7 +207,7 @@ describe('rootLoader', () => { ], isStaffUser: false, shouldActivateSubscriptionLicense: false, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF disabled, non-staff user is not linked to requested customer, resolves // linked customer, does not need to update active enterprise, does not @@ -221,7 +221,7 @@ describe('rootLoader', () => { ], isStaffUser: false, shouldActivateSubscriptionLicense: false, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF disabled, staff user is not linked to requested customer, resolves // requested customer, does not need to update active enterprise, does not @@ -235,7 +235,7 @@ describe('rootLoader', () => { ], isStaffUser: true, shouldActivateSubscriptionLicense: false, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF disabled, staff user is linked to requested customer, resolves // requested customer, needs update to active enterprise, does not @@ -250,7 +250,7 @@ describe('rootLoader', () => { ], isStaffUser: true, shouldActivateSubscriptionLicense: false, - isMatchedRoute: false, + isMatchedBFFRoute: false, }, // BFF enabled, non-staff user is linked to requested customer, resolves // requested customer, needs update to active enterprise, does not @@ -265,7 +265,7 @@ describe('rootLoader', () => { ], isStaffUser: false, shouldActivateSubscriptionLicense: false, - isMatchedRoute: true, + isMatchedBFFRoute: true, }, ])('ensures all requisite root loader queries are resolved with an active enterprise customer user (%s)', async ({ isStaffUser, @@ -274,7 +274,7 @@ describe('rootLoader', () => { activeEnterpriseCustomer, allLinkedEnterpriseCustomerUsers, shouldActivateSubscriptionLicense, - isMatchedRoute, + isMatchedBFFRoute, }) => { const enterpriseLearnerQuery = queryEnterpriseLearner(mockAuthenticatedUser.username, enterpriseSlug); const enterpriseLearnerQueryTwo = queryEnterpriseLearner(mockAuthenticatedUser.username, enterpriseCustomer.slug); @@ -362,7 +362,7 @@ describe('rootLoader', () => { }), ).mockResolvedValue(mockSubscriptionsData); - const routeMetadata = isMatchedRoute + const routeMetadata = isMatchedBFFRoute ? { path: '/:enterpriseSlug', initialEntries: [`/${enterpriseSlug}`] } : { path: '/:enterpriseSlug/search', initialEntries: [`/${enterpriseSlug}/search`] }; @@ -383,7 +383,7 @@ describe('rootLoader', () => { if (!(isLinked || isStaffUser)) { expectedQueryCount = 2; } - } else if (isMatchedRoute) { + } else if (isMatchedBFFRoute) { expectedQueryCount = 9; } expect(mockQueryClient.ensureQueryData).toHaveBeenCalledTimes(expectedQueryCount); @@ -392,7 +392,7 @@ describe('rootLoader', () => { // Enterprise learner query expect(mockQueryClient.ensureQueryData).toHaveBeenCalledWith( expect.objectContaining({ - queryKey: isMatchedRoute ? enterpriseBFFQuery.queryKey : enterpriseLearnerQuery.queryKey, + queryKey: isMatchedBFFRoute ? enterpriseBFFQuery.queryKey : enterpriseLearnerQuery.queryKey, queryFn: expect.any(Function), }), ); @@ -414,7 +414,7 @@ describe('rootLoader', () => { ); // Subscriptions query (only called with BFF disabled) - if (!isMatchedRoute) { + if (!isMatchedBFFRoute) { expect(mockQueryClient.ensureQueryData).toHaveBeenCalledWith( expect.objectContaining({ queryKey: subscriptionsQuery.queryKey,