Skip to content

Commit

Permalink
fix(test): cover config validation, more github endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Aug 28, 2020
1 parent 0eb94b6 commit 4fea5c8
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/TestConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect } from 'chai';

import { validateConfig } from '../src/config';

describe('config', () => {
describe('validate config', () => {
it('should reject non-objects', () => {
expect(validateConfig('')).to.equal(false);
expect(validateConfig(1)).to.equal(false);
});

it('should insert default values', () => {
const config = {
logger: {
level: 'info',
name: 'test',
},
projects: [{
flags: undefined,
name: 'foo',
remote: {
data: {},
type: 'github-remote',
},
}]
};

expect(validateConfig(config)).to.equal(true);
expect(config.projects[0].flags).to.deep.equal([]);
});
});
});
232 changes: 232 additions & 0 deletions test/remote/TestGithubRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,236 @@ describe('github remote', () => {
expect(remote.writeCapable).to.equal(false);
expect(() => remote.writeClient).to.throw(InvalidArgumentError);
});

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 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: '',
});

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(client.issues.createLabel).to.have.callCount(1).and.been.calledWithMatch({
name: data.name,
});
});

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 Octokit();
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 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(client.issues.createLabel).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 Octokit();
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 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(client.issues.deleteLabel).to.have.callCount(1).and.been.calledWithMatch({
name: data.name,
});
});

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 Octokit();
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 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(client.issues.deleteLabel).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 Octokit();
const listStub = stub(client.issues, 'listForRepo').returns(Promise.resolve({
data: [],
headers: {},
status: 0,
url: '',
}));
module.bind(Octokit).toInstance(client);

for (const dryrun of [true, false]) {
const remote = await container.create(GithubRemote, {
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(client.issues.listForRepo).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 Octokit();
const listStub = stub(client.issues, 'listLabelsForRepo').returns(Promise.resolve({
data: [],
headers: {},
status: 0,
url: '',
}));
module.bind(Octokit).toInstance(client);

for (const dryrun of [true, false]) {
const remote = await container.create(GithubRemote, {
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(client.issues.listLabelsForRepo).to.have.callCount(1);
listStub.resetHistory();
}
});
});
});

0 comments on commit 4fea5c8

Please sign in to comment.