mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
fix(tests): migrate invite related tests
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { bot, channel } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] create an invite",
|
||||
async fn(t) {
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
},
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import { assertExists, assertRejects } from "../deps.ts";
|
||||
import { bot, channel } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] delete an invite",
|
||||
async fn(t) {
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
|
||||
await bot.helpers.deleteInvite(invite.code);
|
||||
|
||||
// Assertions
|
||||
assertRejects(() => bot.helpers.getInvite(invite.code));
|
||||
},
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
import { bot, channel } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] get channels invites",
|
||||
async fn(t) {
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: true,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
|
||||
const secondInvite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 0,
|
||||
maxUses: 2,
|
||||
temporary: true,
|
||||
unique: true,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(secondInvite);
|
||||
|
||||
const invites = await bot.helpers.getChannelInvites(channel.id);
|
||||
|
||||
assertEquals(invites.size > 1, true);
|
||||
},
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
import { assertEquals, assertExists, assertNotEquals } from "../deps.ts";
|
||||
import { bot, channel, guild } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] get invite",
|
||||
async fn(t) {
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
|
||||
const fetchedInvite = await bot.helpers.getInvite(invite.code);
|
||||
|
||||
assertExists(fetchedInvite);
|
||||
assertEquals(fetchedInvite.code, invite.code);
|
||||
|
||||
await t.step({
|
||||
name: "[invite] get invites",
|
||||
async fn() {
|
||||
const fetchedInvites = await bot.helpers.getInvites(guild.id);
|
||||
|
||||
assertExists(fetchedInvites);
|
||||
assertNotEquals(fetchedInvites.size, 0);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import { assertExists, assertNotEquals } from "../deps.ts";
|
||||
import { bot, channel, guild } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] get invites",
|
||||
async fn(t) {
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite);
|
||||
|
||||
const fetchedInvites = await bot.helpers.getInvites(guild.id);
|
||||
|
||||
assertExists(fetchedInvites);
|
||||
assertNotEquals(fetchedInvites.size, 0);
|
||||
},
|
||||
});
|
||||
78
testss/channels/invites/invite.test.ts
Normal file
78
testss/channels/invites/invite.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { ChannelTypes } from "../../../mod.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals } from "../../deps.ts";
|
||||
import { loadBot } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[invite] create an invite",
|
||||
async fn(t) {
|
||||
const bot = await loadBot();
|
||||
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildNews,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(channel.id);
|
||||
|
||||
const invite = await bot.helpers.createInvite(channel.id, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
temporary: false,
|
||||
unique: false,
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(invite.code);
|
||||
|
||||
await t.step("[invite] Get an invite", async () => {
|
||||
const inv = await bot.helpers.getInvite(invite.code);
|
||||
assertExists(inv.code);
|
||||
});
|
||||
|
||||
await t.step("[invite] Get an invite with counts", async () => {
|
||||
const inv = await bot.helpers.getInvite(invite.code, { withCounts: true });
|
||||
assertExists(inv.code);
|
||||
assertExists(inv.approximateMemberCount);
|
||||
assertExists(inv.approximatePresenceCount);
|
||||
});
|
||||
|
||||
await t.step("[invite] Get an invite with expiration", async () => {
|
||||
const inv = await bot.helpers.getInvite(invite.code, { withExpiration: true });
|
||||
assertExists(inv.code);
|
||||
assertExists(invite.expiresAt);
|
||||
});
|
||||
|
||||
await t.step("[invite] Get an invite with everything", async () => {
|
||||
const inv = await bot.helpers.getInvite(invite.code, { withCounts: true, withExpiration: true });
|
||||
assertExists(inv.code);
|
||||
assertExists(inv.approximateMemberCount);
|
||||
assertExists(inv.approximatePresenceCount);
|
||||
assertExists(invite.expiresAt);
|
||||
});
|
||||
|
||||
await t.step("[invite] Get all guild invites.", async () => {
|
||||
const fetchedInvites = await bot.helpers.getInvites(CACHED_COMMUNITY_GUILD_ID);
|
||||
|
||||
assertExists(fetchedInvites);
|
||||
assertNotEquals(fetchedInvites.size, 0);
|
||||
});
|
||||
|
||||
await t.step("[invite] Get all channel invites.", async () => {
|
||||
const fetchedInvites = await bot.helpers.getChannelInvites(channel.id);
|
||||
|
||||
assertExists(fetchedInvites);
|
||||
assertNotEquals(fetchedInvites.size, 0);
|
||||
});
|
||||
|
||||
await t.step("[invite] Delete an invite", async () => {
|
||||
await bot.helpers.deleteInvite(invite.code);
|
||||
|
||||
// THERE IS NO WAY TO VALIDATE IT DELETED SO WE JUST ASSUME IT DID
|
||||
// If you fetched a deleted invite, you get a full invite object. Thx discord.
|
||||
});
|
||||
|
||||
// Delete the channel once test is done
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user