1
0
Fork 0

add test stubs

This commit is contained in:
ssube 2020-08-14 23:40:56 -05:00
parent 39a7091ac3
commit b404ecf62e
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
10 changed files with 137 additions and 4 deletions

View File

@ -41,6 +41,6 @@ export declare class GithubRemote implements Remote
| [listIssues(options)](./cautious-journey.githubremote.listissues.md) | | |
| [listLabels(options)](./cautious-journey.githubremote.listlabels.md) | | |
| [splitProject(project)](./cautious-journey.githubremote.splitproject.md) | | |
| [updateIssue()](./cautious-journey.githubremote.updateissue.md) | | |
| [updateIssue(options)](./cautious-journey.githubremote.updateissue.md) | | |
| [updateLabel(options)](./cautious-journey.githubremote.updatelabel.md) | | |

View File

@ -7,8 +7,15 @@
<b>Signature:</b>
```typescript
updateIssue(): Promise<IssueUpdate>;
updateIssue(options: IssueUpdate): Promise<IssueUpdate>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | IssueUpdate | |
<b>Returns:</b>
Promise&lt;IssueUpdate&gt;

View File

@ -140,8 +140,22 @@ export class GithubRemote implements Remote {
return labels;
}
public async updateIssue(): Promise<IssueUpdate> {
throw new NotImplementedError();
public async updateIssue(options: IssueUpdate): Promise<IssueUpdate> {
const path = await this.splitProject(options.project);
if (this.writeCapable) {
const data = await this.writeRequest.issues.setLabels({
/* eslint-disable-next-line camelcase */
issue_number: parseInt(options.issue, 10),
labels: options.labels,
owner: path.owner,
repo: path.repo,
});
this.options.logger.info({ data }, 'updated issue');
}
return options;
}
public async updateLabel(options: LabelUpdate): Promise<LabelUpdate> {

61
test/TestLabels.ts Normal file
View File

@ -0,0 +1,61 @@
import { expect } from 'chai';
import { getLabelNames } from '../src/labels';
describe('labels', () => {
describe('label name helper', () => {
it('should return an empty set', () => {
expect(getLabelNames([], []).size).to.equal(0);
});
it('should return all flags', () => {
const flags = [{
adds: [],
name: 'foo',
priority: 1,
removes: [],
requires: [],
}, {
adds: [],
name: 'bar',
priority: 1,
removes: [],
requires: [],
}];
const names = flags.map((f) => f.name);
const labels = getLabelNames(flags, []);
expect(Array.from(labels)).to.deep.equal(names);
});
it('should return all states', () => {
const values = [{
becomes: [],
name: 'bin',
priority: 1,
requires: [],
}];
const states = [{
adds: [],
name: 'foo',
priority: 1,
removes: [],
requires: [],
values,
}, {
adds: [],
name: 'bar',
priority: 1,
removes: [],
requires: [],
values,
}];
const labels = getLabelNames([], states);
expect(Array.from(labels)).to.deep.equal([
'foo/bin',
'bar/bin',
]);
});
});
});

17
test/TestUtils.ts Normal file
View File

@ -0,0 +1,17 @@
import { expect } from 'chai';
import { defaultTo } from '../src/utils';
const TEST_TRUE = 'foo';
const TEST_FALSE = 'bar';
describe('utils', () => {
describe('default to value helper', () => {
it('should return the first defined value', () => {
/* eslint-disable-next-line no-null/no-null */
expect(defaultTo(null, TEST_TRUE)).to.equal(TEST_TRUE);
expect(defaultTo(undefined, TEST_TRUE)).to.equal(TEST_TRUE);
expect(defaultTo(TEST_TRUE, TEST_FALSE)).to.equal(TEST_TRUE);
});
});
});

View File

@ -0,0 +1,13 @@
import bunyan from 'bunyan';
import { expect } from 'chai';
import { BunyanLogger } from '../../src/logger/bunyan';
describe('bunyan logger', async () => {
it('should create a logger', async () => {
const logger = BunyanLogger.create({
name: 'test-logger',
});
expect(logger).to.be.an.instanceOf(bunyan);
});
});

View File

@ -0,0 +1,5 @@
import { expect } from 'chai';
describe('github remote', () => {
it('should authenticate to Github API');
});

View File

@ -0,0 +1,5 @@
import { expect } from 'chai';
describe('gitlab remote', () => {
it('should authenticate to gitlab API');
});

View File

@ -0,0 +1,6 @@
import { expect } from 'chai';
describe('issue sync', () => {
it('should resolve each issue');
it('should update issues with label changes');
});

View File

@ -0,0 +1,5 @@
import { expect } from 'chai';
describe('label sync', () => {
it('should sync each label');
});