Skip to content

Commit

Permalink
fix: log errors on no results (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeery committed Aug 23, 2023
1 parent d0e214b commit f9201d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const ViewResults = () => {
},
is_default: true,
});

// Check if any LOB doesn't have a recommendation for a job
results.forEach((jobResult) => {
let hasAnyRecommendations = false;
productTypes.current.forEach((lob) => {
if (jobResult.recommendations[lob].length === 0) {
logError(`Job [${jobResult.name}] has no recommendations for ${lob}`);
} else {
hasAnyRecommendations = true;
}
});
if (!hasAnyRecommendations) {
logError(`Job [${jobResult.name}] has no recommendations for any LOB in [${productTypes.current}]`);
}
});
};

getAllRecommendations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from '@testing-library/react';
import { mergeConfig } from '@edx/frontend-platform';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { logError } from '@edx/frontend-platform/logging';
import messages from '../messages';
import { SkillsBuilderWrapperWithContext, contextValue, dispatchMock } from '../../../test/setupSkillsBuilder';
import { getProductRecommendations } from '../../../utils/search';
Expand All @@ -17,6 +18,10 @@ jest.mock('../data/hooks', () => ({
useProductTypes: jest.fn(),
}));

jest.mock('@edx/frontend-platform/logging', () => ({
logError: jest.fn(),
}));

const renderSkillsBuilderWrapper = (
value = {
...contextValue,
Expand Down Expand Up @@ -169,13 +174,39 @@ describe('view-results', () => {
});
it('hides a LOB if there are no results', async () => {
expect(screen.queryByText(messages.productTypeBootCampDescription.defaultMessage)).toBeNull();
expect(logError).toHaveBeenCalledTimes(2);
// These should all work.
expect(screen.getByText(messages.productTypeDegreeDescription.defaultMessage)).toBeTruthy();
expect(screen.getByText(messages.productTypeExecutiveEducationDescription.defaultMessage)).toBeTruthy();
expect(screen.getByText(messages.productTypeProgramDescription.defaultMessage)).toBeTruthy();
expect(screen.getByText(messages.productTypeCourseDescription.defaultMessage)).toBeTruthy();
});
});

describe('Product lines are hidden with no results', () => {
beforeAll(() => {
useProductTypes.mockImplementation(() => (['boot_camp', 'course']));

// Don't return anything for any LOB
getProductRecommendations.mockImplementation(() => []);
// Restore the mock to the expected value for the other tests.
afterEach(() => {
getProductRecommendations.mockImplementation(() => (
mockData.productRecommendations
));
useProductTypes.mockImplementation(() => (['2U_degree', 'boot_camp', 'executive_education', 'program', 'course']));
});
});
it('Sends an error if there are no results for any LOB', async () => {
expect(logError).toHaveBeenCalledTimes(6);
expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for boot_camp');
expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for course');
expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for any LOB in [boot_camp,course]');
expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for boot_camp');
expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for course');
expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for any LOB in [boot_camp,course]');
});
});
});

describe('show all button', () => {
Expand Down

0 comments on commit f9201d9

Please sign in to comment.