Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export function checkTargetVersionsValidity(
if (versions.length !== uniqueVersions.size) {
return `duplicate versions not allowed`;
}
if (requiredVersions.some((item) => item.percentage < 1)) {
return `percentage must be greater than 0`;
}
if (requiredVersions.some((item) => !item.percentage)) {
return `percentage is required`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const TargetVersionsRow: React.FunctionComponent<{
onPercentageChange(newValue);
onUpdate(version, newValue);
}}
min={0}
min={1}
step={1}
max={100}
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,51 @@ describe('validateRequiredVersions', () => {
);
});

it('should throw error if percentage is 0 or undefined', () => {
it('should throw error if percentage is 0', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 100 },
{ version: '9.1.0', percentage: 0 },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed required_versions validation: percentage must be greater than 0`
)
);
});

it('should throw error if percentage is less than 1', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 100 },
{ version: '9.1.0', percentage: 0.5 },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed required_versions validation: percentage must be greater than 0`
)
);
});

it('should throw error if percentage is undefined', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 100 },
{ version: '9.1.0', percentage: undefined as any },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed required_versions validation: percentage is required`
)
);
});

it('should throw error if percentage property is missing', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 100 },
{ version: '9.1.0' } as any,
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed required_versions validation: percentage is required`
Expand Down