summaryrefslogtreecommitdiff
path: root/spec/frontend/ci/pipeline_editor/graphql/resolvers_spec.js
blob: 6a6cc3a14de72eb57c949094337c317020006ba8 (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
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
import { resolvers } from '~/ci/pipeline_editor/graphql/resolvers';
import { mockLintResponse } from '../mock_data';

jest.mock('~/api', () => {
  return {
    getRawFile: jest.fn(),
  };
});

describe('~/ci/pipeline_editor/graphql/resolvers', () => {
  describe('Mutation', () => {
    describe('lintCI', () => {
      let mock;
      let result;

      const endpoint = '/ci/lint';

      beforeEach(async () => {
        mock = new MockAdapter(axios);
        mock.onPost(endpoint).reply(HTTP_STATUS_OK, mockLintResponse);

        result = await resolvers.Mutation.lintCI(null, {
          endpoint,
          content: 'content',
          dry_run: true,
        });
      });

      afterEach(() => {
        mock.restore();
      });

      /* eslint-disable no-underscore-dangle */
      it('lint data has correct type names', async () => {
        expect(result.__typename).toBe('CiLintContent');

        expect(result.jobs[0].__typename).toBe('CiLintJob');
        expect(result.jobs[1].__typename).toBe('CiLintJob');

        expect(result.jobs[1].only.__typename).toBe('CiLintJobOnlyPolicy');
      });
      /* eslint-enable no-underscore-dangle */

      it('lint data is as expected', () => {
        expect(result).toMatchSnapshot();
      });
    });
  });
});