test(gitbeaker-core): 💍 Removed integration tests and old unit tests

Integration tests have been showing odd behaviour in the CI pipelines. Until this behaviour is solved, they will be removed temporarily.
This commit is contained in:
Justin Dalrymple 2020-02-01 11:14:23 +01:00
parent 156a9dce73
commit ecc7890001
11 changed files with 0 additions and 589 deletions

View File

@ -1,55 +0,0 @@
/* eslint no-console: 0 */
import { exec } from 'child_process';
import { promisify } from 'util';
const runCmd = promisify(exec);
it('should create a valid project using configuration from environment variables', async () => {
process.env.GITLAB_HOST = process.env.GITLAB_URL;
process.env.GITLAB_TOKEN = process.env.PERSONAL_ACCESS_TOKEN;
const { stdout } = await runCmd('gitlab projects create --name="Project Creation CLI test1"', {
env: process.env,
});
expect(JSON.parse(stdout).name).toEqual('Project Creation CLI test1');
});
it('should create a valid project using configuration passed in arguments', async () => {
const { stdout } = await runCmd(
`gitlab projects create --gl-token=${process.env.PERSONAL_ACCESS_TOKEN} --gl-host=${process.env.GITLAB_URL} --name="Project Creation CLI test2"`,
{
env: process.env,
},
);
expect(JSON.parse(stdout).name).toEqual('Project Creation CLI test2');
});
it('should create a valid project using configuration passed in arguments and defined in the environment variables', async () => {
process.env.GITLAB_HOST = process.env.GITLAB_URL;
const { stdout } = await runCmd(
`
gitlab projects create --gl-token=${process.env.PERSONAL_ACCESS_TOKEN} --name="Project Creation CLI test3"`,
{
env: process.env,
},
);
expect(JSON.parse(stdout).name).toEqual('Project Creation CLI test3');
});
it('should create a valid project using configuration passed in arguments, overriding those defined in the environment variables', async () => {
process.env.GITLAB_TOKEN = 'faketoken';
const { stdout } = await runCmd(
`
gitlab projects create --gl-host=${process.env.GITLAB_URL} --gl-token=${process.env.PERSONAL_ACCESS_TOKEN} --name="Project Creation CLI test4"`,
{
env: process.env,
},
);
expect(JSON.parse(stdout).name).toEqual('Project Creation CLI test4');
});

View File

@ -1,31 +0,0 @@
import { ProjectsBundle } from '../../../dist';
const config = {
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
};
let project;
let api;
beforeAll(async () => {
api = new ProjectsBundle(config);
project = await api.Projects.create({ name: 'ProjectsBundle Integration test' });
});
describe('ProjectsBundle.Issues.create', () => {
it('should create a valid issue on a project', async () => {
const issue = await api.Issues.create(project.id, {
title: 'ProjectsBundle Integration test',
description: 'A test issue ensuring a sucessfully create Issue in GitLab',
});
expect(issue).toBeInstanceOf(Object);
expect(issue.title).toBe('ProjectsBundle Integration test');
});
it('should get a valid issue of a project', async () => {
const issue = await api.Issues.all(project.id);
expect(issue).toBeInstanceOf(Array);
});
});

View File

