From aa30a2f707b813ec8e5b083be56e74c8dc0a9a63 Mon Sep 17 00:00:00 2001 From: Christian Paul <christianp@matrix.org> Date: Fri, 8 Jan 2021 17:37:05 +0100 Subject: [PATCH] Fix RoomCountLimitReached() --- src/provisioner.ts | 2 +- test/test_provisioner.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/provisioner.ts b/src/provisioner.ts index fee34cd..4abc68c 100644 --- a/src/provisioner.ts +++ b/src/provisioner.ts @@ -46,7 +46,7 @@ export class Provisioner { * @returns Has the limit been reached? */ public async RoomCountLimitReached(limit: number): Promise<boolean> { - return limit >= 0 && limit >= await this.roomStore.countEntries(); + return limit >= 0 && await this.roomStore.countEntries() >= limit; } public async UnbridgeChannel(channel: Discord.TextChannel, rId?: string) { diff --git a/test/test_provisioner.ts b/test/test_provisioner.ts index 8b1a3b8..fe2e34a 100644 --- a/test/test_provisioner.ts +++ b/test/test_provisioner.ts @@ -71,4 +71,30 @@ describe("Provisioner", () => { expect(await promise).to.eq("Approved"); }); }); + describe("RoomCountLimitReached", () => { + it("should return false if no limit is defined", async () => { + const p = new Provisioner({ + countEntries: async () => 7, + } as any, {} as any); + expect(await p.RoomCountLimitReached(-1)).to.equal(false); + }); + it("should return false if less rooms exist than the limit", async () => { + const p = new Provisioner({ + countEntries: async () => 7, + } as any, {} as any); + expect(await p.RoomCountLimitReached(10)).to.equal(false); + }); + it("should return true if more rooms exist than the limit", async () => { + const p = new Provisioner({ + countEntries: async () => 7, + } as any, {} as any); + expect(await p.RoomCountLimitReached(5)).to.equal(true); + }); + it("should return true if there are as many rooms as the limit allows", async () => { + const p = new Provisioner({ + countEntries: async () => 7, + } as any, {} as any); + expect(await p.RoomCountLimitReached(7)).to.equal(true); + }); + }); }); -- GitLab