File size: 1,640 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
51
/**
 * Tests for the Repeats chat plugin
 * @author Annika
 */

'use strict';

const assert = require('assert').strict;
const Repeats = require('../../../dist/server/chat-plugins/repeats').Repeats;

describe("Repeats plugin", function () {
	before(() => {
		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'));
	});
});