pokemon-showdown/test/server/chat-plugins/repeats.js
Slayer95 4b8c6a4d6d
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Refactor startup (#11346)
This minimizes side effects of import/require across the codebase,
and lets the caller be responsible of initializing child processeses,
as well as other async logic, such as restoring saved battles.
2025-10-17 19:37:47 -07:00

53 lines
1.6 KiB
JavaScript

/**
* Tests for the Repeats chat plugin
* @author Annika
*/
'use strict';
const assert = require('assert').strict;
describe("Repeats plugin", function () {
let Repeats = null;
before(() => {
Repeats = require('../../../dist/server/chat-plugins/repeats').Repeats;
this.room = Rooms.createChatRoom('repeatstest');
});
it('should add repeats correctly', () => {
assert(!Repeats.repeats.has(this.room));
Repeats.addRepeat(this.room, { id: 'happyface', phrase: "^_^", interval: 1 });
assert(Repeats.repeats.has(this.room));
assert(Repeats.repeats.get(this.room).has('happyface'));
assert(Repeats.repeats.get(this.room).get('happyface').has("^_^"));
assert(this.room.settings.repeats);
assert(this.room.settings.repeats.some(repeat => repeat.phrase === "^_^"));
});
it('should remove repeats correctly', () => {
Repeats.addRepeat(this.room, { id: 'weirdface', phrase: "^_-", interval: 1 });
assert(Repeats.repeats.get(this.room).get('weirdface').has("^_-"));
assert(this.room.settings.repeats.some(repeat => repeat.phrase === "^_-"));
Repeats.removeRepeat(this.room, 'weirdface');
assert.equal(Repeats.repeats.get(this.room).get('weirdface'), undefined);
assert(!this.room.settings.repeats.some(repeat => repeat.phrase === "^_-"));
});
it('should be able to tell if a repeat exists or not', () => {
assert(!Repeats.hasRepeat(this.room, 'annoyedface'));
Repeats.addRepeat(this.room, { id: 'annoyedface', phrase: "-_-", interval: 1 });
assert(Repeats.hasRepeat(this.room, 'annoyedface'));
Repeats.removeRepeat(this.room, 'annoyedface');
assert(!Repeats.hasRepeat(this.room, 'annoyedface'));
});
});