fix(remote): return created comment for gitlab, cover remaining endpoints
This commit is contained in:
parent
9e769e3355
commit
040ad3c500
|
@ -7,7 +7,7 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createComment(options: CommentUpdate): Promise<unknown>;
|
||||
createComment(options: CommentUpdate): Promise<CommentUpdate>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
@ -18,5 +18,5 @@ createComment(options: CommentUpdate): Promise<unknown>;
|
|||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<unknown>
|
||||
Promise<CommentUpdate>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createComment(options: CommentUpdate): Promise<void>;
|
||||
createComment(options: CommentUpdate): Promise<CommentUpdate>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
@ -18,5 +18,5 @@ createComment(options: CommentUpdate): Promise<void>;
|
|||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<void>
|
||||
Promise<CommentUpdate>
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ Add a comment to an issue (for attribution and auditing).
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createComment(options: CommentUpdate): Promise<unknown>;
|
||||
createComment(options: CommentUpdate): Promise<CommentUpdate>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
@ -20,5 +20,5 @@ createComment(options: CommentUpdate): Promise<unknown>;
|
|||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<unknown>
|
||||
Promise<CommentUpdate>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import { VERSION_INFO } from '../version';
|
|||
|
||||
export enum Commands {
|
||||
UNKNOWN = 'unknown',
|
||||
ERROR = 'error',
|
||||
GRAPH = 'graph-labels',
|
||||
ISSUES = 'sync-issues',
|
||||
LABELS = 'sync-projects',
|
||||
|
@ -63,6 +64,10 @@ export function createParser(modeset: Modeback): Parser<ParsedArgs> {
|
|||
},
|
||||
})
|
||||
.completion()
|
||||
.exitProcess(false)
|
||||
.fail((msg: string, err: Error) => {
|
||||
modeset(Commands.ERROR);
|
||||
})
|
||||
.help()
|
||||
.alias('help', 'h')
|
||||
.version(VERSION_INFO.package.version)
|
||||
|
|
|
@ -13,7 +13,7 @@ export abstract class BaseRemote<TClient, TOptions extends RemoteOptions> implem
|
|||
}
|
||||
|
||||
public abstract connect(): Promise<boolean>;
|
||||
public abstract createComment(options: CommentUpdate): Promise<unknown>;
|
||||
public abstract createComment(options: CommentUpdate): Promise<CommentUpdate>;
|
||||
public abstract createLabel(options: LabelUpdate): Promise<LabelUpdate>;
|
||||
public abstract deleteLabel(options: LabelQuery): Promise<LabelQuery>;
|
||||
public abstract listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>>;
|
||||
|
|
|
@ -55,7 +55,7 @@ export class GithubRemote extends BaseRemote<Octokit, RemoteOptions> implements
|
|||
};
|
||||
}
|
||||
|
||||
public async createComment(options: CommentUpdate): Promise<unknown> {
|
||||
public async createComment(options: CommentUpdate): Promise<CommentUpdate> {
|
||||
const path = await this.resolvePath(options.project);
|
||||
const body = this.formatBody(options);
|
||||
|
||||
|
|
|
@ -37,13 +37,15 @@ export class GitlabRemote extends BaseRemote<RemoteBundle, RemoteOptions> implem
|
|||
return true;
|
||||
}
|
||||
|
||||
public async createComment(options: CommentUpdate): Promise<void> {
|
||||
public async createComment(options: CommentUpdate): Promise<CommentUpdate> {
|
||||
const project = await this.resolvePath(options.project);
|
||||
const body = this.formatBody(options);
|
||||
|
||||
if (this.writeCapable) {
|
||||
await this.writeClient.IssueNotes.create(project.projectId, parseInt(options.issue, 10), body);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
public async createLabel(options: LabelUpdate): Promise<LabelUpdate> {
|
||||
|
|
|
@ -61,7 +61,7 @@ export interface Remote {
|
|||
/**
|
||||
* Add a comment to an issue (for attribution and auditing).
|
||||
*/
|
||||
createComment(options: CommentUpdate): Promise<unknown>;
|
||||
createComment(options: CommentUpdate): Promise<CommentUpdate>;
|
||||
|
||||
/**
|
||||
* Create a new label.
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import { expect } from 'chai';
|
||||
import { stub } from 'sinon';
|
||||
|
||||
import { Commands, createParser } from '../../src/config/args';
|
||||
|
||||
describe('args', () => {
|
||||
it('should set command mode', () => {
|
||||
const modeStub = stub();
|
||||
const parser = createParser(modeStub);
|
||||
|
||||
for (const command of [
|
||||
Commands.GRAPH,
|
||||
Commands.ISSUES,
|
||||
Commands.LABELS,
|
||||
]) {
|
||||
const args = parser.parse([command]);
|
||||
expect(args).to.deep.include({
|
||||
dryrun: true,
|
||||
});
|
||||
expect(modeStub).to.have.been.calledWith(command);
|
||||
modeStub.resetHistory();
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { validateConfig } from '../src/config';
|
||||
import { validateConfig } from '../../src/config';
|
||||
|
||||
describe('config', () => {
|
||||
describe('validate config', () => {
|
|
@ -4,13 +4,28 @@ import { expect } from 'chai';
|
|||
import { BaseOptions, Container, NullLogger } from 'noicejs';
|
||||
import { stub } from 'sinon';
|
||||
|
||||
import { RemoteOptions } from '../../src';
|
||||
import { RemoteModule } from '../../src/module/RemoteModule';
|
||||
import { GithubRemote } from '../../src/remote/github';
|
||||
import { ChangeVerb } from '../../src/resolve';
|
||||
|
||||
const REMOTE_OPTIONS: Omit<RemoteOptions, 'container'> = {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger: NullLogger.global,
|
||||
type: '',
|
||||
};
|
||||
|
||||
const DRYRUN_OPTIONS = {
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun: true,
|
||||
};
|
||||
|
||||
describe('github remote', () => {
|
||||
it('should create an octokit client with token auth', async () => {
|
||||
const logger = NullLogger.global;
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
@ -18,19 +33,12 @@ describe('github remote', () => {
|
|||
const client = stub();
|
||||
module.bind<Octokit, Octokit, BaseOptions>(Octokit).toFactory(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'foo',
|
||||
type: 'token',
|
||||
},
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
|
||||
expect(status).to.equal(true);
|
||||
expect(client).to.have.been.calledWithMatch({
|
||||
auth: 'foo',
|
||||
auth: 'test',
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -78,7 +86,6 @@ describe('github remote', () => {
|
|||
|
||||
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();
|
||||
|
@ -87,15 +94,7 @@ describe('github remote', () => {
|
|||
stub(client.issues, 'createLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
|
||||
for (const effect of [ChangeVerb.CONFLICTED, ChangeVerb.CREATED, ChangeVerb.REMOVED, ChangeVerb.REQUIRED]) {
|
||||
const body = remote.formatBody({
|
||||
|
@ -114,9 +113,63 @@ describe('github remote', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('create comment endpoint', () => {
|
||||
it('should create comments when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const createStub = stub(client.issues, 'createComment');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
changes: [],
|
||||
errors: [],
|
||||
issue: '1',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createComment(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(1).and.been.calledWithMatch({
|
||||
/* eslint-disable-next-line camelcase */
|
||||
issue_number: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not create comments when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const createStub = stub(client.issues, 'createComment');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
changes: [],
|
||||
errors: [],
|
||||
issue: '1',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createComment(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
|
@ -125,16 +178,7 @@ describe('github remote', () => {
|
|||
stub(client.issues, 'createLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -153,7 +197,6 @@ describe('github remote', () => {
|
|||
});
|
||||
|
||||
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();
|
||||
|
@ -162,16 +205,7 @@ describe('github remote', () => {
|
|||
stub(client.issues, 'createLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: true,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const remote = await container.create(GithubRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -190,7 +224,6 @@ describe('github remote', () => {
|
|||
|
||||
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();
|
||||
|
@ -199,16 +232,7 @@ describe('github remote', () => {
|
|||
stub(client.issues, 'deleteLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -227,7 +251,6 @@ describe('github remote', () => {
|
|||
});
|
||||
|
||||
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();
|
||||
|
@ -236,16 +259,7 @@ describe('github remote', () => {
|
|||
stub(client.issues, 'deleteLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: true,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const remote = await container.create(GithubRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -264,7 +278,6 @@ describe('github remote', () => {
|
|||
|
||||
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();
|
||||
|
@ -280,13 +293,8 @@ describe('github remote', () => {
|
|||
|
||||
for (const dryrun of [true, false]) {
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
|
@ -306,7 +314,6 @@ describe('github remote', () => {
|
|||
|
||||
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();
|
||||
|
@ -322,13 +329,8 @@ describe('github remote', () => {
|
|||
|
||||
for (const dryrun of [true, false]) {
|
||||
const remote = await container.create(GithubRemote, {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
|
@ -345,4 +347,127 @@ describe('github remote', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('update issue endpoint', () => {
|
||||
it('should update issues when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const updateStub = stub(client.issues, 'setLabels');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
issue: '1',
|
||||
labels: [],
|
||||
name: '',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateIssue(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(1).and.been.calledWithMatch({
|
||||
/* eslint-disable-next-line camelcase */
|
||||
issue_number: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not update issues when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const updateStub = stub(client.issues, 'setLabels');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
issue: 'foo',
|
||||
labels: [],
|
||||
name: '',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateIssue(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update label endpoint', () => {
|
||||
it('should update labels when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const updateStub = stub(client.issues, 'updateLabel').returns(Promise.resolve({
|
||||
data: {
|
||||
color: 'red',
|
||||
default: false,
|
||||
description: 'bar',
|
||||
id: 0,
|
||||
name: 'foo',
|
||||
/* eslint-disable-next-line camelcase */
|
||||
node_id: '',
|
||||
url: '',
|
||||
},
|
||||
headers: {},
|
||||
status: 0,
|
||||
url: '',
|
||||
}));
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: 'red',
|
||||
desc: 'bar',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(1).and.been.calledWithMatch({
|
||||
name: data.name,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not update labels when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new Octokit();
|
||||
const updateStub = stub(client.issues, 'updateLabel');
|
||||
module.bind(Octokit).toInstance(client);
|
||||
|
||||
const remote = await container.create(GithubRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,35 +5,97 @@ import { match, stub } from 'sinon';
|
|||
|
||||
import { RemoteModule } from '../../src/module/RemoteModule';
|
||||
import { GitlabRemote } from '../../src/remote/gitlab';
|
||||
import { RemoteOptions } from '../../src';
|
||||
|
||||
const REMOTE_OPTIONS: Omit<RemoteOptions, 'container'> = {
|
||||
data: {
|
||||
token: 'test',
|
||||
type: 'token',
|
||||
},
|
||||
dryrun: false,
|
||||
logger: NullLogger.global,
|
||||
type: '',
|
||||
};
|
||||
|
||||
const DRYRUN_OPTIONS = {
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun: true,
|
||||
};
|
||||
|
||||
const STUB_PROJECT = {
|
||||
id: '',
|
||||
namespace: {
|
||||
id: '',
|
||||
},
|
||||
};
|
||||
|
||||
describe('gitlab remote', () => {
|
||||
describe('create label endpoint', () => {
|
||||
it('should create labels when dryrun=false', async () => {
|
||||
const logger = NullLogger.global;
|
||||
describe('create comment endpoint', () => {
|
||||
it('should create comments when dryrun=false', async () => {
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const createStub = stub(client.IssueNotes, 'create');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
changes: [],
|
||||
errors: [],
|
||||
issue: '1',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createComment(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(1).and.been.calledWithMatch(match.string, 1);
|
||||
});
|
||||
|
||||
it('should not create comments when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const createStub = stub(client.IssueNotes, 'create');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
changes: [],
|
||||
errors: [],
|
||||
issue: '1',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.createComment(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(createStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('create label endpoint', () => {
|
||||
it('should create labels when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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 remote = await container.create(GitlabRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -50,32 +112,16 @@ describe('gitlab remote', () => {
|
|||
});
|
||||
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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 remote = await container.create(GitlabRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
|
@ -94,31 +140,16 @@ describe('gitlab remote', () => {
|
|||
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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 remote = await container.create(GitlabRemote, REMOTE_OPTIONS);
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
@ -136,31 +167,16 @@ describe('gitlab remote', () => {
|
|||
});
|
||||
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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 remote = await container.create(GitlabRemote, DRYRUN_OPTIONS);
|
||||
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
@ -180,31 +196,19 @@ describe('gitlab remote', () => {
|
|||
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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',
|
||||
},
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
|
@ -224,31 +228,19 @@ describe('gitlab remote', () => {
|
|||
|
||||
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: '',
|
||||
},
|
||||
}));
|
||||
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
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',
|
||||
},
|
||||
...REMOTE_OPTIONS,
|
||||
dryrun,
|
||||
logger,
|
||||
type: '',
|
||||
});
|
||||
|
||||
const status = await remote.connect();
|
||||
|
@ -265,4 +257,119 @@ describe('gitlab remote', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('update issue endpoint', () => {
|
||||
it('should update issues when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const updateStub = stub(client.Issues, 'edit');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
issue: '1',
|
||||
labels: [],
|
||||
name: 'bar',
|
||||
project: 'foo',
|
||||
};
|
||||
const result = await remote.updateIssue(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(1).and.been.calledWithMatch(match.string, 1);
|
||||
});
|
||||
|
||||
it('should not update issues when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const updateStub = stub(client.Issues, 'edit');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
issue: 'foo',
|
||||
labels: [],
|
||||
name: '',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateIssue(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update label endpoint', () => {
|
||||
it('should update labels when dryrun=false', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const updateStub = stub(client.Labels, 'edit').returns(Promise.resolve({
|
||||
color: 'red',
|
||||
default: false,
|
||||
description: 'bar',
|
||||
id: 0,
|
||||
name: 'foo',
|
||||
url: '',
|
||||
}));
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, REMOTE_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: 'red',
|
||||
desc: 'bar',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(1).and.been.calledWithMatch(match.string, 'foo');
|
||||
});
|
||||
|
||||
it('should not update labels when dryrun=true', async () => {
|
||||
const module = new RemoteModule();
|
||||
const container = Container.from(module);
|
||||
await container.configure();
|
||||
|
||||
const client = new ProjectsBundle();
|
||||
stub(client.Projects, 'show').returns(Promise.resolve(STUB_PROJECT));
|
||||
const updateStub = stub(client.Labels, 'edit');
|
||||
module.bind(ProjectsBundle).toInstance(client);
|
||||
|
||||
const remote = await container.create(GitlabRemote, DRYRUN_OPTIONS);
|
||||
const status = await remote.connect();
|
||||
expect(status).to.equal(true);
|
||||
|
||||
const data = {
|
||||
color: '',
|
||||
desc: '',
|
||||
name: 'foo',
|
||||
project: '',
|
||||
};
|
||||
const result = await remote.updateLabel(data);
|
||||
|
||||
expect(result).to.include(data);
|
||||
expect(updateStub).to.have.callCount(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue