Skip to content

Commit

Permalink
fix: do not require change password to change reporting configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jajjibhai008 committed Jul 12, 2023
1 parent a209dd0 commit cea88b6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/ReportingConfig/ReportingConfigForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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 }), {});

// 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;
}
}
Expand Down Expand Up @@ -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) => ({
Expand Down
32 changes: 32 additions & 0 deletions src/components/ReportingConfig/ReportingConfigForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,38 @@ describe('<ReportingConfigForm />', () => {
wrapper.find('.form-control').forEach(input => input.simulate('blur'));
expect(wrapper.find('input#encryptedPassword').hasClass('is-invalid')).toBeTruthy();
});
it.only('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(
<ReportingConfigForm
config={initialConfig}
createConfig={createConfig}
updateConfig={updateConfigMock}
availableCatalogs={availableCatalogs}
reportingConfigTypes={reportingConfigTypes}
enterpriseCustomerUuid={enterpriseCustomerUuid}
/>,
);

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((
<ReportingConfigForm
Expand Down

0 comments on commit cea88b6

Please sign in to comment.