Skip to content

Commit

Permalink
feat: do not require staff when submitting runs (#908)
Browse files Browse the repository at this point in the history
* feat: do not require staff when submitting runs

* chore: Ensure optional tag appears for staff field
  • Loading branch information
DawoudSheraz authored Aug 25, 2023
1 parent 484b733 commit ccd91ce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/components/EditCoursePage/CollapsibleCourseRun.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ class CollapsibleCourseRun extends React.Component {
</p>
</div>
)}
optional
/>
<Field
name={`${courseId}.staff`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ exports[`Collapsible Course Run renders correctly when given a published course
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -960,7 +960,7 @@ exports[`Collapsible Course Run renders correctly when given an unpublished cour
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -1574,7 +1574,7 @@ exports[`Collapsible Course Run renders correctly when submitting for review 1`]
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -2188,7 +2188,7 @@ exports[`Collapsible Course Run renders correctly when submitting for review and
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -2814,7 +2814,7 @@ exports[`Collapsible Course Run renders correctly with a course run type 1`] = `
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -3440,7 +3440,7 @@ exports[`Collapsible Course Run renders correctly with external key field enable
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down Expand Up @@ -4071,7 +4071,7 @@ exports[`Collapsible Course Run renders correctly with no fields 1`] = `
</div>
}
id="test-course.staff.label"
optional={false}
optional={true}
text="Staff"
/>
<Field
Expand Down
14 changes: 2 additions & 12 deletions src/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const handleCourseEditFail = (errors) => {
};

const editCourseValidate = (values, props) => {
const { targetRun, registeredFields } = props;
const { targetRun } = props;

if (!targetRun || targetRun.status === PUBLISHED) {
return {};
Expand Down Expand Up @@ -156,17 +156,7 @@ const editCourseValidate = (values, props) => {
const { key: targetKey } = targetRun;
const isSubmittingRun = run.key === targetKey;
if (isSubmittingRun) {
// naive check to deteremine if track is executive education or not
const isExecutiveEducation = registeredFields
&& registeredFields['prices.paid-executive-education']
&& registeredFields['prices.paid-executive-education'].count;

// naive check to deteremine if track is bootcamp or not
const isBootcamp = registeredFields
&& registeredFields['prices.paid-bootcamp']
&& registeredFields['prices.paid-bootcamp'].count;

const runRequiredFields = (isExecutiveEducation || isBootcamp) ? ['transcript_languages'] : ['transcript_languages', 'staff'];
const runRequiredFields = ['transcript_languages'];
const runErrors = {};
runRequiredFields.forEach((fieldName) => {
const value = run[fieldName];
Expand Down
72 changes: 2 additions & 70 deletions src/utils/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('editCourseValidate', () => {
expect(editCourseValidate(values, { targetRun: unpublishedTargetRun })).toEqual(expectedErrors);
});

it('returns errors on submitting course runs with missing staff', () => {
it('does not return error when submitting course runs with missing staff', () => {
const values = {
short_description: 'Short',
full_description: 'Full',
Expand All @@ -209,75 +209,7 @@ describe('editCourseValidate', () => {
],
};

const expectedErrors = {
course_runs: [
null,
{
staff: requiredMessage,
},
],
};
expect(editCourseValidate(values, { targetRun: unpublishedTargetRun })).toEqual(expectedErrors);
});
it('returns no error on submitting 2U executive education course runs with missing staff', () => {
const values = {
short_description: 'Short',
full_description: 'Full',
outcome: 'Outcome',
imageSrc: 'base64;encodedimage',
course_runs: [
{
key: 'NonSubmittingTestRun',
},
{
key: 'TestRun',
transcript_languages: [
{
dummy_field: 'Transcript languages dummy field',
},
],
staff: [],
},
],
};
expect(editCourseValidate(values, {
targetRun: unpublishedTargetRun,
registeredFields: {
'prices.paid-executive-education': {
count: 1,
},
},
})).toEqual({});
});
it('returns no error on submitting 2U bootcamp runs with missing staff', () => {
const values = {
short_description: 'Short',
full_description: 'Full',
outcome: 'Outcome',
imageSrc: 'base64;encodedimage',
course_runs: [
{
key: 'NonSubmittingTestRun',
},
{
key: 'TestRun',
transcript_languages: [
{
dummy_field: 'Transcript languages dummy field',
},
],
staff: [],
},
],
};
expect(editCourseValidate(values, {
targetRun: unpublishedTargetRun,
registeredFields: {
'prices.paid-bootcamp': {
count: 1,
},
},
})).toEqual({});
expect(editCourseValidate(values, { targetRun: unpublishedTargetRun })).toEqual({});
});

test.each([
Expand Down

0 comments on commit ccd91ce

Please sign in to comment.