Commit 0c0a6e9e authored by Alexander Turinske's avatar Alexander Turinske

Fix scan execution policy creation issue

- when a new project is created, the default branch was not
  being retrieved with it
- retrieve default branch
- update tests
parent 64b00a0b
...@@ -31,12 +31,12 @@ const assignSecurityPolicyProject = async (projectPath) => { ...@@ -31,12 +31,12 @@ const assignSecurityPolicyProject = async (projectPath) => {
}, },
}); });
return { ...project, errors }; return { ...project, branch: project?.branch?.rootRef, errors };
}; };
/** /**
* Creates a merge request for the changes to the policy file * Creates a merge request for the changes to the policy file
* @param {Object} payload contains the path to the project, the branch to merge on the project, and the branch to merge into * @param {Object} payload contains the path to the parent project, the branch to merge on the project, and the branch to merge into
* @returns {Object} contains the id of the merge request and any errors * @returns {Object} contains the id of the merge request and any errors
*/ */
const createMergeRequest = async ({ projectPath, sourceBranch, targetBranch }) => { const createMergeRequest = async ({ projectPath, sourceBranch, targetBranch }) => {
...@@ -98,7 +98,7 @@ export const savePolicy = async ({ assignedPolicyProject, projectPath, yamlEdito ...@@ -98,7 +98,7 @@ export const savePolicy = async ({ assignedPolicyProject, projectPath, yamlEdito
checkForErrors(currentAssignedPolicyProject); checkForErrors(currentAssignedPolicyProject);
const newPolicyCommitBranch = await updatePolicy({ const newPolicyCommitBranch = await updatePolicy({
projectPath: currentAssignedPolicyProject.fullPath, projectPath,
yamlEditorValue, yamlEditorValue,
}); });
......
...@@ -3,6 +3,9 @@ mutation createPolicyProject($projectPath: ID!) { ...@@ -3,6 +3,9 @@ mutation createPolicyProject($projectPath: ID!) {
project { project {
fullPath fullPath
id id
branch: repository {
rootRef
}
} }
errors errors
} }
......
...@@ -8,7 +8,11 @@ import createMergeRequestMutation from '~/graphql_shared/mutations/create_merge_ ...@@ -8,7 +8,11 @@ import createMergeRequestMutation from '~/graphql_shared/mutations/create_merge_
jest.mock('ee/threat_monitoring/utils'); jest.mock('ee/threat_monitoring/utils');
const defaultAssignedPolicyProject = { fullPath: 'path/to/policy-project', branch: 'main' }; const defaultAssignedPolicyProject = { fullPath: 'path/to/policy-project', branch: 'main' };
const newAssignedPolicyProject = { fullPath: 'path/to/new-project', branch: 'main' }; const newAssignedPolicyProject = {
id: '02',
fullPath: 'path/to/new-project',
branch: { rootRef: 'main' },
};
const projectPath = 'path/to/current-project'; const projectPath = 'path/to/current-project';
const yamlEditorValue = 'some yaml'; const yamlEditorValue = 'some yaml';
const createSavePolicyInput = (assignedPolicyProject = defaultAssignedPolicyProject) => ({ const createSavePolicyInput = (assignedPolicyProject = defaultAssignedPolicyProject) => ({
...@@ -56,7 +60,12 @@ describe('savePolicy', () => { ...@@ -56,7 +60,12 @@ describe('savePolicy', () => {
createSavePolicyInput(DEFAULT_ASSIGNED_POLICY_PROJECT), createSavePolicyInput(DEFAULT_ASSIGNED_POLICY_PROJECT),
); );
expect(currentAssignedPolicyProject).toStrictEqual({ ...newAssignedPolicyProject, errors: [] }); expect(currentAssignedPolicyProject).toStrictEqual({
id: newAssignedPolicyProject.id,
fullPath: newAssignedPolicyProject.fullPath,
branch: newAssignedPolicyProject.branch.rootRef,
errors: [],
});
expect(mergeRequest).toStrictEqual({ id: '01', errors: [] }); expect(mergeRequest).toStrictEqual({ id: '01', errors: [] });
}); });
......
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