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

chore: add subdirectory slug format for bootcamps #910

Merged
merged 1 commit into from
Sep 8, 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
2 changes: 2 additions & 0 deletions src/data/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const FORMAT_DATE_MATCHER = /20\d{2}-(0\d{1}|1[0-2])-([0-2]\d{1}|3[0-1])/;
const NORMALIZE_DATE_MATCHER = /20\d{2}\/(0\d{1}|1[0-2])\/([0-2]\d{1}|3[0-1])/;

const EXECUTIVE_EDUCATION_SLUG = 'executive-education-2u';
const BOOTCAMP_SLUG = 'bootcamp-2u';

const COURSE_URL_SLUG_PATTERN_OLD = '^[a-z0-9_]+(?:-[a-z0-9_]+)*$';
const COURSE_URL_SLUG_PATTERN_NEW = '^learn/[a-z0-9_]+(?:-?[a-z0-9_]+)*/[a-z0-9_]+(?:-?[a-z0-9_]+)*$';
Expand Down Expand Up @@ -53,6 +54,7 @@ export {
COURSE_EXEMPT_FIELDS,
COURSE_RUN_NON_EXEMPT_FIELDS,
EXECUTIVE_EDUCATION_SLUG,
BOOTCAMP_SLUG,
COURSE_URL_SLUG_PATTERN,
COURSE_URL_SLUG_PATTERN_NEW,
COURSE_URL_SLUG_PATTERN_OLD,
Expand Down
8 changes: 8 additions & 0 deletions src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ process.env.COURSE_URL_SLUGS_PATTERN = `{
"default": {
"slug_format": "^learn/[a-z0-9_]+(?:-?[a-z0-9_]+)*/[a-z0-9_]+(?:-?[a-z0-9_]+)*$|^[a-z0-9_]+(?:-[a-z0-9_]+)*$",
"error_msg": "Course URL slug contains lowercase letters, numbers, underscores, and dashes only and must be in the format <custom-url-slug> or learn/<primary_subject>/<org-slug>-<course_slug>."
},
"bootcamp-2u": {
"slug_format": "^boot-camps/[a-z0-9_]+(?:-?[a-z0-9_]+)*/[a-z0-9_]+(?:-?[a-z0-9_]+)*$|^[a-z0-9_]+(?:-[a-z0-9_]+)*$",
"error_msg": "Course URL slug contains lowercase letters, numbers, underscores, and dashes only and must be in the format <custom-url-slug> or boot-camps/<primary_subject>/<org-slug>-<course_slug>."
}
},
"external-source": {
Expand All @@ -27,6 +31,10 @@ process.env.COURSE_URL_SLUGS_PATTERN = `{
"executive-education-2u": {
"slug_format": "^executive-education/[a-z0-9_]+(?:-?[a-z0-9_]+)*$|^[a-z0-9_]+(?:-[a-z0-9_]+)*$",
"error_msg": "Course URL slug contains lowercase letters, numbers, underscores, and dashes only and must be in the format <custom-url-slug> or executive-education/<org-slug>-<course_slug>."
},
"bootcamp-2u": {
"slug_format": "^boot-camps/[a-z0-9_]+(?:-?[a-z0-9_]+)*/[a-z0-9_]+(?:-?[a-z0-9_]+)*$|^[a-z0-9_]+(?:-[a-z0-9_]+)*$",
"error_msg": "Course URL slug contains lowercase letters, numbers, underscores, and dashes only and must be in the format <custom-url-slug> or boot-camps/<primary_subject>/<org-slug>-<course_slug>."
}
}
}`;
Expand Down
23 changes: 22 additions & 1 deletion src/utils/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from '.';
import { COURSE_URL_SLUG_PATTERN_OLD, EXECUTIVE_EDUCATION_SLUG } from '../data/constants';
import { BOOTCAMP_SLUG, COURSE_URL_SLUG_PATTERN_OLD, EXECUTIVE_EDUCATION_SLUG } from '../data/constants';
import { DEFAULT_PRODUCT_SOURCE } from '../data/constants/productSourceOptions';

const initialRuns = [
Expand Down Expand Up @@ -129,6 +129,27 @@ describe('getCourseUrlSlugPattern', () => {
});
},
);

it(
'returns the old course url slug pattern when courseType is bootcamp and updatedSlugFlag is false',
() => {
expect(
utils.getCourseUrlSlugPattern(false, 'external-source', BOOTCAMP_SLUG),
).toEqual({
slug_format: COURSE_URL_SLUG_PATTERN_OLD,
error_msg: 'Course URL slug contains lowercase letters, numbers, underscores, and dashes only.',
});
},
);

it(
'returns the bootcamp subdirectory slug pattern when courseType is bootcamp and updatedSlugFlag is true',
() => {
expect(
utils.getCourseUrlSlugPattern(true, 'external-source', BOOTCAMP_SLUG),
).toEqual(JSON.parse(COURSE_URL_SLUGS_PATTERN)['external-source'][BOOTCAMP_SLUG]);
},
);
});

describe('getCourseError', () => {
Expand Down