patches to reliability computation based on settings

This commit is contained in:
Wyatt Johnson
2018-05-23 16:18:22 -06:00
parent 921b85fba3
commit 975448ec69
8 changed files with 131 additions and 18 deletions
+53
View File
@@ -0,0 +1,53 @@
const chai = require('chai');
const { expect } = chai;
const { merge } = require('lodash');
const Karma = require('../../../services/karma');
const thresholdsBackup = {};
const thresholdsOverride = {
comment: {
RELIABLE: 1,
UNRELIABLE: -1,
},
flag: {
RELIABLE: 1,
UNRELIABLE: -1,
},
};
describe('services.Karma', () => {
before(() => {
// Backup the existing thresholds.
merge(thresholdsBackup, Karma.THRESHOLDS);
// Configure the thresholds to a known value.
merge(Karma.THRESHOLDS, thresholdsOverride);
expect(Karma.THRESHOLDS).to.deep.equal(thresholdsOverride);
});
after(() => {
// Restore the thresholds.
merge(Karma.THRESHOLDS, thresholdsBackup);
expect(Karma.THRESHOLDS).to.deep.equal(thresholdsBackup);
});
describe('#isReliable', () => {
it('neutral', () => {
expect(Karma.isReliable('comment', {})).to.be.null;
expect(Karma.isReliable('comment', { comment: {} })).to.be.null;
expect(Karma.isReliable('comment', { comment: { karma: 0 } })).to.be.null;
});
it('unreliable', () => {
expect(Karma.isReliable('comment', { comment: { karma: -1 } })).to.be
.false;
expect(Karma.isReliable('comment', { comment: { karma: -2 } })).to.be
.false;
});
it('reliable', () => {
expect(Karma.isReliable('comment', { comment: { karma: 1 } })).to.be.true;
expect(Karma.isReliable('comment', { comment: { karma: 2 } })).to.be.true;
});
});
});