Commit 53098c16 authored by Alexander Turinske's avatar Alexander Turinske Committed by Nicolò Maria Mezzopera

Update scan execution policy drawer

parent 969ab7fe
......@@ -47,6 +47,12 @@ const humanizePipelineRule = (rule) => {
};
const humanizeScheduleRule = (rule) => {
if (rule.clusters) {
return sprintf(s__('SecurityOrchestration|Scan to be performed %{cadence}'), {
cadence: humanizeCadence(rule.cadence),
});
}
return sprintf(s__('SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}'), {
cadence: humanizeCadence(rule.cadence),
branches: humanizeBranches(rule.branches),
......@@ -74,7 +80,7 @@ export const humanizeActions = (actions) => {
*/
export const humanizeRules = (rules) => {
const humanizedRules = rules.reduce((acc, curr) => {
return curr.branches ? [...acc, HUMANIZE_RULES_METHODS[curr.type](curr)] : acc;
return curr.branches || curr.clusters ? [...acc, HUMANIZE_RULES_METHODS[curr.type](curr)] : acc;
}, []);
return humanizedRules.length ? humanizedRules : [NO_RULE_MESSAGE];
......
......@@ -4,6 +4,13 @@ import {
NO_RULE_MESSAGE,
} from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib';
jest.mock('~/locale', () => ({
getPreferredLocales: jest.fn().mockReturnValue(['en']),
sprintf: jest.requireActual('~/locale').sprintf,
s__: jest.requireActual('~/locale').s__, // eslint-disable-line no-underscore-dangle
n__: jest.requireActual('~/locale').n__, // eslint-disable-line no-underscore-dangle
}));
const mockActions = [
{ scan: 'dast', scanner_profile: 'Scanner Profile', site_profile: 'Site Profile' },
{ scan: 'dast', scanner_profile: 'Scanner Profile 01', site_profile: 'Site Profile 01' },
......@@ -14,6 +21,11 @@ const mockRules = [
{ type: 'schedule', cadence: '*/10 * * * *', branches: ['main'] },
{ type: 'pipeline', branches: ['release/*', 'staging'] },
{ type: 'pipeline', branches: ['release/1.*', 'canary', 'staging'] },
{
type: 'schedule',
cadence: '* */20 4 * *',
clusters: { protect: { namespaces: ['default-cluster'] } },
},
{ type: 'pipeline' },
];
......@@ -34,17 +46,12 @@ describe('humanizeActions', () => {
});
describe('humanizeRules', () => {
beforeEach(() => {
// Need to spy on window.navigator.languages as it is read-only
jest.spyOn(window.navigator, 'languages', 'get').mockReturnValueOnce(['en']);
});
it('returns the empty rules message in an Array if no rules are specified', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
});
it('returns the empty rules message in an Array if a single rule is passed in without a branch', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
it('returns the empty rules message in an Array if a single rule is passed in without a branch or cluster', () => {
expect(humanizeRules([mockRules[4]])).toStrictEqual([NO_RULE_MESSAGE]);
});
it('returns a single rule as a human-readable string', () => {
......@@ -58,6 +65,7 @@ describe('humanizeRules', () => {
'Scan to be performed every 10 minutes, every hour, every day on the main branch',
'Scan to be performed on every pipeline on the release/* and staging branches',
'Scan to be performed on every pipeline on the release/1.*, canary and staging branches',
'Scan to be performed every minute, every 20 hours, on day 4 of the month',
]);
});
});
......@@ -30959,6 +30959,9 @@ msgstr ""
msgid "SecurityOrchestration|Scan execution policies can only be created by project owners."
msgstr ""
msgid "SecurityOrchestration|Scan to be performed %{cadence}"
msgstr ""
msgid "SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}"
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment