mirror of
https://github.com/wassname/talk.git
synced 2026-08-18 12:30:39 +08:00
patches to reliability computation based on settings
This commit is contained in:
@@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user