2020-08-15 21:06:26 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
|
|
import { resolveLabels } from '../../src/resolve';
|
|
|
|
|
|
|
|
const TEST_LABELS = ['foo', 'bar'];
|
|
|
|
|
|
|
|
describe('resolve labels', () => {
|
2020-08-15 21:13:55 +00:00
|
|
|
describe('flags with unfulfilled requires rule', () => {
|
2020-08-15 21:06:26 +00:00
|
|
|
it('should be removed when required label is missing', () => {
|
|
|
|
const result = resolveLabels({
|
|
|
|
flags: [{
|
|
|
|
adds: [],
|
2020-08-15 21:13:55 +00:00
|
|
|
name: 'gayle',
|
2020-08-15 21:06:26 +00:00
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [{
|
2020-08-15 21:13:55 +00:00
|
|
|
name: 'linda',
|
2020-08-15 21:06:26 +00:00
|
|
|
}],
|
|
|
|
}],
|
2020-08-15 21:13:55 +00:00
|
|
|
labels: ['gayle'],
|
2020-08-15 21:06:26 +00:00
|
|
|
states: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.labels).to.deep.equal([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-15 21:13:55 +00:00
|
|
|
describe('flags with fulfilled requires rule', () => {
|
|
|
|
it('should make no changes', () => {
|
|
|
|
const result = resolveLabels({
|
|
|
|
flags: [{
|
|
|
|
adds: [],
|
|
|
|
name: 'gayle',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [{
|
|
|
|
name: 'linda',
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
labels: ['gayle', 'linda'],
|
|
|
|
states: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.labels).to.deep.equal(['gayle', 'linda']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-15 21:06:26 +00:00
|
|
|
describe('flags with add rules', () => {
|
|
|
|
it('should add the labels', () => {
|
|
|
|
const result = resolveLabels({
|
|
|
|
flags: [{
|
|
|
|
adds: [{
|
|
|
|
name: 'linda',
|
|
|
|
}],
|
|
|
|
name: 'bob',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
labels: ['bob'],
|
|
|
|
states: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.labels).to.deep.equal(['bob', 'linda']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('flags with remove rules', () => {
|
|
|
|
it('should remove labels', () => {
|
|
|
|
const result = resolveLabels({
|
|
|
|
flags: [{
|
|
|
|
adds: [],
|
|
|
|
name: 'bob',
|
|
|
|
priority: 1,
|
|
|
|
removes: [{
|
|
|
|
name: 'hugo',
|
|
|
|
}],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
labels: ['bob', 'hugo'],
|
|
|
|
states: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.labels).to.deep.equal(['bob']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|