mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests: add deleting channel overwrites test (#828)
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: DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} deno test --unstable --coverage=coverage -A --no-check tests/mod.ts
|
run: DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} deno test --unstable --coverage=coverage -A --no-check tests/mod.ts
|
||||||
- name: Create coverage report
|
- name: Create coverage report
|
||||||
run: deno --no-check --unstable coverage ./coverage --lcov > coverage.lcov # create coverage report
|
run: deno --unstable 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:
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export async function createDiscordenoChannel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DiscordenoChannel extends Channel {
|
export interface DiscordenoChannel extends Channel {
|
||||||
|
guildId: string;
|
||||||
// GETTERS
|
// GETTERS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||||
|
import { assertEquals, assertExists } from "../deps.ts";
|
||||||
|
import { cache } from "../../src/cache.ts";
|
||||||
|
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";
|
||||||
|
import { deleteChannelOverwrite } from "../../src/helpers/channels/delete_channel_overwrite.ts";
|
||||||
|
|
||||||
|
async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) {
|
||||||
|
const channel = await createChannel(tempData.guildId, options);
|
||||||
|
|
||||||
|
// Assertions
|
||||||
|
assertExists(channel);
|
||||||
|
assertEquals(channel.type, options.type || DiscordChannelTypes.GUILD_TEXT);
|
||||||
|
|
||||||
|
// Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed
|
||||||
|
await delayUntil(10000, () => cache.channels.has(channel.id));
|
||||||
|
|
||||||
|
if (!cache.channels.has(channel.id)) {
|
||||||
|
throw new Error("The channel seemed to be created but it was not cached.");
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await deleteChannelOverwrite(channel.guildId, channel.id, botId);
|
||||||
|
|
||||||
|
await delayUntil(10000, () => cache.channels.get(channel.id)?.permissionOverwrites?.length === 0);
|
||||||
|
|
||||||
|
if (cache.channels.get(channel.id)?.permissionOverwrites?.length !== 0) {
|
||||||
|
throw new Error(
|
||||||
|
"The channel permission overwrite was supposed to be deleted but it does not appear to be."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
@@ -15,6 +15,7 @@ import "./guilds/create_guild.ts";
|
|||||||
import "./channels/create_channel.ts";
|
import "./channels/create_channel.ts";
|
||||||
import "./channels/category_children.ts";
|
import "./channels/category_children.ts";
|
||||||
import "./channels/delete_channel.ts";
|
import "./channels/delete_channel.ts";
|
||||||
|
import "./channels/delete_channel_overwrite.ts";
|
||||||
|
|
||||||
// Emojis tests
|
// Emojis tests
|
||||||
import "./emojis/create_emoji.ts";
|
import "./emojis/create_emoji.ts";
|
||||||
|
|||||||
Reference in New Issue
Block a user