From 942fea12bfb83ed57fb7eee1282822b4a7c959e8 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 29 Apr 2024 17:50:11 +0100 Subject: [PATCH 1/3] Update dependency minimatch to v9.0.4 (#422) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [minimatch](https://github.com/isaacs/minimatch) | dependencies | patch | [`9.0.3` -> `9.0.4`](https://renovatebot.com/diffs/npm/minimatch/9.0.3/9.0.4) | --- ### Release Notes
isaacs/minimatch (minimatch) ### [`v9.0.4`](https://github.com/isaacs/minimatch/compare/v9.0.3...v9.0.4) [Compare Source](https://github.com/isaacs/minimatch/compare/v9.0.3...v9.0.4)
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Reviewed-on: https://git.vylpes.xyz/RabbitLabs/vylbot-app/pulls/422 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c7f6758..8eb69ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "emoji-regex": "^10.0.0", "jest": "^29.0.0", "jest-mock-extended": "^3.0.0", - "minimatch": "9.0.3", + "minimatch": "9.0.4", "mysql": "^2.18.1", "random-bunny": "^2.1.6", "ts-jest": "^29.0.0", @@ -5968,9 +5968,9 @@ } }, "node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", "dependencies": { "brace-expansion": "^2.0.1" }, diff --git a/package.json b/package.json index feda17d..be0fe06 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "emoji-regex": "^10.0.0", "jest": "^29.0.0", "jest-mock-extended": "^3.0.0", - "minimatch": "9.0.3", + "minimatch": "9.0.4", "mysql": "^2.18.1", "random-bunny": "^2.1.6", "ts-jest": "^29.0.0", From f1c513bd16fe425d0ab7f3e864366f908a2a2861 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 29 Apr 2024 17:51:22 +0100 Subject: [PATCH 2/3] Update actions/checkout action to v4 (#430) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [actions/checkout](https://github.com/actions/checkout) | action | major | `v2` -> `v4` | --- ### Release Notes
actions/checkout (actions/checkout) ### [`v4`](https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v414) [Compare Source](https://github.com/actions/checkout/compare/v3...v4) - Disable `extensions.worktreeConfig` when disabling `sparse-checkout` by [@​jww3](https://github.com/jww3) in https://github.com/actions/checkout/pull/1692 - Add dependabot config by [@​cory-miller](https://github.com/cory-miller) in https://github.com/actions/checkout/pull/1688 - Bump the minor-actions-dependencies group with 2 updates by [@​dependabot](https://github.com/dependabot) in https://github.com/actions/checkout/pull/1693 - Bump word-wrap from 1.2.3 to 1.2.5 by [@​dependabot](https://github.com/dependabot) in https://github.com/actions/checkout/pull/1643 ### [`v3`](https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v360) [Compare Source](https://github.com/actions/checkout/compare/v2...v3) - [Fix: Mark test scripts with Bash'isms to be run via Bash](https://github.com/actions/checkout/pull/1377) - [Add option to fetch tags even if fetch-depth > 0](https://github.com/actions/checkout/pull/579)
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Reviewed-on: https://git.vylpes.xyz/RabbitLabs/vylbot-app/pulls/430 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- .forgejo/workflows/production.yml | 2 +- .forgejo/workflows/stage.yml | 2 +- .forgejo/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/production.yml b/.forgejo/workflows/production.yml index 31e558e..ef10e7e 100644 --- a/.forgejo/workflows/production.yml +++ b/.forgejo/workflows/production.yml @@ -12,7 +12,7 @@ jobs: runs-on: node steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v1 with: diff --git a/.forgejo/workflows/stage.yml b/.forgejo/workflows/stage.yml index 8c36636..d5da5e8 100644 --- a/.forgejo/workflows/stage.yml +++ b/.forgejo/workflows/stage.yml @@ -12,7 +12,7 @@ jobs: runs-on: node steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v1 with: diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml index 989ac4f..9c1ef33 100644 --- a/.forgejo/workflows/test.yml +++ b/.forgejo/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: node steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v1 with: From 7e625b232e8fa0228268e0022e207de8416340c3 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 4 May 2024 16:48:00 +0100 Subject: [PATCH 3/3] Create clear command tests --- tests/commands/clear.test.ts | 209 +++++++++++++++++++++++++++++++++-- 1 file changed, 201 insertions(+), 8 deletions(-) diff --git a/tests/commands/clear.test.ts b/tests/commands/clear.test.ts index 26efe44..9599dc9 100644 --- a/tests/commands/clear.test.ts +++ b/tests/commands/clear.test.ts @@ -1,23 +1,216 @@ +import { ChatInputCommandInteraction, PermissionsBitField, SlashCommandBuilder, SlashCommandNumberOption, TextChannel } from "discord.js"; +import Command from "../../src/commands/clear"; + beforeEach(() => { process.env = {}; }); describe('Constructor', () => { - test.todo("EXPECT values to be set"); + test("EXPECT values to be set", () => { + const command = new Command(); + + expect(command.CommandBuilder).toBeDefined(); + + const commandBuilder = command.CommandBuilder as SlashCommandBuilder; + + expect(commandBuilder.name).toBe("clear"); + expect(commandBuilder.description).toBe("Clears the channel of messages"); + expect(commandBuilder.default_member_permissions).toBe(PermissionsBitField.Flags.ManageMessages.toString()); + expect(commandBuilder.options.length).toBe(1); + + const commandBuilderCountOption = commandBuilder.options[0] as SlashCommandNumberOption; + + expect(commandBuilderCountOption.name).toBe("count"); + expect(commandBuilderCountOption.description).toBe("The amount to delete"); + expect(commandBuilderCountOption.required).toBe(true); + expect(commandBuilderCountOption.min_value).toBe(1); + expect(commandBuilderCountOption.max_value).toBe(100); + }); }); describe('Execute', () => { - test.todo("GIVEN input is valid, EXPECT messages to be cleared"); + test("GIVEN input is valid, EXPECT messages to be cleared", async () => { + // Arrange + const channel = { + manageable: true, + bulkDelete: jest.fn(), + } as unknown as TextChannel; - test.todo("GIVEN interaction is NOT a chat input command, EXPECT nothing to happen"); + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(50), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; - test.todo("GIVEN interaction.channel is null, EXPECT nothing to happen"); + // Act + const command = new Command(); + await command.execute(interaction); - test.todo("GIVEN totalClear input is NOT supplied, EXPECT invalid error"); + // Assert + expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1); - test.todo("GIVEN totalClear is less than or equal to 0, EXPECT invalid error"); + expect(interaction.options.getNumber).toHaveBeenCalledTimes(1); + expect(interaction.options.getNumber).toHaveBeenCalledWith("count"); - test.todo("GIVEN totalClear is greater than 100, EXPECT invalid error"); + expect(channel.bulkDelete).toHaveBeenCalledTimes(1); + expect(channel.bulkDelete).toHaveBeenCalledWith(50); - test.todo("GIVEN channel is NOT manageable, EXPECT insufficient permissions error"); + expect(interaction.reply).toHaveBeenCalledTimes(1); + expect(interaction.reply).toHaveBeenCalledWith("50 message(s) were removed."); + }); + + test("GIVEN interaction is NOT a chat input command, EXPECT nothing to happen", async () => { + // Arrange + const channel = { + manageable: true, + bulkDelete: jest.fn(), + } as unknown as TextChannel; + + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(false), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(50), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).not.toHaveBeenCalled(); + expect(channel.bulkDelete).not.toHaveBeenCalled(); + }); + + test("GIVEN interaction.channel is null, EXPECT nothing to happen", async () => { + // Arrange + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: null, + options: { + getNumber: jest.fn().mockReturnValue(50), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).not.toHaveBeenCalled(); + }); + + test("GIVEN totalClear input is NOT supplied, EXPECT invalid error", async () => { + // Arrange + const channel = { + manageable: true, + bulkDelete: jest.fn(), + } as unknown as TextChannel; + + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(null), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).toHaveBeenCalledTimes(1); + expect(interaction.reply).toHaveBeenCalledWith("Please specify an amount between 1 and 100."); + + expect(channel.bulkDelete).not.toHaveBeenCalled(); + }); + + test("GIVEN totalClear is less than or equal to 0, EXPECT invalid error", async () => { + // Arrange + const channel = { + manageable: true, + bulkDelete: jest.fn(), + } as unknown as TextChannel; + + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(0), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).toHaveBeenCalledTimes(1); + expect(interaction.reply).toHaveBeenCalledWith("Please specify an amount between 1 and 100."); + + expect(channel.bulkDelete).not.toHaveBeenCalled(); + }); + + test("GIVEN totalClear is greater than 100, EXPECT invalid error", async () => { + // Arrange + const channel = { + manageable: true, + bulkDelete: jest.fn(), + } as unknown as TextChannel; + + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(101), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).toHaveBeenCalledTimes(1); + expect(interaction.reply).toHaveBeenCalledWith("Please specify an amount between 1 and 100."); + + expect(channel.bulkDelete).not.toHaveBeenCalled(); + }); + + test("GIVEN channel is NOT manageable, EXPECT insufficient permissions error", async () => { + // Arrange + const channel = { + manageable: false, + bulkDelete: jest.fn(), + } as unknown as TextChannel; + + const interaction = { + isChatInputCommand: jest.fn().mockReturnValue(true), + channel: channel, + options: { + getNumber: jest.fn().mockReturnValue(50), + }, + reply: jest.fn(), + } as unknown as ChatInputCommandInteraction; + + // Act + const command = new Command(); + await command.execute(interaction); + + // Assert + expect(interaction.reply).toHaveBeenCalledTimes(1); + expect(interaction.reply).toHaveBeenCalledWith("Insufficient permissions. Please contact a moderator."); + + expect(channel.bulkDelete).not.toHaveBeenCalled(); + }); }); \ No newline at end of file