File: deployment_data_transformation_helper_spec.js

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (121 lines) | stat: -rw-r--r-- 3,739 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
  getAuthorFromCommit,
  getCommitFromDeploymentNode,
  convertToDeploymentTableRow,
} from '~/environments/helpers/deployment_data_transformation_helper';

describe('deployment_data_transformation_helper', () => {
  const commitWithAuthor = {
    id: 'gid://gitlab/CommitPresenter/0cb48dd5deddb7632fd7c3defb16075fc6c3ca74',
    shortId: '0cb48dd5',
    message: 'Update .gitlab-ci.yml file',
    webUrl:
      'http://gdk.test:3000/gitlab-org/pipelinestest/-/commit/0cb48dd5deddb7632fd7c3defb16075fc6c3ca74',
    authorGravatar:
      'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
    authorName: 'Administrator',
    authorEmail: 'admin@example.com',
    author: {
      id: 'gid://gitlab/User/1',
      name: 'Administrator',
      avatarUrl: '/uploads/-/system/user/avatar/1/avatar.png',
      webUrl: 'http://gdk.test:3000/root',
    },
  };

  const commitWithoutAuthor = {
    id: 'gid://gitlab/CommitPresenter/02274a949a88c9aef68a29685d99bd9a661a7f9b',
    shortId: '02274a94',
    message: 'Commit message',
    webUrl:
      'http://gdk.test:3000/gitlab-org/pipelinestest/-/commit/02274a949a88c9aef68a29685d99bd9a661a7f9b',
    authorGravatar:
      'https://www.gravatar.com/avatar/91811aee1dec1b2655fa56f894e9e7c9?s=80&d=identicon',
    authorName: 'Andrei Zubov',
    authorEmail: 'azubov@gitlab.com',
    author: null,
  };

  const deploymentNode = {
    id: 'gid://gitlab/Deployment/76',
    iid: '31',
    status: 'SUCCESS',
    createdAt: '2022-10-17T07:44:17Z',
    ref: 'main',
    tag: false,
    job: {
      name: 'deploy-prod',
      refName: 'main',
      id: 'gid://gitlab/Ci::Build/860',
      webPath: '/gitlab-org/pipelinestest/-/jobs/860',
      deploymentPipeline: {
        jobs: {
          nodes: [
            {
              name: 'deploy-staging',
              playable: true,
              scheduledAt: '2023-01-17T11:02:41.369Z',
              webPath: 'https://gdk.test:3000/redeploy',
            },
            {
              name: 'deploy-production',
              playable: true,
              scheduledAt: '2023-01-17T11:02:41.369Z',
              webPath: 'https://gdk.test:3000/redeploy',
            },
          ],
        },
      },
    },
    commit: commitWithAuthor,
    triggerer: {
      id: 'gid://gitlab/User/1',
      webUrl: 'http://gdk.test:3000/root',
      name: 'Administrator',
      avatarUrl: '/uploads/-/system/user/avatar/1/avatar.png',
    },
    finishedAt: '2022-10-17T07:44:43Z',
  };

  const deploymentNodeWithNoJob = {
    ...deploymentNode,
    job: null,
    finishedAt: null,
  };

  const environment = {
    lastDeployment: {
      job: {
        name: 'deploy-production',
      },
    },
  };
  describe('getAuthorFromCommit', () => {
    it.each([commitWithAuthor, commitWithoutAuthor])('should be properly converted', (commit) => {
      expect(getAuthorFromCommit(commit)).toMatchSnapshot();
    });
  });

  describe('getCommitFromDeploymentNode', () => {
    it('should throw an error when commit field is missing', () => {
      const emptyDeploymentNode = {};

      expect(() => getCommitFromDeploymentNode(emptyDeploymentNode)).toThrow();
    });

    it('should get correclty formatted commit object', () => {
      expect(getCommitFromDeploymentNode(deploymentNode)).toMatchSnapshot();
    });
  });

  describe('convertToDeploymentTableRow', () => {
    const deploymentNodeWithEmptyJob = { ...deploymentNode, job: undefined };

    it.each([deploymentNode, deploymentNodeWithEmptyJob, deploymentNodeWithNoJob])(
      'should be converted to proper table row data',
      (node) => {
        expect(convertToDeploymentTableRow(node, environment)).toMatchSnapshot();
      },
    );
  });
});