diff --git a/src/components/ReportingConfig/ReportingConfigForm.jsx b/src/components/ReportingConfig/ReportingConfigForm.jsx
index c2c9d8c804..4e662c6a11 100644
--- a/src/components/ReportingConfig/ReportingConfigForm.jsx
+++ b/src/components/ReportingConfig/ReportingConfigForm.jsx
@@ -55,7 +55,7 @@ class ReportingConfigForm extends React.Component {
* @param {FormData} formData
* @param {[String]} requiredFields
*/
- validateReportingForm = (formData, requiredFields) => {
+ validateReportingForm = (config, formData, requiredFields) => {
const invalidFields = requiredFields
.filter(field => !formData.get(field))
.reduce((prevFields, currField) => ({ ...prevFields, [currField]: true }), {});
@@ -63,7 +63,7 @@ class ReportingConfigForm extends React.Component {
// Password is conditionally required only when pgp key will not be present
// and delivery method is email
if (!formData.get('pgpEncryptionKey') && formData.get('deliveryMethod') === 'email') {
- if (!formData.get('encryptedPassword')) {
+ if (!formData.get('encryptedPassword') && !config?.encryptedPassword) {
invalidFields.encryptedPassword = true;
}
}
@@ -131,7 +131,7 @@ class ReportingConfigForm extends React.Component {
requiredFields = config ? [...REQUIRED_SFTP_FIELDS] : [...REQUIRED_NEW_SFTP_FEILDS];
}
// validate the form
- const invalidFields = this.validateReportingForm(formData, requiredFields);
+ const invalidFields = this.validateReportingForm(config, formData, requiredFields);
// if there are invalid fields, reflect that in the UI
if (!isEmpty(invalidFields)) {
this.setState((state) => ({
diff --git a/src/components/ReportingConfig/ReportingConfigForm.test.jsx b/src/components/ReportingConfig/ReportingConfigForm.test.jsx
index 1e29207089..0263df7fa0 100644
--- a/src/components/ReportingConfig/ReportingConfigForm.test.jsx
+++ b/src/components/ReportingConfig/ReportingConfigForm.test.jsx
@@ -384,6 +384,38 @@ describe('', () => {
wrapper.find('.form-control').forEach(input => input.simulate('blur'));
expect(wrapper.find('input#encryptedPassword').hasClass('is-invalid')).toBeTruthy();
});
+ it('Password is not required while updating if it is already present and delivery method is email', async () => {
+ const updateConfigMock = jest.fn().mockResolvedValue();
+ const initialConfig = {
+ ...defaultConfig,
+ };
+ initialConfig.encryptedPassword = 'some_pass';
+ initialConfig.pgpEncryptionKey = '';
+ initialConfig.hourOfDay = 4;
+ const requiredFields = ['hourOfDay', 'emailRaw'];
+ const wrapper = mount(
+ ,
+ );
+
+ const updatedFormData = new FormData();
+ updatedFormData.append('deliveryMethod', 'email');
+ updatedFormData.append('pgpEncryptionKey', '');
+ updatedFormData.append('encryptedPassword', '');
+
+ const invalidFields = await wrapper.instance().validateReportingForm(
+ initialConfig,
+ updatedFormData,
+ requiredFields,
+ );
+ expect('encryptedPassword' in invalidFields).toBe(false);
+ });
it('Submit enterprise uuid upon report config creation', async () => {
const wrapper = mount((