mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests: add channel create with perms test (#825)
This commit is contained in:
@@ -23,7 +23,7 @@ jobs:
|
|||||||
if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'run-tests' }}
|
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
|
run: deno test --unstable --coverage=coverage -A --no-check tests/mod.ts
|
||||||
- name: Create coverage report
|
- 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
|
- name: Collect coverage
|
||||||
uses: codecov/codecov-action@v1.0.10 # upload the report on Codecov
|
uses: codecov/codecov-action@v1.0.10 # upload the report on Codecov
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import { DiscordChannel } from "../../types/channels/channel.ts";
|
|||||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
requireBotGuildPermissions,
|
|
||||||
} from "../../util/permissions.ts";
|
|
||||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.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. */
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
export type DiscordOverwriteTypes = 0 | 1;
|
export enum DiscordOverwriteTypes {
|
||||||
|
ROLE,
|
||||||
|
MEMBER
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts";
|
|||||||
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
|
import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts";
|
||||||
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
import { createChannel } from "../../src/helpers/channels/create_channel.ts";
|
||||||
import { delayUntil } from "../util/delay_until.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) {
|
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||||
const channel = await createChannel(tempData.guildId, options);
|
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) {
|
if (options.topic && channel.topic !== options.topic) {
|
||||||
throw new Error(
|
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) {
|
if (options.bitrate && channel.bitrate !== options.bitrate) {
|
||||||
throw new Error(
|
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",
|
name: "Discordeno-test",
|
||||||
type: DiscordChannelTypes.GUILD_CATEGORY,
|
type: DiscordChannelTypes.GUILD_CATEGORY,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
@@ -81,7 +89,7 @@ Deno.test({
|
|||||||
name: "Discordeno-test",
|
name: "Discordeno-test",
|
||||||
type: DiscordChannelTypes.GUILD_VOICE,
|
type: DiscordChannelTypes.GUILD_VOICE,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
@@ -96,7 +104,7 @@ Deno.test({
|
|||||||
type: DiscordChannelTypes.GUILD_VOICE,
|
type: DiscordChannelTypes.GUILD_VOICE,
|
||||||
bitrate: 32000,
|
bitrate: 32000,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
@@ -111,7 +119,7 @@ Deno.test({
|
|||||||
type: DiscordChannelTypes.GUILD_VOICE,
|
type: DiscordChannelTypes.GUILD_VOICE,
|
||||||
userLimit: 32,
|
userLimit: 32,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
@@ -125,7 +133,7 @@ Deno.test({
|
|||||||
name: "Discordeno-test",
|
name: "Discordeno-test",
|
||||||
rateLimitPerUser: 2423,
|
rateLimitPerUser: 2423,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
...defaultTestOptions,
|
...defaultTestOptions,
|
||||||
@@ -139,6 +147,26 @@ Deno.test({
|
|||||||
...defaultTestOptions,
|
...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
|
// TODO: Need to validate tests for these options
|
||||||
// /** Sorting position of the channel */
|
// /** Sorting position of the channel */
|
||||||
// position?: number;
|
// position?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user