From 040ad3c5005082a068d502678faaebd35853a377 Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 28 Aug 2020 18:51:46 -0500 Subject: [PATCH] fix(remote): return created comment for gitlab, cover remaining endpoints --- ...ious-journey.githubremote.createcomment.md | 4 +- ...ious-journey.gitlabremote.createcomment.md | 4 +- .../cautious-journey.remote.createcomment.md | 4 +- src/config/args.ts | 5 + src/remote/base.ts | 2 +- src/remote/github.ts | 2 +- src/remote/gitlab.ts | 4 +- src/remote/index.ts | 2 +- test/config/TestArgs.ts | 24 ++ test/{ => config}/TestConfig.ts | 2 +- test/remote/TestGithubRemote.ts | 281 +++++++++++----- test/remote/TestGitlabRemote.ts | 305 ++++++++++++------ 12 files changed, 451 insertions(+), 188 deletions(-) create mode 100644 test/config/TestArgs.ts rename test/{ => config}/TestConfig.ts (93%) diff --git a/docs/api/cautious-journey.githubremote.createcomment.md b/docs/api/cautious-journey.githubremote.createcomment.md index 3a763b4..c4179d2 100644 --- a/docs/api/cautious-journey.githubremote.createcomment.md +++ b/docs/api/cautious-journey.githubremote.createcomment.md @@ -7,7 +7,7 @@ Signature: ```typescript -createComment(options: CommentUpdate): Promise; +createComment(options: CommentUpdate): Promise; ``` ## Parameters @@ -18,5 +18,5 @@ createComment(options: CommentUpdate): Promise; Returns: -Promise<unknown> +Promise<CommentUpdate> diff --git a/docs/api/cautious-journey.gitlabremote.createcomment.md b/docs/api/cautious-journey.gitlabremote.createcomment.md index 0a4082e..c5e886f 100644 --- a/docs/api/cautious-journey.gitlabremote.createcomment.md +++ b/docs/api/cautious-journey.gitlabremote.createcomment.md @@ -7,7 +7,7 @@ Signature: ```typescript -createComment(options: CommentUpdate): Promise; +createComment(options: CommentUpdate): Promise; ``` ## Parameters @@ -18,5 +18,5 @@ createComment(options: CommentUpdate): Promise; Returns: -Promise<void> +Promise<CommentUpdate> diff --git a/docs/api/cautious-journey.remote.createcomment.md b/docs/api/cautious-journey.remote.createcomment.md index bf7ff2f..164b505 100644 --- a/docs/api/cautious-journey.remote.createcomment.md +++ b/docs/api/cautious-journey.remote.createcomment.md @@ -9,7 +9,7 @@ Add a comment to an issue (for attribution and auditing). Signature: ```typescript -createComment(options: CommentUpdate): Promise; +createComment(options: CommentUpdate): Promise; ``` ## Parameters @@ -20,5 +20,5 @@ createComment(options: CommentUpdate): Promise; Returns: -Promise<unknown> +Promise<CommentUpdate> diff --git a/src/config/args.ts b/src/config/args.ts index 4ee5f62..5e68bb8 100644 --- a/src/config/args.ts +++ b/src/config/args.ts @@ -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 { }, }) .completion() + .exitProcess(false) + .fail((msg: string, err: Error) => { + modeset(Commands.ERROR); + }) .help() .alias('help', 'h') .version(VERSION_INFO.package.version) diff --git a/src/remote/base.ts b/src/remote/base.ts index 87abf2c..f09459d 100644 --- a/src/remote/base.ts +++ b/src/remote/base.ts @@ -13,7 +13,7 @@ export abstract class BaseRemote implem } public abstract connect(): Promise; - public abstract createComment(options: CommentUpdate): Promise; + public abstract createComment(options: CommentUpdate): Promise; public abstract createLabel(options: LabelUpdate): Promise; public abstract deleteLabel(options: LabelQuery): Promise; public abstract listIssues(options: ProjectQuery): Promise>; diff --git a/src/remote/github.ts b/src/remote/github.ts index afab1a0..4764f3d 100644 --- a/src/remote/github.ts +++ b/src/remote/github.ts @@ -55,7 +55,7 @@ export class GithubRemote extends BaseRemote implements }; } - public async createComment(options: CommentUpdate): Promise { + public async createComment(options: CommentUpdate): Promise { const path = await this.resolvePath(options.project); const body = this.formatBody(options); diff --git a/src/remote/gitlab.ts b/src/remote/gitlab.ts index db7ec19..e4a200f 100644 --- a/src/remote/gitlab.ts +++ b/src/remote/gitlab.ts @@ -37,13 +37,15 @@ export class GitlabRemote extends BaseRemote implem return true; } - public async createComment(options: CommentUpdate): Promise { + public async createComment(options: CommentUpdate): Promise { 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 { diff --git a/src/remote/index.ts b/src/remote/index.ts index 8405297..c364734 100644 --- a/src/remote/index.ts +++ b/src/remote/index.ts @@ -61,7 +61,7 @@ export interface Remote { /** * Add a comment to an issue (for attribution and auditing). */ - createComment(options: CommentUpdate): Promise; + createComment(options: CommentUpdate): Promise; /** * Create a new label. diff --git a/test/config/TestArgs.ts b/test/config/TestArgs.ts new file mode 100644 index 0000000..1bf1efd --- /dev/null +++ b/test/config/TestArgs.ts @@ -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(); + } + }); +}); diff --git a/test/TestConfig.ts b/test/config/TestConfig.ts similarity index 93% rename from test/TestConfig.ts rename to test/config/TestConfig.ts index 7e461f3..2e2778a 100644 --- a/test/TestConfig.ts +++ b/test/config/TestConfig.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { validateConfig } from '../src/config'; +import { validateConfig } from '../../src/config'; describe('config', () => { describe('validate config', () => { diff --git a/test/remote/TestGithubRemote.ts b/test/remote/TestGithubRemote.ts index 0a1e182..0179a34 100644 --- a/test/remote/TestGithubRemote.ts +++ b/test/remote/TestGithubRemote.ts @@ -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 = { + 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).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); + }); + }); }); diff --git a/test/remote/TestGitlabRemote.ts b/test/remote/TestGitlabRemote.ts index d3cfcb0..6b921ef 100644 --- a/test/remote/TestGitlabRemote.ts +++ b/test/remote/TestGitlabRemote.ts @@ -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 = { + 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); + }); + }); });