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'; ...@@ -4,7 +4,7 @@ import { visitUrl } from '~/lib/utils/url_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { SAVE_ERROR } from '../constants'; import { SAVE_ERROR } from '../constants';
import createComplianceFrameworkMutation from '../graphql/queries/create_compliance_framework.mutation.graphql'; 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 FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue'; import SharedForm from './shared_form.vue';
...@@ -51,18 +51,16 @@ export default { ...@@ -51,18 +51,16 @@ export default {
this.errorMessage = ''; this.errorMessage = '';
try { try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData; const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({ const { data } = await this.$apollo.mutate({
mutation: createComplianceFrameworkMutation, mutation: createComplianceFrameworkMutation,
variables: { variables: {
input: { input: {
namespacePath: this.groupPath, namespacePath: this.groupPath,
params: { params,
name,
description,
pipelineConfigurationFullPath,
color,
},
}, },
}, },
}); });
......
...@@ -7,7 +7,7 @@ import { __ } from '~/locale'; ...@@ -7,7 +7,7 @@ import { __ } from '~/locale';
import { FETCH_ERROR, SAVE_ERROR } from '../constants'; import { FETCH_ERROR, SAVE_ERROR } from '../constants';
import getComplianceFrameworkQuery from '../graphql/queries/get_compliance_framework.query.graphql'; import getComplianceFrameworkQuery from '../graphql/queries/get_compliance_framework.query.graphql';
import updateComplianceFrameworkMutation from '../graphql/queries/update_compliance_framework.mutation.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 FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue'; import SharedForm from './shared_form.vue';
...@@ -114,18 +114,16 @@ export default { ...@@ -114,18 +114,16 @@ export default {
this.saveErrorMessage = ''; this.saveErrorMessage = '';
try { try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData; const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({ const { data } = await this.$apollo.mutate({
mutation: updateComplianceFrameworkMutation, mutation: updateComplianceFrameworkMutation,
variables: { variables: {
input: { input: {
id: this.graphqlId, id: this.graphqlId,
params: { params,
name,
description,
pipelineConfigurationFullPath,
color,
},
}, },
}, },
}); });
......
...@@ -18,6 +18,16 @@ export const initialiseFormData = () => ({ ...@@ -18,6 +18,16 @@ export const initialiseFormData = () => ({
color: null, color: null,
}); });
export const getSubmissionParams = (formData, pipelineConfigurationFullPathEnabled) => {
const params = { ...formData };
if (!pipelineConfigurationFullPathEnabled) {
delete params.pipelineConfigurationFullPath;
}
return params;
};
export const getPipelineConfigurationPathParts = (path) => { export const getPipelineConfigurationPathParts = (path) => {
const [, file, group, project] = path.match(PIPELINE_CONFIGURATION_PATH_FORMAT) || []; const [, file, group, project] = path.match(PIPELINE_CONFIGURATION_PATH_FORMAT) || [];
......
...@@ -41,6 +41,43 @@ describe('Utils', () => { ...@@ -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', () => { describe('getPipelineConfigurationPathParts', () => {
it.each` it.each`
path | parts 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