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 11, 2023
1 parent f0ea4b0 commit 63505eb
Show file tree
Hide file tree
Showing 2 changed files with 39 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
36 changes: 36 additions & 0 deletions src/components/ReportingConfig/ReportingConfigForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,42 @@ describe('<ReportingConfigForm />', () => {
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,
deliveryMethod: 'email',
encryptedPassword: '',
};

const wrapper = mount(
<ReportingConfigForm
config={initialConfig}
createConfig={createConfig}
updateConfig={updateConfigMock}
availableCatalogs={availableCatalogs}
reportingConfigTypes={reportingConfigTypes}
enterpriseCustomerUuid={enterpriseCustomerUuid}
/>,
);

// Update the report
const updatedConfig = {
...initialConfig,
active: false,
enterpriseCustomer: [{
uuid: 'test-customer-uuid',
}],
};
const updateFormData = new FormData();
Object.entries(updatedConfig).forEach(([key, value]) => {
updateFormData.append(key, value);
});
await wrapper.instance().handleSubmit(updateFormData, updatedConfig);

wrapper.find('.form-control').forEach(input => input.simulate('blur'));
expect(wrapper.find('input#encryptedPassword').hasClass('is-invalid')).toBeTruthy();
});
it('Submit enterprise uuid upon report config creation', async () => {
const wrapper = mount((
<ReportingConfigForm
Expand Down

0 comments on commit 63505eb

Please sign in to comment.