Feat: stage instance tests

This commit is contained in:
Skillz4Killz
2021-11-23 18:15:19 +00:00
committed by GitHub
parent ef6befc2b5
commit d7dbdb66df
6 changed files with 58 additions and 17 deletions
+10 -3
View File
@@ -8,9 +8,16 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
}
return await bot.rest.runMethod<StageInstance>(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, {
channel_id: channelId,
const result = await bot.rest.runMethod<StageInstance>(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, {
channel_id: channelId.toString(),
topic,
privacy_level: privacyLevel,
privacy_level: privacyLevel || PrivacyLevel.GuildOnly,
});
return {
id: bot.transformers.snowflake(result.id),
guildId: bot.transformers.snowflake(result.guild_id),
channelId: bot.transformers.snowflake(result.channel_id),
topic: result.topic,
};
}
+18 -11
View File
@@ -1,15 +1,11 @@
import type { StageInstance } from "../../types/channels/stageInstance.ts";
import type { Bot } from "../../bot.ts";
import { ChannelTypes } from "../../types/channels/channelTypes.ts";
import { AtLeastOne } from "../../types/util.ts";
/** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */
export async function updateStageInstance(
bot: Bot,
channelId: bigint,
data: Partial<Pick<StageInstance, "topic" | "privacyLevel">> = {}
) {
export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtLeastOne<Pick<StageInstance, "topic">>) {
if (
data?.topic &&
data.topic &&
!bot.utils.validateLength(data.topic, {
min: 1,
max: 120,
@@ -18,8 +14,19 @@ export async function updateStageInstance(
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
}
return await bot.rest.runMethod<StageInstance>(bot.rest, "patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), {
topic: data.topic,
privacy_level: data.privacyLevel,
});
const result = await bot.rest.runMethod<StageInstance>(
bot.rest,
"patch",
bot.constants.endpoints.STAGE_INSTANCE(channelId),
{
topic: data.topic,
}
);
return {
id: bot.transformers.snowflake(result.id),
guildId: bot.transformers.snowflake(result.guild_id),
channelId: bot.transformers.snowflake(result.channel_id),
topic: result.topic,
};
}
+2 -2
View File
@@ -1,7 +1,7 @@
// TODO: add resource link
export enum PrivacyLevel {
/** The Stage instance is visible publicly, such as on Stage discovery */
Public = 1,
// Public = 1,
/** The Stage instance is visible to only guild members */
GuildOnly,
GuildOnly = 2,
}
+3 -1
View File
@@ -1,3 +1,5 @@
import { PrivacyLevel } from "./privacyLevel.ts";
/** https://discord.com/developers/docs/resources/stage-instance#auto-closing-stage-instance-structure */
export interface StageInstance {
/** The id of this Stage instance */
@@ -9,7 +11,7 @@ export interface StageInstance {
/** The topic of the Stage instance (1-120 characters) */
topic: string;
/** The privacy level of the Stage instance */
privacyLevel: number;
privacyLevel: PrivacyLevel;
/** Whether or not Stage discovery is disabled */
discoverableDisabled: boolean;
}
+24
View File
@@ -0,0 +1,24 @@
import { ChannelTypes } from "../../src/types/channels/channelTypes.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts";
import { assertNotEquals, assertExists } from "../deps.ts";
import { bot } from "../mod.ts";
Deno.test("[stage] Create a stage instance", async (t) => {
const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "instance",
type: ChannelTypes.GuildStageVoice,
});
const instance = await bot.helpers.createStageInstance(stage.id, "test it");
assertExists(instance);
await t.step("[stage] Edit a stage instance", async () => {
const edited = await bot.helpers.updateStageInstance(stage.id, {
topic: "edited"
})
assertNotEquals(edited.topic, stage.topic);
})
await t.step("[stage] Delete a stage instance", async () => {
await bot.helpers.deleteStageInstance(stage.id);
});
});
+1
View File
@@ -565,6 +565,7 @@ Deno.test({
});
import "./channels/connectToVoice.ts";
import "./channels/stageInstances.ts"
import "./emoji/createEmoji.ts";
import "./emoji/deleteEmojiWithReason.ts";
import "./emoji/deleteEmojiWithoutReason.ts";