From ecc78900018e1cf1d1bb6f002b8d1bec0bdc141b Mon Sep 17 00:00:00 2001 From: Justin Dalrymple Date: Sat, 1 Feb 2020 11:14:23 +0100 Subject: [PATCH] =?UTF-8?q?test(gitbeaker-core):=20=F0=9F=92=8D=20Removed?= =?UTF-8?q?=20integration=20tests=20and=20old=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integration tests have been showing odd behaviour in the CI pipelines. Until this behaviour is solved, they will be removed temporarily. --- test/integration/bin/index.ts | 55 --------- test/integration/bundles/ProjectsBundle.ts | 31 ----- .../services/ApplicationSettings.ts | 29 ----- test/integration/services/Commits.ts | 53 -------- test/integration/services/Issues.ts | 68 ----------- test/integration/services/Labels.ts | 83 ------------- test/integration/services/Projects.ts | 38 ------ test/integration/services/PushRules.ts | 20 --- test/integration/services/Snippets.ts | 25 ---- test/unit/bin/index.ts | 114 ------------------ test/unit/infrastructure/BaseService.ts | 73 ----------- 11 files changed, 589 deletions(-) delete mode 100644 test/integration/bin/index.ts delete mode 100644 test/integration/bundles/ProjectsBundle.ts delete mode 100644 test/integration/services/ApplicationSettings.ts delete mode 100644 test/integration/services/Commits.ts delete mode 100644 test/integration/services/Issues.ts delete mode 100644 test/integration/services/Labels.ts delete mode 100644 test/integration/services/Projects.ts delete mode 100644 test/integration/services/PushRules.ts delete mode 100644 test/integration/services/Snippets.ts delete mode 100644 test/unit/bin/index.ts delete mode 100644 test/unit/infrastructure/BaseService.ts diff --git a/test/integration/bin/index.ts b/test/integration/bin/index.ts deleted file mode 100644 index 3c75af60..00000000 --- a/test/integration/bin/index.ts +++ /dev/null @@ -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'); -}); diff --git a/test/integration/bundles/ProjectsBundle.ts b/test/integration/bundles/ProjectsBundle.ts deleted file mode 100644 index c2ed77b5..00000000 --- a/test/integration/bundles/ProjectsBundle.ts +++ /dev/null @@ -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); - }); -}); diff --git a/test/integration/services/ApplicationSettings.ts b/test/integration/services/ApplicationSettings.ts deleted file mode 100644 index 7e8be498..00000000 --- a/test/integration/services/ApplicationSettings.ts +++ /dev/null @@ -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']); - }); -}); diff --git a/test/integration/services/Commits.ts b/test/integration/services/Commits.ts deleted file mode 100644 index 2651fbc9..00000000 --- a/test/integration/services/Commits.ts +++ /dev/null @@ -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', - ); - }); -}); diff --git a/test/integration/services/Issues.ts b/test/integration/services/Issues.ts deleted file mode 100644 index d30557ff..00000000 --- a/test/integration/services/Issues.ts +++ /dev/null @@ -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'); - }); -}); diff --git a/test/integration/services/Labels.ts b/test/integration/services/Labels.ts deleted file mode 100644 index 4bb8b211..00000000 --- a/test/integration/services/Labels.ts +++ /dev/null @@ -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, - }); - }); -}); diff --git a/test/integration/services/Projects.ts b/test/integration/services/Projects.ts deleted file mode 100644 index f880da29..00000000 --- a/test/integration/services/Projects.ts +++ /dev/null @@ -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']); - }); -}); diff --git a/test/integration/services/PushRules.ts b/test/integration/services/PushRules.ts deleted file mode 100644 index f6562c08..00000000 --- a/test/integration/services/PushRules.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/test/integration/services/Snippets.ts b/test/integration/services/Snippets.ts deleted file mode 100644 index c481a93f..00000000 --- a/test/integration/services/Snippets.ts +++ /dev/null @@ -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'); - }); -}); diff --git a/test/unit/bin/index.ts b/test/unit/bin/index.ts deleted file mode 100644 index a9e3ff19..00000000 --- a/test/unit/bin/index.ts +++ /dev/null @@ -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); - }); -}); diff --git a/test/unit/infrastructure/BaseService.ts b/test/unit/infrastructure/BaseService.ts deleted file mode 100644 index fe50c3b2..00000000 --- a/test/unit/infrastructure/BaseService.ts +++ /dev/null @@ -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 }); - }); -});