tests: add channel create with perms test (#825)

This commit is contained in:
Skillz4Killz
2021-04-11 14:40:56 -04:00
committed by GitHub
parent 52057fbb65
commit b357a5fb04
4 changed files with 42 additions and 12 deletions
+1 -1
View File
@@ -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:
+2 -3
View File
@@ -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(
+4 -1
View File
@@ -1 +1,4 @@
export type DiscordOverwriteTypes = 0 | 1;
export enum DiscordOverwriteTypes {
ROLE,
MEMBER
}
+35 -7
View File
@@ -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;