2020-11-27 07:09:14 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-10-30 17:08:52 -04:00
|
|
|
import Api from '~/api';
|
2021-02-01 10:08:56 -05:00
|
|
|
import httpStatus from '~/lib/utils/http_status';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { resolvers } from '~/pipeline_editor/graphql/resolvers';
|
2020-11-27 07:09:14 -05:00
|
|
|
import {
|
|
|
|
mockCiConfigPath,
|
|
|
|
mockCiYml,
|
|
|
|
mockDefaultBranch,
|
|
|
|
mockLintResponse,
|
2021-01-08 19:10:30 -05:00
|
|
|
mockProjectFullPath,
|
2020-11-27 07:09:14 -05:00
|
|
|
} from '../mock_data';
|
2020-10-30 17:08:52 -04:00
|
|
|
|
|
|
|
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-01-08 19:10:30 -05:00
|
|
|
projectPath: mockProjectFullPath,
|
2020-10-30 17:08:52 -04:00
|
|
|
path: mockCiConfigPath,
|
|
|
|
ref: mockDefaultBranch,
|
|
|
|
});
|
|
|
|
|
2021-01-08 19:10:30 -05:00
|
|
|
expect(Api.getRawFile).toHaveBeenCalledWith(mockProjectFullPath, mockCiConfigPath, {
|
2020-10-30 17:08:52 -04:00
|
|
|
ref: mockDefaultBranch,
|
|
|
|
});
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
expect(result.__typename).toBe('BlobContent');
|
|
|
|
await expect(result.rawData).resolves.toBe(mockCiYml);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-11-27 07:09:14 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-30 17:08:52 -04:00
|
|
|
});
|