Commit 377354af authored by Robert Hunt's avatar Robert Hunt

Exclude the pipeline config if disabled

If the pipeline config is enabled, it is added to the submission params
otherwise we won't send it. This needs to change because the backend
now expects the value to not be sent if the feature is disabled
parent 3181eaad
......@@ -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