summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/util_spec.js
blob: 14cce8320e9e5122162421e2290eba07dc4937d0 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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({
        data: [
          {
            author: {
              id: expect.any(String),
            },
          },
          {
            author: {
              id: expect.any(String),
            },
            evidences: [
              {
                id: expect.any(String),
                filepath: expect.any(String),
              },
            ],
          },
        ],
        paginationInfo: {
          startCursor: expect.any(String),
          endCursor: expect.any(String),
        },
      });
    });
  });

  describe('convertOneReleaseGraphQLResponse', () => {
    it('matches snapshot', () => {
      expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot({
        data: {
          author: {
            id: expect.any(String),
          },
          evidences: [
            {
              id: expect.any(String),
              filepath: expect.any(String),
            },
          ],
        },
      });
    });
  });

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