Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deployment_data_transformation_helper_spec.js « helpers « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bb87c0a208ed541090f06999db30093bba01b99 (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
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
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 commitWithourAuthor = {
    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',
    },
    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,
  };

  describe('getAuthorFromCommit', () => {
    it.each([commitWithAuthor, commitWithourAuthor])('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)).toMatchSnapshot();
      },
    );
  });
});