Spaces:
Running
Running
File size: 1,943 Bytes
5c2ed06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/**
* Tests for the username-prefixes chat plugin.
* @author Annika
*/
'use strict';
const assert = require('assert').strict;
const { PrefixManager } = require('../../../dist/server/chat-plugins/username-prefixes');
const PREFIX_DURATION = 10 * 24 * 60 * 60 * 1000;
describe('PrefixManager', function () {
beforeEach(() => {
this.prefixManager = new PrefixManager();
Config.forcedprefixes = [];
});
it('Config.forcedprefixes should reflect prefix additions and removals', () => {
this.prefixManager.addPrefix('forcedpublic', 'privacy');
this.prefixManager.addPrefix('nomodchat', 'modchat');
assert(Config.forcedprefixes.find(x => x.prefix === 'forcedpublic' && x.type === 'privacy'));
assert(Config.forcedprefixes.find(x => x.prefix === 'nomodchat' && x.type === 'modchat'));
this.prefixManager.removePrefix('forcedpublic', 'privacy');
this.prefixManager.removePrefix('nomodchat', 'modchat');
assert(!Config.forcedprefixes.find(x => x.prefix === 'forcedpublic' && x.type === 'privacy'));
assert(!Config.forcedprefixes.find(x => x.prefix === 'nomodchat' && x.type === 'modchat'));
});
it('should not overwrite manually specified prefixes', () => {
const time = Date.now() + PREFIX_DURATION;
Config.forcedprefixes = [{ prefix: 'manual', type: 'modchat', expireAt: time }];
this.prefixManager.addPrefix('nomodchat', 'modchat');
assert.deepEqual(Config.forcedprefixes, [
{ prefix: 'manual', type: 'modchat', expireAt: time },
{ prefix: 'nomodchat', type: 'modchat', expireAt: Config.forcedprefixes.find(x => x.prefix === 'nomodchat').expireAt },
]);
});
it('should correctly validate prefix types', () => {
assert.doesNotThrow(() => this.prefixManager.validateType('privacy'));
assert.doesNotThrow(() => this.prefixManager.validateType('modchat'));
assert.throws(() => this.prefixManager.validateType('gibberish'));
assert.throws(() => this.prefixManager.validateType(''));
});
});
|