Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log errors on no results #39

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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