fix(test): cover more remote endpoints
This commit is contained in:
parent
65cf8e78d4
commit
9e769e3355
|
@ -7,14 +7,14 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
listIssues(options: IssueQuery): Promise<Array<IssueUpdate>>;
|
||||
listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | IssueQuery | |
|
||||
| options | ProjectQuery | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
|
|
|
@ -3,11 +3,9 @@ import { GetResponse } from '@gitbeaker/core/dist/types/infrastructure/RequestHe
|
|||
import { Bundle } from '@gitbeaker/core/dist/types/infrastructure/Utils';
|
||||
import { IssueNotes, Issues, Labels, Projects, ProjectsBundle } from '@gitbeaker/node';
|
||||
|
||||
import { CommentUpdate, IssueQuery, IssueUpdate, LabelUpdate, ProjectQuery, Remote, RemoteOptions } from '.';
|
||||
import { CommentUpdate, IssueUpdate, LabelUpdate, ProjectQuery, Remote, RemoteOptions } from '.';
|
||||
import { BaseRemote } from './base';
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
// gitbeaker exports the bundle types as const, breaking typeof
|
||||
type RemoteBundle = InstanceType<Bundle<{
|
||||
Issues: typeof Issues;
|
||||
|
@ -31,7 +29,7 @@ export class GitlabRemote extends BaseRemote<RemoteBundle, RemoteOptions> implem
|
|||
}
|
||||
|
||||
public async connect(): Promise<boolean> {
|
||||
this.client = new ProjectsBundle({
|
||||
this.client = await this.options.container.create(ProjectsBundle, {
|
||||
host: this.options.data.host,
|
||||
token: mustExist(this.options.data.token),
|
||||
});
|
||||
|
@ -70,7 +68,7 @@ export class GitlabRemote extends BaseRemote<RemoteBundle, RemoteOptions> implem
|
|||
return options;
|
||||
}
|
||||
|
||||
public async listIssues(options: IssueQuery): Promise<Array<IssueUpdate>> {
|
||||
public async listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>> {
|
||||
const project = await this.resolvePath(options.project);
|
||||
const data = unwrapResponse<Array<GitlabIssue>>(await mustExist(this.client).Issues.all({
|
||||
...project,
|
||||
|
|
|
@ -6,6 +6,7 @@ import { stub } from 'sinon';
|
|||
|
||||
import { RemoteModule } from '../../src/module/RemoteModule';
|
||||
import { GithubRemote } from '../../src/remote/github';
|
||||
import { ChangeVerb } from '../../src/resolve';
|
||||
|
||||
describe('github remote', () => {
|
||||
it('should create an octokit client with token auth', async () => {
|
||||
|
@ -75,6 +76,44 @@ describe('github remote', () => {
|
|||
expect(() => remote.writeClient).to.throw(InvalidArgumentError);
|
||||
});
|
||||
|
||||
describe('format body', () => {
|
||||
it('should include change details', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
stub(client.issues, 'createLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
for (const effect of [ChangeVerb.CONFLICTED, ChangeVerb.CREATED, ChangeVerb.REMOVED, ChangeVerb.REQUIRED]) {
|
||||
const body = remote.formatBody({
|
||||
changes: [{
|
||||
cause: 'foo',
|
||||
effect,
|
||||
label: 'bar',
|
||||
}],
|
||||
errors: [],
|
||||
issue: '',
|
||||
project: '',
|
||||
});
|
||||
|
||||
expect(body).to.include('bar').and.include('foo');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('create label endpoint', () => {
|
||||
it('should create labels when dryrun=false', async () => {
|
||||
const logger = NullLogger.global;
|
||||
|
|
|
@ -1,5 +1,268 @@
|
|||
import { ProjectsBundle } from '@gitbeaker/node';
|
||||
import { expect } from 'chai';
|
||||
import { Container, NullLogger } from 'noicejs';
|
||||
import { match, stub } from 'sinon';
|
||||
|
||||
import { RemoteModule } from '../../src/module/RemoteModule';
|
||||
import { GitlabRemote } from '../../src/remote/gitlab';
|
||||
|
||||
describe('gitlab remote', () => {
|
||||
it('should authenticate to gitlab API');
|
||||
describe('create label endpoint', () => {
|
||||
it('should create labels when dryrun=false', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
const createStub = stub(client.Labels, 'create');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(1).and.been.calledWithMatch(match.string, 'foo');
|
||||
});
|
||||
|
||||
it('should not create labels when dryrun=true', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
|
||||
const createStub = stub(client.Labels, 'create');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: true,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete label endpoint', () => {
|
||||
it('should delete labels when dryrun=false', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
|
||||
const removeStub = stub(client.Labels, 'remove');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.deleteLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(removeStub).to.have.callCount(1).and.been.calledWithMatch(match.string, 'foo');
|
||||
});
|
||||
|
||||
it('should not delete labels when dryrun=true', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
|
||||
const removeStub = stub(client.Labels, 'remove');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: true,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.deleteLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(removeStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('list issues endpoint', () => {
|
||||
it('should list issues when dryrun=*', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
|
||||
const listStub = stub(client.Issues, 'all').returns(Promise.resolve([]));
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
for (const dryrun of [true, false]) {
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.listIssues(data);
|
||||
|
||||
expect(result).to.deep.equal([]);
|
||||
expect(listStub).to.have.callCount(1);
|
||||
listStub.resetHistory();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('list labels endpoint', () => {
|
||||
it('should list labels when dryrun=*', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve({
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
}));
|
||||
|
||||
const listStub = stub(client.Labels, 'all').returns(Promise.resolve([]));
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
for (const dryrun of [true, false]) {
|
||||
const remote = await container.create(GitlabRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.listLabels(data);
|
||||
|
||||
expect(result).to.deep.equal([]);
|
||||
expect(listStub).to.have.callCount(1);
|
||||
listStub.resetHistory();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue