Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Dec 10, 2024
1 parent 71d9685 commit 7d890ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/components/app/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ export function transformCourseMetadataByAllocatedCourseRunAssignments({

export function isBFFEnabledForEnterpriseCustomer(enterpriseCustomerUuid) {
const { FEATURE_ENABLE_BFF_API_FOR_ENTERPRISE_CUSTOMERS } = getConfig();
console.log('FEATURE_ENABLE_BFF_API_FOR_ENTERPRISE_CUSTOMERS', FEATURE_ENABLE_BFF_API_FOR_ENTERPRISE_CUSTOMERS);

Check warning on line 890 in src/components/app/data/utils.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
if (!FEATURE_ENABLE_BFF_API_FOR_ENTERPRISE_CUSTOMERS) {
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/enterprise-page/EnterprisePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ function useLoggingCustomAttributes() {
if (isDefinedAndNotNull(enterpriseCustomer)) {
pushUserCustomerAttributes(enterpriseCustomer);

// Set custom attributes for logging service
// Set custom attributes via logging service
const loggingService = getLoggingService();
loggingService.setCustomAttribute('enterprise_customer_uuid', enterpriseCustomer.uuid);
const isBFFEnabled = isBFFEnabledForEnterpriseCustomer(enterpriseCustomer.uuid);
loggingService.setCustomAttribute('is_bff_enabled', isBFFEnabled);
loggingService.setCustomAttribute(
'is_bff_enabled',
isBFFEnabledForEnterpriseCustomer(enterpriseCustomer.uuid),
);
}
}, [enterpriseCustomer]);
}
Expand Down
24 changes: 13 additions & 11 deletions src/components/enterprise-page/EnterprisePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { AppContext } from '@edx/frontend-platform/react';
import { getLoggingService } from '@edx/frontend-platform/logging';

import EnterprisePage from './EnterprisePage';
import { useEnterpriseCustomer } from '../app/data';
import { isBFFEnabledForEnterpriseCustomer, useEnterpriseCustomer } from '../app/data';
import { authenticatedUserFactory, enterpriseCustomerFactory } from '../app/data/services/data/__factories__';

jest.mock('../app/data', () => ({
...jest.requireActual('../app/data'),
useEnterpriseCustomer: jest.fn(),
isBFFEnabledForEnterpriseCustomer: jest.fn().mockReturnValue(false),
}));

const mockEnterpriseCustomer = enterpriseCustomerFactory();
Expand Down Expand Up @@ -79,18 +80,19 @@ describe('<EnterprisePage />', () => {
it.each([
{ isBFFEnabled: false },
{ isBFFEnabled: true },
])('sets custom attributes via logging service', ({ isBFFEnabled }) => {
// Mock the BFF-related feature flag
const bffFeatureFlag = isBFFEnabled ? [mockEnterpriseCustomer.uuid] : [];
const appContextValueWithBFFConfig = {
authenticatedUser: mockAuthenticatedUser,
config: {
FEATURE_ENABLE_BFF_API_FOR_ENTERPRISE_CUSTOMERS: bffFeatureFlag,
},
};
])('sets custom attributes via logging service (%s)', ({ isBFFEnabled }) => {
// Mock the BFF feature flag
isBFFEnabledForEnterpriseCustomer.mockReturnValue(isBFFEnabled);

// Mount the component
mount(<EnterprisePageWrapper appContextValue={appContextValueWithBFFConfig} />);
const wrapper = mount(
<EnterprisePageWrapper>
<div data-testid="child-component" />
</EnterprisePageWrapper>,
);

// Verify the children are rendered
expect(wrapper.find('[data-testid="child-component"]').exists()).toBe(true);

// Verify that the custom attributes were set
expect(mockSetCustomAttribute).toHaveBeenCalledTimes(2);
Expand Down

0 comments on commit 7d890ab

Please sign in to comment.