Skip to content

Commit

Permalink
chore: add subdirectory slug format for bootcamps (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 authored Sep 8, 2023
1 parent ccd91ce commit 8e7726a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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

0 comments on commit 8e7726a

Please sign in to comment.