BREAKING CHANGE(gitlab): rename to @apiclient.xyz/gitlab v2.0.0 with new GitLabClient API
Replaces legacy @mojoio/gitlab with modern ESM TypeScript client supporting projects, groups, CI/CD variables, and pipelines.
This commit is contained in:
34
test/test.node.ts
Normal file
34
test/test.node.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import { GitLabClient } from '../ts/index.js';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', '.nogit/');
|
||||
|
||||
let gitlabClient: GitLabClient;
|
||||
|
||||
tap.test('should create a GitLabClient instance', async () => {
|
||||
const baseUrl = testQenv.getEnvVarOnDemand('GITLAB_BASE_URL') || 'https://gitlab.com';
|
||||
const token = testQenv.getEnvVarOnDemand('GITLAB_TOKEN') || '';
|
||||
gitlabClient = new GitLabClient(baseUrl, token);
|
||||
expect(gitlabClient).toBeInstanceOf(GitLabClient);
|
||||
});
|
||||
|
||||
tap.test('should test connection', async () => {
|
||||
const result = await gitlabClient.testConnection();
|
||||
expect(result).toHaveProperty('ok');
|
||||
console.log('Connection test:', result);
|
||||
});
|
||||
|
||||
tap.test('should get projects', async () => {
|
||||
const projects = await gitlabClient.getProjects({ perPage: 5 });
|
||||
expect(projects).toBeArray();
|
||||
console.log(`Found ${projects.length} projects`);
|
||||
});
|
||||
|
||||
tap.test('should get groups', async () => {
|
||||
const groups = await gitlabClient.getGroups({ perPage: 5 });
|
||||
expect(groups).toBeArray();
|
||||
console.log(`Found ${groups.length} groups`);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
43
test/test.ts
43
test/test.ts
@@ -1,43 +0,0 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as gitlab from '../ts/index';
|
||||
|
||||
let testGitlabAccount: gitlab.GitlabAccount;
|
||||
|
||||
const test1 = tap.test('should create an anonymous Gitlab Account', async () => {
|
||||
testGitlabAccount = gitlab.GitlabAccount.createAnonymousAccount();
|
||||
expect(testGitlabAccount).to.be.instanceOf(gitlab.GitlabAccount);
|
||||
});
|
||||
|
||||
const test2 = tap.test('should get the pushrocks group', async () => {
|
||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||
console.log(pushrocksGroup);
|
||||
});
|
||||
|
||||
const test3 = tap.test('should get the pushrocks group', async () => {
|
||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||
await pushrocksGroup.getProjects();
|
||||
});
|
||||
|
||||
const test4 = tap.test('should get the readme of a project', async () => {
|
||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||
const projects = await pushrocksGroup.getProjects();
|
||||
const selectedProject = projects.find((project) => {
|
||||
return project.data?.name === 'smartfile';
|
||||
});
|
||||
expect(selectedProject.data.name).to.equal('smartfile');
|
||||
const readme = await selectedProject.getReadmeAsMarkdown('master');
|
||||
expect(readme.startsWith('# @pushrocks/smartfile')).to.be.true;
|
||||
return projects;
|
||||
});
|
||||
|
||||
const test5 = tap.test('should be able to create an article list', async () => {
|
||||
const projects: gitlab.GitlabProject[] = (await test4.testResultPromise) as any;
|
||||
for (const project of projects) {
|
||||
console.log(await project.getProjectAsArticle());
|
||||
}
|
||||
})
|
||||
|
||||
tap.start();
|
||||
Reference in New Issue
Block a user