mock_data.js 10.9 KB
Newer Older
1
import { CI_CONFIG_STATUS_INVALID, CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants';
2
import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils';
3

4 5 6
export const mockProjectNamespace = 'user1';
export const mockProjectPath = 'project1';
export const mockProjectFullPath = `${mockProjectNamespace}/${mockProjectPath}`;
Jacques Erasmus's avatar
Jacques Erasmus committed
7
export const mockDefaultBranch = 'main';
8
export const mockNewBranch = 'new-branch';
9
export const mockNewMergeRequestPath = '/-/merge_requests/new';
10 11
export const mockCommitSha = 'aabbccdd';
export const mockCommitNextSha = 'eeffgghh';
12
export const mockLintHelpPagePath = '/-/lint-help';
13
export const mockYmlHelpPagePath = '/-/yml-help';
14
export const mockCommitMessage = 'My commit message';
15 16 17

export const mockCiConfigPath = '.gitlab-ci.yml';
export const mockCiYml = `
18 19 20 21 22
stages:
  - test
  - build

job_test_1:
23
  stage: test
24 25 26 27 28 29 30 31 32 33
  script:
    - echo "test 1"

job_test_2:
  stage: test
  script:
    - echo "test 2"

job_build:
  stage: build
34
  script:
35 36
    - echo "build"
  needs: ["job_test_2"]
37
`;
38 39 40 41 42 43 44 45 46 47 48

export const mockCiTemplateQueryResponse = {
  data: {
    project: {
      ciTemplate: {
        content: mockCiYml,
      },
    },
  },
};

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
export const mockBlobContentQueryResponse = {
  data: {
    project: { repository: { blobs: { nodes: [{ rawBlob: mockCiYml }] } } },
  },
};

export const mockBlobContentQueryResponseNoCiFile = {
  data: {
    project: { repository: { blobs: { nodes: [] } } },
  },
};

export const mockBlobContentQueryResponseEmptyCiFile = {
  data: {
    project: { repository: { blobs: { nodes: [{ rawBlob: '' }] } } },
  },
};
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
const mockJobFields = {
  beforeScript: [],
  afterScript: [],
  environment: null,
  allowFailure: false,
  tags: [],
  when: 'on_success',
  only: { refs: ['branches', 'tags'], __typename: 'CiJobLimitType' },
  except: null,
  needs: { nodes: [], __typename: 'CiConfigNeedConnection' },
  __typename: 'CiConfigJob',
};

// Mock result of the graphql query at:
// app/assets/javascripts/pipeline_editor/graphql/queries/ci_config.graphql
82 83 84 85
export const mockCiConfigQueryResponse = {
  data: {
    ciConfig: {
      errors: [],
86
      mergedYaml: mockCiYml,
87 88 89 90 91 92 93 94 95 96
      status: CI_CONFIG_STATUS_VALID,
      stages: {
        __typename: 'CiConfigStageConnection',
        nodes: [
          {
            name: 'test',
            groups: {
              nodes: [
                {
                  name: 'job_test_1',
97
                  size: 1,
98 99 100 101
                  jobs: {
                    nodes: [
                      {
                        name: 'job_test_1',
102 103
                        script: ['echo "test 1"'],
                        ...mockJobFields,
104 105 106 107 108 109 110 111
                      },
                    ],
                    __typename: 'CiConfigJobConnection',
                  },
                  __typename: 'CiConfigGroup',
                },
                {
                  name: 'job_test_2',
112
                  size: 1,
113 114 115 116
                  jobs: {
                    nodes: [
                      {
                        name: 'job_test_2',
117 118
                        script: ['echo "test 2"'],
                        ...mockJobFields,
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
                      },
                    ],
                    __typename: 'CiConfigJobConnection',
                  },
                  __typename: 'CiConfigGroup',
                },
              ],
              __typename: 'CiConfigGroupConnection',
            },
            __typename: 'CiConfigStage',
          },
          {
            name: 'build',
            groups: {
              nodes: [
                {
                  name: 'job_build',
136
                  size: 1,
137 138 139 140
                  jobs: {
                    nodes: [
                      {
                        name: 'job_build',
141 142
                        script: ['echo "build"'],
                        ...mockJobFields,
143 144 145 146 147 148 149 150 151 152 153 154 155 156
                      },
                    ],
                    __typename: 'CiConfigJobConnection',
                  },
                  __typename: 'CiConfigGroup',
                },
              ],
              __typename: 'CiConfigGroupConnection',
            },
            __typename: 'CiConfigStage',
          },
        ],
      },
      __typename: 'CiConfig',
157 158 159 160
    },
  },
};

161 162 163 164 165 166 167 168 169
export const mergeUnwrappedCiConfig = (mergedConfig) => {
  const { ciConfig } = mockCiConfigQueryResponse.data;
  return {
    ...ciConfig,
    stages: unwrapStagesWithNeeds(ciConfig.stages.nodes),
    ...mergedConfig,
  };
};

mgandres's avatar
mgandres committed
170
export const mockCommitShaResults = {
171 172
  data: {
    project: {
173 174 175
      repository: {
        tree: {
          lastCommit: {
mgandres's avatar
mgandres committed
176
            sha: mockCommitSha,
177
          },
178
        },
179 180 181 182 183 184 185 186
      },
    },
  },
};

export const mockNewCommitShaResults = {
  data: {
    project: {
187 188 189
      repository: {
        tree: {
          lastCommit: {
190 191
            sha: 'eeff1122',
          },
192
        },
193 194 195 196 197
      },
    },
  },
};

mgandres's avatar
mgandres committed
198 199 200
export const mockEmptyCommitShaResults = {
  data: {
    project: {
201 202 203 204 205 206
      repository: {
        tree: {
          lastCommit: {
            sha: '',
          },
        },
mgandres's avatar
mgandres committed
207 208 209 210 211
      },
    },
  },
};

212
export const mockProjectBranches = {
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
  data: {
    project: {
      repository: {
        branchNames: [
          'main',
          'develop',
          'production',
          'test',
          'better-feature',
          'feature-abc',
          'update-ci',
          'mock-feature',
          'test-merge-request',
          'staging',
        ],
      },
    },
230 231 232
  },
};

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
export const mockTotalBranchResults =
  mockProjectBranches.data.project.repository.branchNames.length;

export const mockSearchBranches = {
  data: {
    project: {
      repository: {
        branchNames: ['test', 'better-feature', 'update-ci', 'test-merge-request'],
      },
    },
  },
};

export const mockTotalSearchResults = mockSearchBranches.data.project.repository.branchNames.length;

export const mockEmptySearchBranches = {
  data: {
    project: {
      repository: {
        branchNames: [],
      },
    },
  },
};

export const mockBranchPaginationLimit = 10;
export const mockTotalBranches = 20; // must be greater than mockBranchPaginationLimit to test pagination

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
export const mockProjectPipeline = ({ hasStages = true } = {}) => {
  const stages = hasStages
    ? {
        edges: [
          {
            node: {
              id: 'gid://gitlab/Ci::Stage/605',
              name: 'prepare',
              status: 'success',
              detailedStatus: {
                detailsPath: '/root/sample-ci-project/-/pipelines/268#prepare',
                group: 'success',
                hasDetails: true,
                icon: 'status_success',
                id: 'success-605-605',
                label: 'passed',
                text: 'passed',
                tooltip: 'passed',
              },
            },
          },
        ],
      }
    : null;

  return {
    pipeline: {
      id: 'gid://gitlab/Ci::Pipeline/118',
      iid: '28',
      shortSha: mockCommitSha,
      status: 'SUCCESS',
292 293 294 295
      commit: {
        title: 'Update .gitlabe-ci.yml',
        webPath: '/-/commit/aabbccdd',
      },
296 297 298 299 300 301 302
      detailedStatus: {
        detailsPath: '/root/sample-ci-project/-/pipelines/118',
        group: 'success',
        icon: 'status_success',
        text: 'passed',
      },
      stages,
303
    },
304
  };
305 306
};

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
export const mockLinkedPipelines = ({ hasDownstream = true, hasUpstream = true } = {}) => {
  let upstream = null;
  let downstream = {
    nodes: [],
    __typename: 'PipelineConnection',
  };

  if (hasDownstream) {
    downstream = {
      nodes: [
        {
          id: 'gid://gitlab/Ci::Pipeline/612',
          path: '/root/job-log-sections/-/pipelines/612',
          project: { name: 'job-log-sections', __typename: 'Project' },
          detailedStatus: {
            group: 'success',
            icon: 'status_success',
            label: 'passed',
            __typename: 'DetailedStatus',
          },
          __typename: 'Pipeline',
        },
      ],
      __typename: 'PipelineConnection',
    };
  }

  if (hasUpstream) {
    upstream = {
      id: 'gid://gitlab/Ci::Pipeline/610',
      path: '/root/trigger-downstream/-/pipelines/610',
      project: { name: 'trigger-downstream', __typename: 'Project' },
      detailedStatus: {
        group: 'success',
        icon: 'status_success',
        label: 'passed',
        __typename: 'DetailedStatus',
      },
      __typename: 'Pipeline',
    };
  }

  return {
    data: {
      project: {
        pipeline: {
          path: '/root/ci-project/-/pipelines/790',
          downstream,
          upstream,
        },
        __typename: 'Project',
      },
    },
  };
};

363 364
export const mockLintResponse = {
  valid: true,
365 366
  mergedYaml: mockCiYml,
  status: CI_CONFIG_STATUS_VALID,
367 368 369 370 371 372 373 374 375 376 377 378 379 380
  errors: [],
  warnings: [],
  jobs: [
    {
      name: 'job_1',
      stage: 'test',
      before_script: ["echo 'before script 1'"],
      script: ["echo 'script 1'"],
      after_script: ["echo 'after script 1"],
      tag_list: ['tag 1'],
      environment: 'prd',
      when: 'on_success',
      allow_failure: false,
      only: null,
Jacques Erasmus's avatar
Jacques Erasmus committed
381
      except: { refs: ['main@gitlab-org/gitlab', '/^release/.*$/@gitlab-org/gitlab'] },
382 383 384 385 386 387 388 389 390 391 392 393
    },
    {
      name: 'job_2',
      stage: 'test',
      before_script: ["echo 'before script 2'"],
      script: ["echo 'script 2'"],
      after_script: ["echo 'after script 2"],
      tag_list: ['tag 2'],
      environment: 'stg',
      when: 'on_success',
      allow_failure: true,
      only: { refs: ['web', 'chat', 'pushes'] },
Jacques Erasmus's avatar
Jacques Erasmus committed
394
      except: { refs: ['main@gitlab-org/gitlab', '/^release/.*$/@gitlab-org/gitlab'] },
395 396 397 398
    },
  ],
};

399 400 401 402 403 404 405 406
export const mockLintResponseWithoutMerged = {
  valid: false,
  status: CI_CONFIG_STATUS_INVALID,
  errors: ['error'],
  warnings: [],
  jobs: [],
};

407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
export const mockJobs = [
  {
    name: 'job_1',
    stage: 'build',
    beforeScript: [],
    script: ["echo 'Building'"],
    afterScript: [],
    tagList: [],
    environment: null,
    when: 'on_success',
    allowFailure: true,
    only: { refs: ['web', 'chat', 'pushes'] },
    except: null,
  },
  {
    name: 'multi_project_job',
    stage: 'test',
    beforeScript: [],
    script: [],
    afterScript: [],
    tagList: [],
    environment: null,
    when: 'on_success',
    allowFailure: false,
    only: { refs: ['branches', 'tags'] },
    except: null,
  },
  {
    name: 'job_2',
    stage: 'test',
    beforeScript: ["echo 'before script'"],
    script: ["echo 'script'"],
    afterScript: ["echo 'after script"],
    tagList: [],
    environment: null,
    when: 'on_success',
    allowFailure: false,
    only: { refs: ['branches@gitlab-org/gitlab'] },
Jacques Erasmus's avatar
Jacques Erasmus committed
445
    except: { refs: ['main@gitlab-org/gitlab', '/^release/.*$/@gitlab-org/gitlab'] },
446 447 448 449 450 451 452 453 454 455
  },
];

export const mockErrors = [
  '"job_1 job: chosen stage does not exist; available stages are .pre, build, test, deploy, .post"',
];

export const mockWarnings = [
  '"jobs:multi_project_job may allow multiple pipelines to run for a single action due to `rules:when` clause with no `workflow:rules` - read more: https://docs.gitlab.com/ee/ci/troubleshooting.html#pipeline-warnings"',
];