1
0
Fork 0
cautious-journey/test/sync/TestSyncIssues.ts

155 lines
3.5 KiB
TypeScript
Raw Normal View History

import { NotImplementedError } from '@apextoaster/js-utils';
2020-08-15 04:40:56 +00:00
import { expect } from 'chai';
2020-08-22 15:24:50 +00:00
import { Container, NullLogger } from 'noicejs';
import { alea } from 'seedrandom';
import sinon from 'sinon';
import { GithubRemote } from '../../src/remote/github';
import { syncIssueLabels } from '../../src/sync';
2020-08-15 04:40:56 +00:00
const { stub } = sinon;
2020-08-15 04:40:56 +00:00
describe('issue sync', () => {
it('should resolve each issue', async () => {
2020-08-22 15:24:50 +00:00
const container = Container.from();
await container.configure();
const logger = NullLogger.global;
const remoteData = {
data: {},
dryrun: true,
logger,
type: '',
};
2020-08-22 15:44:14 +00:00
const remote = await container.create(GithubRemote, remoteData);
const listStub = stub(remote, 'listIssues').returns(Promise.resolve([{
issue: '',
labels: ['nope'],
name: '',
project: 'foo',
}]));
const updateStub = stub(remote, 'updateIssue').returns(Promise.resolve({
issue: '',
labels: [],
name: '',
project: '',
}));
await syncIssueLabels({
logger,
project: {
colors: [],
comment: false,
flags: [{
adds: [],
name: 'nope',
priority: 0,
removes: [],
requires: [{
name: 'yep',
}],
}],
2020-08-31 04:29:17 +00:00
initial: [],
name: 'foo',
remote: remoteData,
states: [],
},
random: alea(),
remote,
});
expect(listStub).to.have.callCount(1);
expect(updateStub).to.have.callCount(1);
expect(updateStub).to.have.been.calledWithMatch({
project: 'foo',
});
});
it('should comment on updated issues', async () => {
const container = Container.from();
await container.configure();
const logger = NullLogger.global;
const remoteData = {
data: {},
dryrun: true,
logger,
type: '',
};
const remote = await container.create(GithubRemote, remoteData);
stub(remote, 'listIssues').resolves([{
issue: '',
labels: ['nope'],
name: '',
project: 'foo',
}]);
const commentStub = stub(remote, 'createComment');
await syncIssueLabels({
logger,
project: {
colors: [],
comment: true,
flags: [{
adds: [],
name: 'nope',
priority: 0,
removes: [],
requires: [{
name: 'yep',
}],
}],
initial: [],
name: 'foo',
remote: remoteData,
states: [],
},
random: alea(),
remote,
});
expect(commentStub).to.have.callCount(1);
});
it('should handle errors from the remote', async () => {
const container = Container.from();
await container.configure();
const logger = NullLogger.global;
const remoteData = {
data: {},
dryrun: true,
logger,
type: '',
};
const remote = await container.create(GithubRemote, remoteData);
const listStub = stub(remote, 'listIssues').rejects(NotImplementedError);
const result = await syncIssueLabels({
logger,
project: {
colors: [],
comment: false,
flags: [{
adds: [],
name: 'nope',
priority: 0,
removes: [],
requires: [{
name: 'yep',
}],
}],
initial: [],
name: 'foo',
remote: remoteData,
states: [],
},
random: alea(),
remote,
});
expect(listStub).to.have.callCount(1);
expect(result).to.equal(undefined);
});
2020-08-15 04:40:56 +00:00
});