diff --git a/src/provisioner.ts b/src/provisioner.ts index fee34cd92c6bb1f14cc94e1a42e7754ce485f175..4abc68c850e91fd9608d386cfc9b21bd7dd805f2 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 8b1a3b8d7e3adcb48f3a9aeaedf550f46c40d056..fe2e34a0989e3975eafba72a84743b2e4a427cf9 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); + }); + }); });