Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding pagination tests #1186

Merged
merged 8 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
testRegex: 'test\\/.*\\.ts$',
testMatch: null,
testURL: 'http://localhost/',
testTimeout: 15000,
testTimeout: 120000,

coverageDirectory: 'coverage',
collectCoverage: true,
Expand Down
40 changes: 40 additions & 0 deletions packages/gitbeaker-node/test/integration/services/Issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Issues, Projects } from '../../../src';

let issueAPI: InstanceType<typeof Issues>;
let projectAPI: InstanceType<typeof Projects>;

beforeAll(async () => {
issueAPI = new Issues({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
projectAPI = new Projects({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
});

describe('Issues.all', () => {
beforeAll(async () => {
const project = await projectAPI.create({ name: 'Issues All Integration Test' });
const newIssues: any[] = [];

for (let i = 0; i < 100; i += 1) {
newIssues.push(
issueAPI.create(project.id as number, {
title: `Issue.all Test ${i}`,
description: 'A test issue',
}),
);
}

await Promise.all(newIssues);
});

it('should get 60 projects using keyset pagination', async () => {
const projects = await issueAPI.all({ maxPages: 3, pagination: 'keyset' });

expect(projects).toBeInstanceOf(Array);
expect(projects).toHaveLength(60);
});
});
25 changes: 22 additions & 3 deletions packages/gitbeaker-node/test/integration/services/Projects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Projects } from '../../../src';

let service;
let service: InstanceType<typeof Projects>;

beforeEach(() => {
service = new Projects({
Expand All @@ -18,16 +18,35 @@ describe('Projects.create', () => {
});
});

describe('Projects.all', () => {
beforeAll(async () => {
const newProjects: any[] = [];

for (let i = 0; i < 100; i += 1) {
newProjects.push(service.create({ name: `Project All Integration Test${i}` }));
}

await Promise.all(newProjects);
});

it('should get 40 projects using offset pagination', async () => {
const projects = await service.all({ maxPages: 2 });

expect(projects).toBeInstanceOf(Array);
expect(projects).toHaveLength(40);
});
});

describe('Projects.upload', () => {
let project;
let project: Record<string, unknown>;

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, {
const results = await service.upload(project.id as number, content, {
metadata: {
filename: 'testfile.txt',
contentType: 'text/plain',
Expand Down