From b357a5fb048ac4937f9232abcb55d8b6b90ba153 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 11 Apr 2021 14:40:56 -0400 Subject: [PATCH] tests: add channel create with perms test (#825) --- .github/workflows/test.yml | 2 +- src/helpers/channels/create_channel.ts | 5 ++- src/types/channels/overwrite_types.ts | 5 ++- tests/channels/create_channel.ts | 42 +++++++++++++++++++++----- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 489ab24f1..66ed11b98 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'run-tests' }} run: deno test --unstable --coverage=coverage -A --no-check tests/mod.ts - name: Create coverage report - run: deno --unstable coverage ./coverage --lcov > coverage.lcov # create coverage report + run: deno --unstable --no-check coverage ./coverage --lcov > coverage.lcov # create coverage report - name: Collect coverage uses: codecov/codecov-action@v1.0.10 # upload the report on Codecov with: diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 817656efd..9871c1486 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -6,11 +6,10 @@ import { DiscordChannel } from "../../types/channels/channel.ts"; import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts"; import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; -import { - requireBotGuildPermissions, -} from "../../util/permissions.ts"; +import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; +import { calculateBits } from "../../util/permissions.ts"; /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel( diff --git a/src/types/channels/overwrite_types.ts b/src/types/channels/overwrite_types.ts index e0c37c4ca..f3364e411 100644 --- a/src/types/channels/overwrite_types.ts +++ b/src/types/channels/overwrite_types.ts @@ -1 +1,4 @@ -export type DiscordOverwriteTypes = 0 | 1; +export enum DiscordOverwriteTypes { + ROLE, + MEMBER +} diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 9c237556f..d087b3948 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -5,6 +5,8 @@ import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { DiscordOverwriteTypes } from "../../src/types/channels/overwrite_types.ts" +import { botId } from "../../src/bot.ts"; async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { const channel = await createChannel(tempData.guildId, options); @@ -24,13 +26,19 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { if (options.topic && channel.topic !== options.topic) { throw new Error( - "The channel was supposed to have a topic but it does not appear to be the same topic.", + "The channel was supposed to have a topic but it does not appear to be the same topic." ); } if (options.bitrate && channel.bitrate !== options.bitrate) { throw new Error( - "The channel was supposed to have a bitrate but it does not appear to be the same bitrate.", + "The channel was supposed to have a bitrate but it does not appear to be the same bitrate." + ); + } + + if (options.permissionOverwrites && channel.permissionOverwrites.length !== options.permissionOverwrites.length) { + throw new Error( + "The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites." ); } } @@ -51,7 +59,7 @@ Deno.test({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_CATEGORY, }, - true, + true ); }, ...defaultTestOptions, @@ -81,7 +89,7 @@ Deno.test({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, }, - true, + true ); }, ...defaultTestOptions, @@ -96,7 +104,7 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, bitrate: 32000, }, - true, + true ); }, ...defaultTestOptions, @@ -111,7 +119,7 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, userLimit: 32, }, - true, + true ); }, ...defaultTestOptions, @@ -125,7 +133,7 @@ Deno.test({ name: "Discordeno-test", rateLimitPerUser: 2423, }, - true, + true ); }, ...defaultTestOptions, @@ -139,6 +147,26 @@ Deno.test({ ...defaultTestOptions, }); +Deno.test({ + name: "[channel] create a new text channel with permission overwrites", + async fn() { + await ifItFailsBlameWolf( + { + name: "Discordeno-test", + permissionOverwrites: [ + { + id: botId, + type: DiscordOverwriteTypes.MEMBER, + allow: ["VIEW_CHANNEL"], + deny: [], + }, + ], + }, + true + ); + }, + ...defaultTestOptions, +}); // TODO: Need to validate tests for these options // /** Sorting position of the channel */ // position?: number;