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

util_spec.js « releases « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c1060cb0e8bdc13b422f0c989b536e2eb929d1e (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
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
122
123
124
import { cloneDeep } from 'lodash';
import originalAllReleasesQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/all_releases.query.graphql.json';
import originalOneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json';
import originalOneReleaseForEditingQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release_for_editing.query.graphql.json';
import {
  convertGraphQLRelease,
  convertAllReleasesGraphQLResponse,
  convertOneReleaseGraphQLResponse,
} from '~/releases/util';

describe('releases/util.js', () => {
  describe('convertGraphQLRelease', () => {
    let releaseFromResponse;
    let convertedRelease;

    beforeEach(() => {
      releaseFromResponse = cloneDeep(originalOneReleaseQueryResponse).data.project.release;
      convertedRelease = convertGraphQLRelease(releaseFromResponse);
    });

    describe('assets', () => {
      it("handles asset links that don't have a linkType", () => {
        expect(convertedRelease.assets.links[0].linkType).not.toBeUndefined();

        delete releaseFromResponse.assets.links.nodes[0].linkType;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.assets.links[0].linkType).toBeUndefined();
      });

      it('handles assets that have no links', () => {
        expect(convertedRelease.assets.links[0]).not.toBeUndefined();

        delete releaseFromResponse.assets.links;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.assets.links).toEqual([]);
      });

      it('handles assets that have no sources', () => {
        expect(convertedRelease.assets.sources[0]).not.toBeUndefined();

        delete releaseFromResponse.assets.sources;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.assets.sources).toEqual([]);
      });
    });

    describe('_links', () => {
      it("handles releases that don't have any links", () => {
        expect(convertedRelease._links.selfUrl).not.toBeUndefined();

        delete releaseFromResponse.links;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease._links.selfUrl).toBeUndefined();
      });
    });

    describe('commit', () => {
      it("handles releases that don't have any commit info", () => {
        expect(convertedRelease.commit).not.toBeUndefined();

        delete releaseFromResponse.commit;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.commit).toBeUndefined();
      });
    });

    describe('milestones', () => {
      it("handles releases that don't have any milestone stats", () => {
        expect(convertedRelease.milestones[0].issueStats).not.toBeUndefined();

        releaseFromResponse.milestones.nodes = releaseFromResponse.milestones.nodes.map((n) => ({
          ...n,
          stats: undefined,
        }));

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.milestones[0].issueStats).toEqual({});
      });
    });

    describe('evidences', () => {
      it("handles releases that don't have any evidences", () => {
        expect(convertedRelease.evidences).not.toBeUndefined();

        delete releaseFromResponse.evidences;

        convertedRelease = convertGraphQLRelease(releaseFromResponse);

        expect(convertedRelease.evidences).toEqual([]);
      });
    });
  });

  describe('convertAllReleasesGraphQLResponse', () => {
    it('matches snapshot', () => {
      expect(convertAllReleasesGraphQLResponse(originalAllReleasesQueryResponse)).toMatchSnapshot();
    });
  });

  describe('convertOneReleaseGraphQLResponse', () => {
    it('matches snapshot', () => {
      expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot();
    });
  });

  describe('convertOneReleaseForEditingGraphQLResponse', () => {
    it('matches snapshot', () => {
      expect(
        convertOneReleaseGraphQLResponse(originalOneReleaseForEditingQueryResponse),
      ).toMatchSnapshot();
    });
  });
});