debian-mirror-gitlab/spec/frontend/pipeline_editor/graphql/resolvers_spec.js
2021-04-17 20:07:23 +05:30

107 lines
3 KiB
JavaScript

import MockAdapter from 'axios-mock-adapter';
import Api from '~/api';
import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status';
import { resolvers } from '~/pipeline_editor/graphql/resolvers';
import {
mockCiConfigPath,
mockCiYml,
mockDefaultBranch,
mockLintResponse,
mockProjectFullPath,
} from '../mock_data';
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, {
projectPath: mockProjectFullPath,
path: mockCiConfigPath,
ref: mockDefaultBranch,
});
expect(Api.getRawFile).toHaveBeenCalledWith(mockProjectFullPath, mockCiConfigPath, {
ref: mockDefaultBranch,
});
// eslint-disable-next-line no-underscore-dangle
expect(result.__typename).toBe('BlobContent');
await expect(result.rawData).resolves.toBe(mockCiYml);
});
});
describe('pipeline', () => {
it('resolves pipeline data with type names', async () => {
const result = await resolvers.Query.project(null);
// eslint-disable-next-line no-underscore-dangle
expect(result.__typename).toBe('Project');
});
it('resolves pipeline data with necessary data', async () => {
const result = await resolvers.Query.project(null);
const pipelineKeys = Object.keys(result.pipeline);
const statusKeys = Object.keys(result.pipeline.detailedStatus);
expect(pipelineKeys).toContain('id', 'commitPath', 'detailedStatus', 'shortSha');
expect(statusKeys).toContain('detailsPath', 'text');
});
});
});
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();
});
});
});
});