2020-08-31 03:41:48 +00:00
|
|
|
import { InvalidArgumentError } from '@apextoaster/js-utils';
|
2020-08-20 22:08:57 +00:00
|
|
|
import { expect } from 'chai';
|
2020-08-31 03:41:48 +00:00
|
|
|
import { Container, NullLogger } from 'noicejs';
|
2020-08-20 22:08:57 +00:00
|
|
|
import { alea } from 'seedrandom';
|
2020-08-31 03:41:48 +00:00
|
|
|
import { createStubInstance, match, spy, stub } from 'sinon';
|
2020-08-20 22:08:57 +00:00
|
|
|
|
|
|
|
import { BunyanLogger } from '../../src/logger/bunyan';
|
|
|
|
import { GithubRemote } from '../../src/remote/github';
|
2020-08-22 17:25:19 +00:00
|
|
|
import { syncProjectLabels, updateLabel } from '../../src/sync';
|
2020-08-31 03:41:48 +00:00
|
|
|
import { FlagLabel, StateLabel } from '../../src';
|
|
|
|
|
|
|
|
const TEST_FLAG: FlagLabel = {
|
|
|
|
adds: [],
|
|
|
|
color: 'aabbcc',
|
|
|
|
desc: '',
|
|
|
|
name: 'foo',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const TEST_STATE: StateLabel = {
|
|
|
|
adds: [],
|
|
|
|
color: '',
|
|
|
|
desc: '',
|
|
|
|
divider: '/',
|
|
|
|
name: 'foo',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
values: [{
|
|
|
|
adds: [],
|
|
|
|
becomes: [],
|
|
|
|
color: 'aabbcc',
|
|
|
|
name: 'bar',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
};
|
2020-08-20 22:08:57 +00:00
|
|
|
|
|
|
|
describe('project sync', () => {
|
|
|
|
describe('all labels', () => {
|
|
|
|
it('should sync each label');
|
|
|
|
it('should pick a stable random color for each label', async () => {
|
2020-08-22 15:24:50 +00:00
|
|
|
const container = Container.from();
|
|
|
|
await container.configure();
|
|
|
|
|
2020-08-20 22:08:57 +00:00
|
|
|
const logger = BunyanLogger.create({
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
const remoteConfig = {
|
|
|
|
data: {},
|
|
|
|
dryrun: true,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
};
|
2020-08-22 15:44:14 +00:00
|
|
|
const remote = await container.create(GithubRemote, remoteConfig);
|
2020-08-20 22:08:57 +00:00
|
|
|
const updateSpy = spy(remote, 'updateLabel');
|
|
|
|
|
2020-08-22 17:25:19 +00:00
|
|
|
await updateLabel({
|
2020-08-20 22:08:57 +00:00
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [
|
|
|
|
'ff0000',
|
|
|
|
],
|
|
|
|
comment: true,
|
2020-08-31 03:41:48 +00:00
|
|
|
flags: [TEST_FLAG],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-20 22:08:57 +00:00
|
|
|
name: '',
|
|
|
|
remote: remoteConfig,
|
|
|
|
states: [],
|
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote,
|
|
|
|
}, {
|
|
|
|
color: '',
|
|
|
|
desc: '',
|
|
|
|
name: 'foo',
|
|
|
|
project: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(updateSpy).to.have.callCount(1);
|
|
|
|
|
|
|
|
const COLOR_LENGTH = 6;
|
|
|
|
expect(updateSpy).to.have.been.calledWithMatch({
|
|
|
|
color: match.string.and(match((it) => it.length === COLOR_LENGTH)),
|
|
|
|
name: 'foo',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-28 04:07:58 +00:00
|
|
|
it('should create missing flags', async () => {
|
2020-08-22 15:24:50 +00:00
|
|
|
const container = Container.from();
|
|
|
|
await container.configure();
|
|
|
|
|
2020-08-20 22:08:57 +00:00
|
|
|
const logger = BunyanLogger.create({
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
const remoteConfig = {
|
|
|
|
data: {},
|
|
|
|
dryrun: true,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
};
|
2020-08-22 15:44:14 +00:00
|
|
|
const remote = await container.create(GithubRemote, remoteConfig);
|
2020-08-20 22:08:57 +00:00
|
|
|
const createStub = stub(remote, 'createLabel');
|
|
|
|
const deleteStub = stub(remote, 'deleteLabel');
|
|
|
|
const listStub = stub(remote, 'listLabels').returns(Promise.resolve([]));
|
|
|
|
|
|
|
|
await syncProjectLabels({
|
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [],
|
|
|
|
comment: true,
|
2020-08-31 03:41:48 +00:00
|
|
|
flags: [TEST_FLAG],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-20 22:08:57 +00:00
|
|
|
name: '',
|
|
|
|
remote: remoteConfig,
|
|
|
|
states: [],
|
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(listStub).to.have.callCount(1);
|
|
|
|
expect(createStub).to.have.callCount(1);
|
|
|
|
expect(deleteStub).to.have.callCount(0);
|
|
|
|
});
|
|
|
|
|
2020-08-28 04:07:58 +00:00
|
|
|
it('should create missing states', async () => {
|
|
|
|
const container = Container.from();
|
|
|
|
await container.configure();
|
|
|
|
|
|
|
|
const logger = BunyanLogger.create({
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
const remoteConfig = {
|
|
|
|
data: {},
|
|
|
|
dryrun: true,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
};
|
|
|
|
const remote = await container.create(GithubRemote, remoteConfig);
|
|
|
|
const createStub = stub(remote, 'createLabel');
|
|
|
|
const listStub = stub(remote, 'listLabels').returns(Promise.resolve([]));
|
|
|
|
|
|
|
|
await syncProjectLabels({
|
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [],
|
|
|
|
comment: true,
|
|
|
|
flags: [],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-28 04:07:58 +00:00
|
|
|
name: '',
|
|
|
|
remote: remoteConfig,
|
2020-08-31 03:41:48 +00:00
|
|
|
states: [TEST_STATE],
|
2020-08-28 04:07:58 +00:00
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(listStub).to.have.callCount(1);
|
|
|
|
expect(createStub).to.have.callCount(1).and.to.have.been.calledWithMatch({
|
|
|
|
name: 'foo/bar',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-20 22:08:57 +00:00
|
|
|
it('should delete extra labels', async () => {
|
2020-08-22 15:24:50 +00:00
|
|
|
const container = Container.from();
|
|
|
|
await container.configure();
|
|
|
|
|
2020-08-20 22:08:57 +00:00
|
|
|
const logger = BunyanLogger.create({
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
const remoteConfig = {
|
|
|
|
data: {},
|
|
|
|
dryrun: true,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
};
|
2020-08-22 15:44:14 +00:00
|
|
|
const remote = await container.create(GithubRemote, remoteConfig);
|
2020-08-20 22:08:57 +00:00
|
|
|
const createStub = stub(remote, 'createLabel');
|
|
|
|
const deleteStub = stub(remote, 'deleteLabel');
|
|
|
|
const listStub = stub(remote, 'listLabels').returns(Promise.resolve([{
|
|
|
|
color: '',
|
|
|
|
desc: '',
|
|
|
|
name: '',
|
|
|
|
project: '',
|
|
|
|
}]));
|
|
|
|
|
|
|
|
await syncProjectLabels({
|
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [],
|
|
|
|
comment: true,
|
|
|
|
flags: [],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-20 22:08:57 +00:00
|
|
|
name: '',
|
|
|
|
remote: remoteConfig,
|
|
|
|
states: [],
|
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(listStub).to.have.callCount(1);
|
|
|
|
expect(createStub).to.have.callCount(0);
|
|
|
|
expect(deleteStub).to.have.callCount(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('flag labels', () => {
|
|
|
|
it('should prefer flag color');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('state labels', () => {
|
|
|
|
it('should prefer value color');
|
|
|
|
it('should fall back to state color');
|
|
|
|
it('should use state divider');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('create label', () => {
|
|
|
|
it('should create label');
|
|
|
|
});
|
2020-08-31 03:41:48 +00:00
|
|
|
|
|
|
|
describe('update label', () => {
|
|
|
|
it('should update flags');
|
|
|
|
it('should update states', async () => {
|
|
|
|
const logger = NullLogger.global;
|
|
|
|
const remote = createStubInstance(GithubRemote);
|
|
|
|
|
|
|
|
await updateLabel({
|
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [],
|
|
|
|
comment: false,
|
|
|
|
flags: [],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-31 03:41:48 +00:00
|
|
|
name: '',
|
|
|
|
remote: {
|
|
|
|
data: {},
|
|
|
|
dryrun: false,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
},
|
|
|
|
states: [TEST_STATE],
|
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote,
|
|
|
|
}, {
|
|
|
|
color: '',
|
|
|
|
desc: '',
|
|
|
|
name: 'foo/bar',
|
|
|
|
project: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(remote.updateLabel).to.have.been.calledWithMatch({
|
|
|
|
name: 'foo/bar',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw on labels that do not exist', async () => {
|
|
|
|
const logger = NullLogger.global;
|
|
|
|
await expect(updateLabel({
|
|
|
|
logger,
|
|
|
|
project: {
|
|
|
|
colors: [],
|
|
|
|
comment: false,
|
|
|
|
flags: [],
|
2020-08-31 04:29:17 +00:00
|
|
|
initial: [],
|
2020-08-31 03:41:48 +00:00
|
|
|
name: '',
|
|
|
|
remote: {
|
|
|
|
data: {},
|
|
|
|
dryrun: false,
|
|
|
|
logger,
|
|
|
|
type: '',
|
|
|
|
},
|
|
|
|
states: [],
|
|
|
|
},
|
|
|
|
random: alea(),
|
|
|
|
remote: createStubInstance(GithubRemote),
|
|
|
|
}, {
|
|
|
|
color: '',
|
|
|
|
desc: '',
|
|
|
|
name: '',
|
|
|
|
project: '',
|
|
|
|
})).to.eventually.be.rejectedWith(InvalidArgumentError);
|
|
|
|
});
|
|
|
|
});
|
2020-08-20 22:08:57 +00:00
|
|
|
});
|