debian-mirror-gitlab/spec/frontend/pipeline_editor/graphql/resolvers_spec.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-01-29 00:20:46 +05:30
import Api from '~/api';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status';
import { resolvers } from '~/pipeline_editor/graphql/resolvers';
2021-02-22 17:27:13 +05:30
import {
mockCiConfigPath,
mockCiYml,
mockDefaultBranch,
mockLintResponse,
2021-03-08 18:12:59 +05:30
mockProjectFullPath,
2021-02-22 17:27:13 +05:30
} from '../mock_data';
2021-01-29 00:20:46 +05:30
jest.mock('~/api', () => {
return {
getRawFile: jest.fn(),
};
});
describe('~/pipeline_editor/graphql/resolvers', () => {
describe('Query', () => {
describe('blobContent', () => {
beforeEach(() => {
Api.getRawFile.mockResolvedValue({
data: mockCiYml,
});
});
afterEach(() => {
Api.getRawFile.mockReset();
});
it('resolves lint data with type names', async () => {
const result = resolvers.Query.blobContent(null, {
2021-03-08 18:12:59 +05:30
projectPath: mockProjectFullPath,
2021-01-29 00:20:46 +05:30
path: mockCiConfigPath,
ref: mockDefaultBranch,
});
2021-03-08 18:12:59 +05:30
expect(Api.getRawFile).toHaveBeenCalledWith(mockProjectFullPath, mockCiConfigPath, {
2021-01-29 00:20:46 +05:30
ref: mockDefaultBranch,
});
// eslint-disable-next-line no-underscore-dangle
expect(result.__typename).toBe('BlobContent');
await expect(result.rawData).resolves.toBe(mockCiYml);
});
});
});
2021-02-22 17:27:13 +05:30
describe('Mutation', () => {
describe('lintCI', () => {
let mock;
let result;
const endpoint = '/ci/lint';
beforeEach(async () => {
mock = new MockAdapter(axios);
mock.onPost(endpoint).reply(httpStatus.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();
});
});
});
2021-01-29 00:20:46 +05:30
});