Skip to content

Commit

Permalink
Merge pull request #521 from edx/trhodes/fix-email-validation
Browse files Browse the repository at this point in the history
fix: license reminder email doesn't need subject
  • Loading branch information
taliaedX authored Mar 30, 2021
2 parents 6b4ec89 + 4cdeb24 commit 913348f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/LicenseRemindModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LicenseRemindModal extends React.Component {
sendLicenseReminder,
} = this.props;
// Validate form data
validateEmailTemplateForm(formData, 'email-template-body');
validateEmailTemplateForm(formData, 'email-template-body', false);
// Configure the options to send to the assignment reminder API endpoint
const options = {
greeting: formData['email-template-greeting'],
Expand Down
4 changes: 2 additions & 2 deletions src/data/validation/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ is invalid. Please try again.`;
return errorsDict;
};

const validateEmailTemplateForm = (formData, templateKey) => {
const validateEmailTemplateForm = (formData, templateKey, isSubjectRequired = true) => {
// Takes redux form data and a string template key
// Throws an error or otherwise returns nothing.
const errorsDict = validateEmailTemplateFields(formData, templateKey);
const errorsDict = validateEmailTemplateFields(formData, templateKey, isSubjectRequired);

if (Object.keys(errorsDict) > 1 || errorsDict._error.length > 0) {
throw new SubmissionError(errorsDict);
Expand Down
7 changes: 7 additions & 0 deletions src/data/validation/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ describe('email validation', () => {
formData[EMAIL_TEMPLATE_SUBJECT_KEY] = 'Subject';
expect(validateEmailTemplateForm(formData, templateKey)).toBeUndefined();
});

it('returns nothing on successful validation (and no subject is required)', () => {
const formData = new FormData();
formData[EMAIL_ADDRESS_CSV_FORM_DATA] = ['[email protected]', '[email protected]'];
formData[templateKey] = 'Template 1';
expect(validateEmailTemplateForm(formData, templateKey, false)).toBeUndefined();
});
});

describe('validate email address and template form', () => {
Expand Down

0 comments on commit 913348f

Please sign in to comment.