@ -1,29 +0,0 @@
import { ApplicationSettings } from '../../../dist';
let service;
beforeAll(async () => {
service = new ApplicationSettings({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
});
describe('ApplicationSettings.all', () => {
let settings;
beforeEach(async () => {
settings = await service.all();
});
it('Should return an object', async () => {
expect(settings).toBeObject();
});
/**
* @see https://docs.gitlab.com/ee/api/settings.html#get-current-application-settings
*/
it('should contain all the required properties', async () => {
expect(settings).toContainKeys(['id', 'gravatar_enabled']);
});
});

View File

@ -1,53 +0,0 @@
import { Commits, Projects } from '../../../dist';
const config = {
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
};
let project;
let service: Commits;
beforeAll(async () => {
// Crease project service
const projectService = new Projects(config);
// Create issue service
service = new Commits(config);
// Create a template project
project = await projectService.create({ name: 'Commit Integration test' });
});
describe('Commits.create', () => {
it('should create a valid commit on the master branch', async () => {
const actions = [
{
action: 'create',
filePath: 'foo/bar',
content: 'some content',
},
];
const commit = await service.create(project.id, 'master', 'Test API commit creation', actions);
expect(commit).toBeInstanceOf(Object);
expect(commit.message).toEqual('Test API commit creation');
});
});
describe('Commits.cherryPick', () => {
it("should handle error messages when attempting to cherry pick a commit that can't be cherrypicked", async () => {
const actions = [
{
action: 'create',
filePath: 'foo/bar/boo',
content: 'some other content',
},
];
const commit = await service.create(project.id, 'master', 'Test API commit creation', actions);
await expect(service.cherryPick(project.id, commit.sha, 'master')).rejects.toHaveProperty(
'description',
);
});
});

View File

@ -1,68 +0,0 @@
import { Issues, Projects } from '../../../dist';
const config = {
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
};
let project;
let service: Issues;
beforeAll(async () => {
// Crease project service
const projectService = new Projects(config);
// Create issue service
service = new Issues(config);
// Create a template project
project = await projectService.create({ name: 'Issue Integration test' });
});
describe('Issues.create', () => {
it('should create a valid issue on a project', async () => {
const issue1 = await service.create(project.id, {
title: 'Issue Integration test1',
description: 'A test issue ensuring a sucessfully create Issue in GitLab',
});
const issue2 = await service.create(project.id, {
title: 'Issue Integration test2',
description: 'A test issue ensuring a sucessfully create Issue in GitLab',
});
expect(issue1).toBeInstanceOf(Object);
expect(issue1.title).toBe('Issue Integration test1');
expect(issue2).toBeInstanceOf(Object);
expect(issue2.title).toBe('Issue Integration test2');
});
});
describe('Issues.all', () => {
it('should return a list of issues on a project', async () => {
const issues = await service.all({ projectId: project.id });
expect(issues).toBeInstanceOf(Array);
expect(issues.length).toEqual(2);
});
it('should return a list of all issues', async () => {
const issues = await service.all();
expect(issues).toBeInstanceOf(Array);
expect(issues).toHaveLength(2);
});
it('should return a list filtered to a specfic page', async () => {
const issues1 = await service.all({ projectId: project.id, perPage: 1, page: 1 });
expect(issues1).toBeInstanceOf(Array);
expect(issues1).toHaveLength(1);
expect(issues1[0].title).toBe('Issue Integration test2');
const issues2 = await service.all({ projectId: project.id, perPage: 1, page: 2 });
expect(issues2).toBeInstanceOf(Array);
expect(issues2).toHaveLength(1);
expect(issues2[0].title).toBe('Issue Integration test1');
});
});

View File

@ -1,83 +0,0 @@
import { Labels, Projects } from '../../../dist';
const config = {
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
};
let project;
let service: Labels;
beforeAll(async () => {
// Crease project service
const projectService = new Projects(config);
// Create issue service
service = new Labels(config);
// Create a template project
project = await projectService.create({ name: 'Labels Integration test' });
});
describe('Labels.create', () => {
it('should create a valid label on a project', async () => {
const label = await service.create(project.id, 'Test Label1', '#FFAABB');
expect(label).toBeInstanceOf(Object);
expect(label.name).toBe('Test Label1');
});
});
describe('Labels.remove', () => {
it('should remove/delete a valid label on a project', async () => {
const label = await service.create(project.id, 'Test Label3', '#FFAABB');
const value = await service.remove(project.id, label.name);
expect(value).toEqual('');
});
});
describe('Labels.all', () => {
beforeAll(async () => {
const labels: object[] = [];
for (let i = 0; i < 50; i += 1) {
labels.push(service.create(project.id, `All Labels ${i}`, '#FFAABB'));
}
return Promise.all(labels);
});
it('should return a list of labels on a project', async () => {
const labels = await service.all(project.id, { perPage: 3 });
const filtered = labels.filter(l => l.name.includes('All Labels'));
expect(labels).toBeInstanceOf(Array);
expect(filtered).toHaveLength(50);
});
it('should return a list of labels on a project restricted to page 5', async () => {
const labels = await service.all(project.id, { perPage: 5, page: 5 });
expect(labels).toBeInstanceOf(Array);
expect(labels).toHaveLength(5);
});
it('should return a list of labels on a project restricted to page 5 and show the pagination object', async () => {
const { data, pagination } = await service.all(project.id, {
perPage: 5,
page: 5,
showPagination: true,
});
expect(data).toBeInstanceOf(Array);
expect(data).toHaveLength(5);
expect(pagination).toMatchObject({
total: 51, // TODO: change this to not depend on previous data
previous: 4,
current: 5,
next: 6,
perPage: 5,
totalPages: 11,
});
});
});

View File

@ -1,38 +0,0 @@
import { Projects } from '../../../dist';
let service: Projects;
beforeEach(() => {
service = new Projects({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
});
describe('Projects.create', () => {
it('should create a valid project', async () => {
const p = await service.create({ name: 'Project Creation Integration test' });
expect(p).toBeInstanceOf(Object);
expect(p.name).toEqual('Project Creation Integration test');
});
});
describe('Projects.upload', () => {
let project: object;
beforeAll(async () => {
project = await service.create({ name: 'Project Upload Integration test' });
});
it('should upload a text file', async () => {
const content = 'TESTING FILE UPLOAD :D';
const results = await service.upload(project.id, content, {
metadata: {
filename: 'testfile.txt',
contentType: 'text/plain',
},
});
expect(results).toContainKeys(['alt', 'url', 'markdown']);
});
});

View File

@ -1,20 +0,0 @@
import { PushRules } from '../../../dist';
describe('PushRules.edit', () => {
// the feature is not available for CE users https://gitlab.com/gitlab-org/gitlab-ee/issues/3825
/* eslint jest/no-disabled-tests: 0 */
it.skip('should create or edit push rule on upsert', async () => {
const service = new PushRules({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
const result = await service.edit(1, {
upsert: true,
memberCheck: true,
});
expect(result).toBeInstanceOf(Object);
expect(result.member_check).toBeTrue();
});
});

View File

@ -1,25 +0,0 @@
import { Snippets } from '../../../dist';
let service: Snippets;
beforeEach(() => {
service = new Snippets({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
});
describe('Snippets.create', () => {
it('should create a snippet', async () => {
const result = await service.create(
'This is a snippet',
'test.txt',
'Hello world',
'internal',
{ description: 'Hello World snippet' },
);
expect(result).toBeInstanceOf(Object);
expect(result.title).toEqual('This is a snippet');
});
});

View File

@ -1,114 +0,0 @@
import { exec } from 'child_process';
import { promisify } from 'util';
import strip from 'strip-ansi';
import pkg from '../../../package.json';
const runCmd = promisify(exec);
describe('gitlab -g -- CLI Global Enviroment Variables', () => {
it('should return an object of available gitlab cli environment variables', async () => {
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(strip(stdout)).toBe('No global variables have been set!\n');
});
it('should only have the personal token set', async () => {
process.env.GITLAB_TOKEN = 'faketoken';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-token'].value).toBe('faketoken');
});
it('should only have the oauth token set', async () => {
process.env.GITLAB_OAUTH_TOKEN = 'faketoken';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-oauth-token'].value).toBe('faketoken');
});
it('should only have the job token set', async () => {
process.env.GITLAB_JOB_TOKEN = 'faketoken';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-job-token'].value).toBe('faketoken');
});
it('should only have the host set', async () => {
process.env.GITLAB_HOST = 'www.fakehost.com';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-host'].value).toBe('www.fakehost.com');
});
it('should only have the version set', async () => {
process.env.GITLAB_VERSION = '4';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-version'].value).toBe(4);
});
it('should only have sudo set', async () => {
process.env.GITLAB_SUDO = 'sudoaccount';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-sudo'].value).toBe('sudoaccount');
});
it('should only have the camelize set', async () => {
process.env.GITLAB_CAMELIZE = 'true';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-camelize'].value).toBe(true);
});
it('should only have the profile token set', async () => {
process.env.GITLAB_PROFILE_TOKEN = 'faketoken';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-profile-token'].value).toBe('faketoken');
});
it('should only have the profile mode set', async () => {
process.env.GITLAB_PROFILE_MODE = 'mode1';
const { stdout } = await runCmd('gitlab -g', {
env: process.env,
});
expect(JSON.parse(stdout)['gl-profile-mode'].value).toBe('mode1');
});
});
describe('gitlab -v -- Package Version', () => {
it('should return the current version number of the package', async () => {
const { stdout } = await runCmd('gitlab -v');
expect(stdout.trim()).toBe(pkg.version);
});
});

View File

@ -1,73 +0,0 @@
import { RequestHelper, KyRequester, BaseService } from '../../../src/core/infrastructure';
describe('Creation of BaseService instance', () => {
test('host defaults to https://gitlab.com/api/v4/', async () => {
const service = new BaseService({ token: 'test' });
expect(service.url).toBe('https://gitlab.com/api/v4/');
});
test('Use the Oauth Token when a given both a Private Token and a Oauth Token', async () => {
const service = new BaseService({ token: 'test', oauthToken: '1234' });
expect(service.headers['private-token']).toBeUndefined();
expect(service.headers.authorization).toBe('Bearer 1234');
});
test('Custom host still appends api and version number to host', async () => {
const service = new BaseService({ host: 'https://testing.com', token: 'test' });
expect(service.url).toBe('https://testing.com/api/v4/');
});
test('Oauth token adds to authorization header as a bearer token', async () => {
const service = new BaseService({ host: 'https://testing.com', oauthToken: '1234' });
expect(service.headers.authorization).toBe('Bearer 1234');
});
test('Private token adds to private-token header', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234' });
expect(service.headers['private-token']).toBe('1234');
});
test('API version should be modified', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234', version: 3 });
expect(service.url).toBe('https://testing.com/api/v3/');
});
/* eslint @typescript-eslint/camelcase: 0 */
test('Camelize option should return simple response with camelized keys', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234', camelize: true });
service.show = jest.fn(() => RequestHelper.get(service, 'test'));
KyRequester.get = jest.fn(() => ({
body: [
{ id: 3, gravatar_enable: true },
{ id: 4, gravatar_enable: false },
],
headers: {},
}));
const results = await service.show();
expect(results).toIncludeSameMembers([
{ id: 3, gravatarEnable: true },
{ id: 4, gravatarEnable: false },
]);
});
/* eslint @typescript-eslint/camelcase: 0 */
test('Camelize option unset should return simple response with default keys', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234' });
service.show = jest.fn(() => RequestHelper.get(service, 'test'));
KyRequester.get = jest.fn(() => ({ body: { id: 3, gravatar_enable: true }, headers: {} }));
const results = await service.show();
expect(results).toMatchObject({ id: 3, gravatar_enable: true });
});
});