summaryrefslogtreecommitdiff
path: root/spec/frontend/commit/pipelines/utils_spec.js
blob: 472e35a6eb3a105f338f52781476dc11e3dedc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { formatStages } from '~/projects/commit_box/info/utils';

const graphqlStage = [
  {
    __typename: 'CiStage',
    name: 'deploy',
    detailedStatus: {
      __typename: 'DetailedStatus',
      icon: 'status_success',
      group: 'success',
      id: 'success-409-409',
    },
  },
];

const restStage = [
  {
    name: 'deploy',
    title: 'deploy: passed',
    status: {
      icon: 'status_success',
      text: 'passed',
      label: 'passed',
      group: 'success',
      tooltip: 'passed',
      has_details: true,
      details_path: '/root/ci-project/-/pipelines/318#deploy',
      illustration: null,
      favicon:
        '/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png',
    },
    path: '/root/ci-project/-/pipelines/318#deploy',
    dropdown_path: '/root/ci-project/-/pipelines/318/stage.json?stage=deploy',
  },
];

describe('Utils', () => {
  it('combines REST and GraphQL stages correctly for component', () => {
    expect(formatStages(graphqlStage, restStage)).toEqual([
      {
        dropdown_path: '/root/ci-project/-/pipelines/318/stage.json?stage=deploy',
        name: 'deploy',
        status: {
          __typename: 'DetailedStatus',
          group: 'success',
          icon: 'status_success',
          id: 'success-409-409',
        },
        title: 'deploy: passed',
      },
    ]);
  });

  it('throws an error if arrays are not the same length', () => {
    expect(() => {
      formatStages(graphqlStage, []);
    }).toThrow('Rest stages and graphQl stages must be the same length');
  });
});