Commit bfa4ebdd authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'compliance-frameworks-do-not-submit-pipeline-config-when-disabled' into 'master'

Exclude the pipeline configuration path from form submission if it is disabled

See merge request gitlab-org/gitlab!56740
parents f254fe87 377354af
......@@ -4,7 +4,7 @@ import { visitUrl } from '~/lib/utils/url_utility';
import { s__ } from '~/locale';
import { SAVE_ERROR } from '../constants';
import createComplianceFrameworkMutation from '../graphql/queries/create_compliance_framework.mutation.graphql';
import { initialiseFormData } from '../utils';
import { getSubmissionParams, initialiseFormData } from '../utils';
import FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue';
......@@ -51,18 +51,16 @@ export default {
this.errorMessage = '';
try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData;
const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({
mutation: createComplianceFrameworkMutation,
variables: {
input: {
namespacePath: this.groupPath,
params: {
name,
description,
pipelineConfigurationFullPath,
color,
},
params,
},
},
});
......
......@@ -7,7 +7,7 @@ import { __ } from '~/locale';
import { FETCH_ERROR, SAVE_ERROR } from '../constants';
import getComplianceFrameworkQuery from '../graphql/queries/get_compliance_framework.query.graphql';
import updateComplianceFrameworkMutation from '../graphql/queries/update_compliance_framework.mutation.graphql';
import { initialiseFormData } from '../utils';
import { getSubmissionParams, initialiseFormData } from '../utils';
import FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue';
......@@ -114,18 +114,16 @@ export default {
this.saveErrorMessage = '';
try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData;
const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({
mutation: updateComplianceFrameworkMutation,
variables: {
input: {
id: this.graphqlId,
params: {
name,
description,
pipelineConfigurationFullPath,
color,
},
params,
},
},
});
......
......@@ -18,6 +18,16 @@ export const initialiseFormData = () => ({
color: null,
});
export const getSubmissionParams = (formData, pipelineConfigurationFullPathEnabled) => {
const params = { ...formData };
if (!pipelineConfigurationFullPathEnabled) {
delete params.pipelineConfigurationFullPath;
}
return params;
};
export const getPipelineConfigurationPathParts = (path) => {
const [, file, group, project] = path.match(PIPELINE_CONFIGURATION_PATH_FORMAT) || [];
......
......@@ -41,6 +41,43 @@ describe('Utils', () => {
});
});
describe('getSubmissionParams', () => {
const baseFormData = {
name: 'a',
description: 'b',
color: '#000',
};
it.each([true, false])(
'should return the initial object when pipelineConfigurationFullPath is undefined and pipelineConfigurationFullPathEnabled is %s',
(enabled) => {
expect(Utils.getSubmissionParams(baseFormData, enabled)).toStrictEqual(baseFormData);
},
);
it.each`
pipelineConfigurationFullPath | pipelineConfigurationFullPathEnabled
${'a/b'} | ${true}
${null} | ${true}
${'a/b'} | ${false}
${null} | ${false}
`(
'should return the correct object when pipelineConfigurationFullPathEnabled is $pipelineConfigurationFullPathEnabled',
({ pipelineConfigurationFullPath, pipelineConfigurationFullPathEnabled }) => {
const formData = Utils.getSubmissionParams(
{ ...baseFormData, pipelineConfigurationFullPath },
pipelineConfigurationFullPathEnabled,
);
if (pipelineConfigurationFullPathEnabled) {
expect(formData).toStrictEqual({ ...baseFormData, pipelineConfigurationFullPath });
} else {
expect(formData).toStrictEqual(baseFormData);
}
},
);
});
describe('getPipelineConfigurationPathParts', () => {
it.each`
path | parts
......
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