add channel overwrite has permission

This commit is contained in:
Skillz
2020-10-01 09:48:53 -04:00
parent 3d3aee8310
commit 2dc6b8d460
+52 -1
View File
@@ -10,8 +10,12 @@ import {
Intents,
Role,
} from "../mod.ts";
import { createServer } from "../src/handlers/guild.ts";
import { channelOverwriteHasPermission } from "../src/handlers/channel.ts";
import { createGuildChannel, createServer } from "../src/handlers/guild.ts";
import { Guild } from "../src/structures/guild.ts";
import { OverwriteType } from "../src/types/guild.ts";
import { Permissions } from "../src/types/permission.ts";
import { cache } from "../src/utils/cache.ts";
const token = Deno.env.get("DISCORD_TOKEN");
if (!token) throw "Token is not provided";
@@ -99,6 +103,53 @@ Deno.test({
...testOptions,
});
Deno.test({
name: "channel overwrite has permission",
async fn() {
const guild = cache.guilds.get(guildID)!;
const channel = await createGuildChannel(guild, "testing", {
permission_overwrites: [
{
id: roleID,
type: OverwriteType.ROLE,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"],
deny: ["USE_EXTERNAL_EMOJIS"],
},
],
});
assert(channel.id);
// Checks whether the role has these perms
assert(
channelOverwriteHasPermission(
guildID,
roleID,
channel.permission_overwrites || [],
[Permissions.VIEW_CHANNEL, Permissions.SEND_MESSAGES],
),
);
// Checks if this permission was actually disabled
assert(
!channelOverwriteHasPermission(
guildID,
roleID,
channel.permission_overwrites || [],
[Permissions.USE_EXTERNAL_EMOJIS],
),
);
// Checks if this permission is missing that was neither allowed nor denied
assert(
!channelOverwriteHasPermission(
guildID,
roleID,
channel.permission_overwrites || [],
[Permissions.MANAGE_MESSAGES],
),
);
},
...testOptions,
});
Deno.test({
name: "delete a role from the guild",
async fn() {