|
| 1 | +import { assertEquals } from "../deps.ts"; |
| 2 | +import { delay, describe } from "../testing/helpers.ts"; |
| 3 | +import { mock } from "../testing/mock.ts"; |
| 4 | + |
| 5 | +describe("plugins/antiflood", (test) => { |
| 6 | + test("send two PRIVMSG with delay", async () => { |
| 7 | + const { client, server } = await mock({ floodDelay: 250 }); |
| 8 | + |
| 9 | + client.privmsg("#channel", "Hello world"); |
| 10 | + client.privmsg("#channel", "Hello world, again"); |
| 11 | + let raw = server.receive(); |
| 12 | + |
| 13 | + // Should only get first message |
| 14 | + assertEquals(raw, [ |
| 15 | + "PRIVMSG #channel :Hello world", |
| 16 | + ]); |
| 17 | + |
| 18 | + // Wait for second message to make it through |
| 19 | + await delay(1000); |
| 20 | + raw = server.receive(); |
| 21 | + |
| 22 | + // Second message now dispatched to server |
| 23 | + assertEquals(raw, [ |
| 24 | + "PRIVMSG #channel :Hello world, again", |
| 25 | + ]); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe("plugins/antiflood", (test) => { |
| 30 | + test("disabled when delay not set", async () => { |
| 31 | + const { client, server } = await mock(); |
| 32 | + |
| 33 | + client.privmsg("#channel", "Hello world"); |
| 34 | + client.privmsg("#channel", "Hello world, again"); |
| 35 | + const raw = server.receive(); |
| 36 | + |
| 37 | + // Should get both messages |
| 38 | + assertEquals(raw, [ |
| 39 | + "PRIVMSG #channel :Hello world", |
| 40 | + "PRIVMSG #channel :Hello world, again", |
| 41 | + ]); |
| 42 | + }); |
| 43 | +}); |
0 commit comments