fixing some validation issues with edit policy (#27045)
* fixing validation issues with editing existing policy * preventing less than 1 values for max size and max age and adding tests
This commit is contained in:
parent
2fc7deebf9
commit
c4900f7daa
|
@ -171,6 +171,50 @@ describe('edit policy', () => {
|
|||
expectedErrorMessages(rendered, [policyNameStartsWithUnderscoreErrorMessage]);
|
||||
});
|
||||
});
|
||||
describe('hot phase', () => {
|
||||
test('should show errors when trying to save with no max size and no max age', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
setPolicyName(rendered, 'mypolicy');
|
||||
save(rendered);
|
||||
expectedErrorMessages(rendered, [maximumSizeRequiredMessage, maximumAgeRequiredMessage]);
|
||||
});
|
||||
test('should show number above 0 required error when trying to save with -1 for max size', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
setPolicyName(rendered, 'mypolicy');
|
||||
const maxSizeInput = rendered.find(`input#hot-selectedMaxSizeStored`);
|
||||
maxSizeInput.simulate('change', { target: { value: -1 } });
|
||||
rendered.update();
|
||||
save(rendered);
|
||||
expectedErrorMessages(rendered, [positiveNumbersAboveZeroErrorMessage]);
|
||||
});
|
||||
test('should show number above 0 required error when trying to save with 0 for max size', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
setPolicyName(rendered, 'mypolicy');
|
||||
const maxSizeInput = rendered.find(`input#hot-selectedMaxSizeStored`);
|
||||
maxSizeInput.simulate('change', { target: { value: 0 } });
|
||||
rendered.update();
|
||||
save(rendered);
|
||||
expectedErrorMessages(rendered, [positiveNumbersAboveZeroErrorMessage]);
|
||||
});
|
||||
test('should show number above 0 required error when trying to save with -1 for max age', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
setPolicyName(rendered, 'mypolicy');
|
||||
const maxSizeInput = rendered.find(`input#hot-selectedMaxAge`);
|
||||
maxSizeInput.simulate('change', { target: { value: -1 } });
|
||||
rendered.update();
|
||||
save(rendered);
|
||||
expectedErrorMessages(rendered, [positiveNumbersAboveZeroErrorMessage]);
|
||||
});
|
||||
test('should show number above 0 required error when trying to save with 0 for max age', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
setPolicyName(rendered, 'mypolicy');
|
||||
const maxSizeInput = rendered.find(`input#hot-selectedMaxAge`);
|
||||
maxSizeInput.simulate('change', { target: { value: 0 } });
|
||||
rendered.update();
|
||||
save(rendered);
|
||||
expectedErrorMessages(rendered, [positiveNumbersAboveZeroErrorMessage]);
|
||||
});
|
||||
});
|
||||
describe('warm phase', () => {
|
||||
test('should show number required error when trying to save empty warm phase', () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
|
|
|
@ -60,8 +60,9 @@ export const validatePhase = (type, phase, errors) => {
|
|||
|
||||
for (const numberedAttribute of PHASE_ATTRIBUTES_THAT_ARE_NUMBERS_VALIDATE) {
|
||||
if (phase.hasOwnProperty(numberedAttribute)) {
|
||||
// If WARM_PHASE_ON_ROLLOVER there is no need to validate this
|
||||
if (numberedAttribute === PHASE_ROLLOVER_MINIMUM_AGE && phase[WARM_PHASE_ON_ROLLOVER]) {
|
||||
// If WARM_PHASE_ON_ROLLOVER or PHASE_HOT there is no need to validate this
|
||||
if (numberedAttribute === PHASE_ROLLOVER_MINIMUM_AGE
|
||||
&& (phase[WARM_PHASE_ON_ROLLOVER] || type === PHASE_HOT)) {
|
||||
continue;
|
||||
}
|
||||
// If shrink is disabled, there is no need to validate this
|
||||
|
@ -100,6 +101,16 @@ export const validatePhase = (type, phase, errors) => {
|
|||
maximumSizeRequiredMessage
|
||||
];
|
||||
}
|
||||
if (isNumber(phase[PHASE_ROLLOVER_MAX_AGE]) && phase[PHASE_ROLLOVER_MAX_AGE] < 1) {
|
||||
phaseErrors[PHASE_ROLLOVER_MAX_AGE] = [
|
||||
positiveNumbersAboveZeroErrorMessage
|
||||
];
|
||||
}
|
||||
if (isNumber(phase[PHASE_ROLLOVER_MAX_SIZE_STORED]) && phase[PHASE_ROLLOVER_MAX_SIZE_STORED] < 1) {
|
||||
phaseErrors[PHASE_ROLLOVER_MAX_SIZE_STORED] = [
|
||||
positiveNumbersAboveZeroErrorMessage
|
||||
];
|
||||
}
|
||||
}
|
||||
if (phase[PHASE_SHRINK_ENABLED]) {
|
||||
if (!isNumber(phase[PHASE_PRIMARY_SHARD_COUNT])) {
|
||||
|
@ -172,7 +183,7 @@ export const validateLifecycle = state => {
|
|||
|
||||
if (getSaveAsNewPolicy(state) && getSelectedOriginalPolicyName(state) === getSelectedPolicyName(state)) {
|
||||
errors[STRUCTURE_POLICY_NAME].push(policyNameMustBeDifferentErrorMessage);
|
||||
} else {
|
||||
} else if (getSelectedOriginalPolicyName(state) !== getSelectedPolicyName(state)) {
|
||||
const policyNames = getPolicies(state).map(policy => policy.name);
|
||||
if (policyNames.includes(getSelectedPolicyName(state))) {
|
||||
errors[STRUCTURE_POLICY_NAME].push(policyNameAlreadyUsedErrorMessage);
|
||||
|
|
|
@ -268,6 +268,5 @@ export const phaseToES = (state, phase) => {
|
|||
number_of_shards: phase[PHASE_PRIMARY_SHARD_COUNT]
|
||||
};
|
||||
}
|
||||
console.log("PHASE", phase);
|
||||
return esPhase;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue