mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
test(rest): Restore the E2E tests (#4259)
* guild.spec.ts * automod.spec.ts * emoji.spec.ts * member.spec.ts * message.spec.ts * misc.spec.ts * role.spec.ts * stickers.spec.ts * user.spec.ts * webhook.spec.ts * delete dd-test-emoji role
This commit is contained in:
@@ -1,216 +1,239 @@
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
import { AutoModerationActionType, AutoModerationEventTypes, AutoModerationTriggerTypes } from '@discordeno/types'
|
||||
import { expect } from 'chai'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
describe('Automod tests', async () => {
|
||||
it('Create a MessageSend rule for Keyword with BlockMessage action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.BlockMessage,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
describe('Run automod tests', async () => {
|
||||
it.skip('Create a MessageSend rule for Keyword with BlockMessage action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.BlockMessage,
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
// expect(fetchedRule.id).to.be.exist
|
||||
// expect(fetchedRule.name).to.equal(rule.name)
|
||||
// expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
// expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
// expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
// expect(fetchedRule.actions).to.be.exist
|
||||
// expect(fetchedRule.actions[0]).to.be.exist
|
||||
// expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.be.exist
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
|
||||
it.skip('Create a MessageSend rule for Keyword with Timeout action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.Timeout,
|
||||
// metadata: {
|
||||
// durationSeconds: 10,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
// expect(fetchedRule.id).to.be.exist
|
||||
// expect(fetchedRule.name).to.equal(rule.name)
|
||||
// expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
// expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
// expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
// expect(fetchedRule.actions).to.be.exist
|
||||
// expect(fetchedRule.actions[0]).to.be.exist
|
||||
// expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.Timeout)
|
||||
// expect(fetchedRule.actions[0].metadata?.durationSeconds).to.equal(10)
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
it('Create a MessageSend rule for Keyword with Timeout action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.Timeout,
|
||||
metadata: {
|
||||
durationSeconds: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.be.exist
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.Timeout)
|
||||
expect(fetchedRule.actions[0].metadata?.durationSeconds).to.equal(10)
|
||||
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
|
||||
it.skip('Create a MessageSend rule for Keyword with BlockMessage & Timeout action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.BlockMessage,
|
||||
// },
|
||||
// {
|
||||
// type: AutoModerationActionType.Timeout,
|
||||
// metadata: {
|
||||
// durationSeconds: 10,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
it('Create a MessageSend rule for Keyword with BlockMessage & Timeout action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.BlockMessage,
|
||||
},
|
||||
{
|
||||
type: AutoModerationActionType.Timeout,
|
||||
metadata: {
|
||||
durationSeconds: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.have.length(2)
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
expect(fetchedRule.actions[1].type).to.equal(AutoModerationActionType.Timeout)
|
||||
expect(fetchedRule.actions[1].metadata?.durationSeconds).to.equal(10)
|
||||
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
|
||||
describe('with a channel', () => {
|
||||
// let channel: Camelize<DiscordChannel>
|
||||
it('Create a MessageSend rule for Keyword with SendAlertMessage action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.SendAlertMessage,
|
||||
metadata: {
|
||||
channelId: e2eCache.channel.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// beforeEach(async () => {
|
||||
// channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// })
|
||||
// })
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
// afterEach(async () => {
|
||||
// await rest.deleteChannel(channel.id)
|
||||
// })
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.be.exist
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
expect(fetchedRule.actions[0].metadata?.channelId).to.equal(e2eCache.channel.id)
|
||||
|
||||
it.skip('Create a MessageSend rule for Keyword with SendAlertMessage action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.SendAlertMessage,
|
||||
// metadata: {
|
||||
// channelId: channel.id,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
// expect(fetchedRule.id).to.be.exist
|
||||
// expect(fetchedRule.name).to.equal(rule.name)
|
||||
// expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
// expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
// expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
// expect(fetchedRule.actions).to.be.exist
|
||||
// expect(fetchedRule.actions[0]).to.be.exist
|
||||
// expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
// expect(fetchedRule.actions[0].metadata?.channelId).to.equal(channel.id)
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
|
||||
it.skip('Create a MessageSend rule for Keyword with SendAlertMessage & Timeout action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.SendAlertMessage,
|
||||
// metadata: {
|
||||
// channelId: channel.id,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// type: AutoModerationActionType.Timeout,
|
||||
// metadata: {
|
||||
// durationSeconds: 10,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
it('Create a MessageSend rule for Keyword with SendAlertMessage & Timeout action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.SendAlertMessage,
|
||||
metadata: {
|
||||
channelId: e2eCache.channel.id,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: AutoModerationActionType.Timeout,
|
||||
metadata: {
|
||||
durationSeconds: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.have.length(2)
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
expect(fetchedRule.actions[0].metadata?.channelId).to.equal(e2eCache.channel.id)
|
||||
expect(fetchedRule.actions[1].type).to.equal(AutoModerationActionType.Timeout)
|
||||
expect(fetchedRule.actions[1].metadata?.durationSeconds).to.equal(10)
|
||||
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
|
||||
it.skip('Create a MessageSend rule for Keyword with BlockMessage & SendAlertMessage & Timeout action.', async () => {
|
||||
// const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// eventType: AutoModerationEventTypes.MessageSend,
|
||||
// triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
// triggerMetadata: {
|
||||
// keywordFilter: ['iblamewolf'],
|
||||
// },
|
||||
// actions: [
|
||||
// {
|
||||
// type: AutoModerationActionType.BlockMessage,
|
||||
// },
|
||||
// {
|
||||
// type: AutoModerationActionType.SendAlertMessage,
|
||||
// metadata: {
|
||||
// channelId: channel.id,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// type: AutoModerationActionType.Timeout,
|
||||
// metadata: {
|
||||
// durationSeconds: 10,
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(rule.id).to.be.exist
|
||||
// // Get the rule again to make sure it was created correctly
|
||||
// const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
// expect(fetchedRule.id).to.be.exist
|
||||
// expect(fetchedRule.name).to.equal(rule.name)
|
||||
// expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
// expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
// expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
// expect(fetchedRule.actions).to.be.exist
|
||||
// expect(fetchedRule.actions[0]).to.be.exist
|
||||
// expect(fetchedRule.actions[1].metadata).to.be.exist
|
||||
// expect(fetchedRule.actions[2].metadata).to.be.exist
|
||||
// expect(fetchedRule.actions[1].metadata?.channelId).to.equal(channel.id)
|
||||
// expect(fetchedRule.actions[2].metadata?.durationSeconds).to.equal(10)
|
||||
// expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
// expect(fetchedRule.actions[1].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
// expect(fetchedRule.actions[2].type).to.equal(AutoModerationActionType.Timeout)
|
||||
// await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
it('Create a MessageSend rule for Keyword with BlockMessage & SendAlertMessage & Timeout action.', async () => {
|
||||
const rule = await rest.createAutomodRule(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
eventType: AutoModerationEventTypes.MessageSend,
|
||||
triggerType: AutoModerationTriggerTypes.Keyword,
|
||||
triggerMetadata: {
|
||||
keywordFilter: ['iblamewolf'],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
type: AutoModerationActionType.BlockMessage,
|
||||
},
|
||||
{
|
||||
type: AutoModerationActionType.SendAlertMessage,
|
||||
metadata: {
|
||||
channelId: e2eCache.channel.id,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: AutoModerationActionType.Timeout,
|
||||
metadata: {
|
||||
durationSeconds: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// Get the rule again to make sure it was created correctly
|
||||
const fetchedRule = await rest.getAutomodRule(e2eCache.guild.id, rule.id)
|
||||
|
||||
expect(rule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.be.exist
|
||||
expect(fetchedRule.id).to.equal(rule.id)
|
||||
expect(fetchedRule.name).to.equal(rule.name)
|
||||
expect(fetchedRule.eventType).to.equal(AutoModerationEventTypes.MessageSend)
|
||||
expect(fetchedRule.triggerType).to.equal(AutoModerationTriggerTypes.Keyword)
|
||||
expect(fetchedRule.triggerMetadata?.keywordFilter?.[0]).to.equal('iblamewolf')
|
||||
expect(fetchedRule.actions).to.be.exist
|
||||
expect(fetchedRule.actions[0]).to.be.exist
|
||||
expect(fetchedRule.actions[1].metadata).to.be.exist
|
||||
expect(fetchedRule.actions[2].metadata).to.be.exist
|
||||
expect(fetchedRule.actions[1].metadata?.channelId).to.equal(e2eCache.channel.id)
|
||||
expect(fetchedRule.actions[2].metadata?.durationSeconds).to.equal(10)
|
||||
expect(fetchedRule.actions[0].type).to.equal(AutoModerationActionType.BlockMessage)
|
||||
expect(fetchedRule.actions[1].type).to.equal(AutoModerationActionType.SendAlertMessage)
|
||||
expect(fetchedRule.actions[2].type).to.equal(AutoModerationActionType.Timeout)
|
||||
|
||||
await rest.deleteAutomodRule(e2eCache.guild.id, rule.id)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,113 +1,115 @@
|
||||
import { use as chaiUse } from 'chai'
|
||||
import type { Camelize, DiscordEmoji } from '@discordeno/types'
|
||||
import { urlToBase64 } from '@discordeno/utils'
|
||||
import { use as chaiUse, expect } from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import { describe, it } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
|
||||
describe('Create and delete emojis', () => {
|
||||
it.skip('create an emoji', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'blamewolf',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
// roles: [],
|
||||
// })
|
||||
// // Assertions
|
||||
// expect(emoji.id).to.be.exist
|
||||
// await rest.deleteEmoji(e2eCache.guild.id, emoji.id!)
|
||||
it('create an emoji', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'blamewolf',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
roles: [],
|
||||
})
|
||||
|
||||
// Assertions
|
||||
expect(emoji.id).to.be.exist
|
||||
await rest.deleteEmoji(e2eCache.guild.id, emoji.id!)
|
||||
})
|
||||
|
||||
// delete an emoji without a reason
|
||||
it.skip('delete an emoji without a reason', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'blamewolf',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
// roles: [],
|
||||
// })
|
||||
// // Assertions
|
||||
// expect(emoji.id).to.be.exist
|
||||
// await rest.deleteEmoji(e2eCache.guild.id, emoji.id!)
|
||||
// await expect(rest.getEmoji(e2eCache.guild.id, emoji.id!)).to.eventually.rejected
|
||||
it('delete an emoji without a reason', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'blamewolf',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
roles: [],
|
||||
})
|
||||
|
||||
// Assertions
|
||||
expect(emoji.id).to.be.exist
|
||||
await rest.deleteEmoji(e2eCache.guild.id, emoji.id!)
|
||||
await expect(rest.getEmoji(e2eCache.guild.id, emoji.id!)).to.eventually.rejected
|
||||
})
|
||||
|
||||
// delete an emoji with a reason
|
||||
it.skip('delete an emoji with a reason', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'blamewolf',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
// roles: [],
|
||||
// })
|
||||
// // Assertions
|
||||
// expect(emoji.id).to.be.exist
|
||||
// await rest.deleteEmoji(e2eCache.guild.id, emoji.id!, 'with a reason')
|
||||
// await expect(rest.getEmoji(e2eCache.guild.id, emoji.id!)).to.eventually.rejected
|
||||
it('delete an emoji with a reason', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'blamewolf',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
roles: [],
|
||||
})
|
||||
|
||||
// Assertions
|
||||
expect(emoji.id).to.be.exist
|
||||
await rest.deleteEmoji(e2eCache.guild.id, emoji.id!, 'with a reason')
|
||||
await expect(rest.getEmoji(e2eCache.guild.id, emoji.id!)).to.eventually.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('Edit and get emojis', () => {
|
||||
// let emoji: Camelize<DiscordEmoji> & { id: string }
|
||||
let emoji: Camelize<DiscordEmoji> & { id: string }
|
||||
|
||||
// beforeEach(async () => {
|
||||
// emoji = (await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'blamewolf',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
// roles: [],
|
||||
// })) as Camelize<DiscordEmoji> & { id: string }
|
||||
// })
|
||||
beforeEach(async () => {
|
||||
emoji = (await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'blamewolf',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
roles: [],
|
||||
})) as Camelize<DiscordEmoji> & { id: string }
|
||||
})
|
||||
|
||||
// afterEach(async () => {
|
||||
// await rest.deleteEmoji(e2eCache.guild.id, emoji.id)
|
||||
// })
|
||||
afterEach(async () => {
|
||||
await rest.deleteEmoji(e2eCache.guild.id, emoji.id)
|
||||
})
|
||||
|
||||
// edit an emoji name
|
||||
it.skip('Edit an emoji name', async () => {
|
||||
// await rest.editEmoji(e2eCache.guild.id, emoji.id, {
|
||||
// name: 'edited',
|
||||
// })
|
||||
// const edited = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
// expect(edited.name).to.equal('edited')
|
||||
it('Edit an emoji name', async () => {
|
||||
await rest.editEmoji(e2eCache.guild.id, emoji.id, {
|
||||
name: 'edited',
|
||||
})
|
||||
|
||||
const edited = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
expect(edited.name).to.equal('edited')
|
||||
})
|
||||
|
||||
// edit an emoji roles
|
||||
it.skip("Edit an emoji's roles", async () => {
|
||||
// const role = await rest.createRole(e2eCache.guild.id, {
|
||||
// name: 'dd-test-emoji',
|
||||
// })
|
||||
// await rest.editEmoji(e2eCache.guild.id, emoji.id, {
|
||||
// roles: [role.id],
|
||||
// })
|
||||
// const edited = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
// expect(edited.roles?.length).to.equal(1)
|
||||
it("Edit an emoji's roles", async () => {
|
||||
const role = await rest.createRole(e2eCache.guild.id, {
|
||||
name: 'dd-test-emoji',
|
||||
})
|
||||
after(async () => {
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
})
|
||||
await rest.editEmoji(e2eCache.guild.id, emoji.id, {
|
||||
roles: [role.id],
|
||||
})
|
||||
|
||||
const edited = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
expect(edited.roles?.length).to.equal(1)
|
||||
})
|
||||
|
||||
// get an emoji
|
||||
it.skip('get an emoji', async () => {
|
||||
// const exists = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
// expect(exists.id).to.be.exist
|
||||
// expect(emoji.id).to.equal(exists.id)
|
||||
it('get an emoji', async () => {
|
||||
const exists = await rest.getEmoji(e2eCache.guild.id, emoji.id)
|
||||
|
||||
expect(exists.id).to.be.exist
|
||||
expect(emoji.id).to.equal(exists.id)
|
||||
})
|
||||
|
||||
it.skip('get all guild emojis', async () => {
|
||||
// await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'blamewolf2',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
// roles: [],
|
||||
// })
|
||||
// const exists = await rest.getEmojis(e2eCache.guild.id)
|
||||
// expect(exists.length).to.greaterThan(1)
|
||||
it('get all guild emojis', async () => {
|
||||
const newEmoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'blamewolf2',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/814955268123000832.png'),
|
||||
roles: [],
|
||||
})
|
||||
|
||||
const exists = await rest.getEmojis(e2eCache.guild.id)
|
||||
expect(exists.length).to.greaterThan(1)
|
||||
expect(exists.find((x) => x.id === newEmoji.id)).to.exist
|
||||
expect(exists.find((x) => x.id === emoji.id)).to.exist
|
||||
|
||||
await rest.deleteEmoji(e2eCache.guild.id, newEmoji.id!)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,108 +1,93 @@
|
||||
import { ChannelTypes } from '@discordeno/types'
|
||||
import { use as chaiUse, expect } from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import { describe, it } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
})
|
||||
|
||||
describe('Manage Guilds', async () => {
|
||||
it.skip('Create and delete a guild', async () => {
|
||||
// const guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// expect(e2eCache.guild.id).to.be.exist
|
||||
// await rest.deleteGuild(guild.id)
|
||||
// Make sure the guild was deleted
|
||||
// const deleted = await rest.getGuild(guild.id).catch(() => undefined)
|
||||
// expect(deleted).to.be.equal(undefined)
|
||||
})
|
||||
|
||||
it('Get a guild', async () => {
|
||||
const exists = await rest.getGuild(e2eCache.communityGuildId)
|
||||
const exists = await rest.getGuild(e2eCache.guildId)
|
||||
expect(exists).to.be.exist
|
||||
expect(exists.id).to.be.exist
|
||||
// expect(exists.name).to.equal(e2eCache.guild.name)
|
||||
expect(exists.name).to.equal(e2eCache.guild.name)
|
||||
})
|
||||
|
||||
it.skip('AFK channel', async () => {
|
||||
// const voiceChannel = await rest.createChannel(e2eCache.guild.id, {
|
||||
// name: 'edit-guild-test',
|
||||
// type: ChannelTypes.GuildVoice,
|
||||
// })
|
||||
// expect(voiceChannel.id).to.be.exist
|
||||
// const edited = await rest.editGuild(e2eCache.guild.id, {
|
||||
// name: 'Discordeno-test-edited',
|
||||
// afkChannelId: voiceChannel.id,
|
||||
// // afkTimeout: 5,
|
||||
// })
|
||||
// expect(edited.name).to.equal('Discordeno-test-edited')
|
||||
// expect(e2eCache.guild.afkChannelId).to.not.equal(voiceChannel.id)
|
||||
// expect(edited.afkChannelId).to.equal(voiceChannel.id)
|
||||
// // expect(guild.afkTimeout).to.equal(0);
|
||||
// // expect(edited.afkTimeout).to.equal(5);
|
||||
// const edited2 = await rest.editGuild(e2eCache.guild.id, { afkChannelId: null })
|
||||
// expect(edited.afkChannelId).to.not.equal(edited2.afkChannelId)
|
||||
// // Use boolean to check both undefined or null
|
||||
// expect(!!edited2.afkChannelId).to.equal(false)
|
||||
// await rest.deleteChannel(voiceChannel.id)
|
||||
it('AFK channel', async () => {
|
||||
// Prepare the AFK channel
|
||||
const voiceChannel = await rest.createChannel(e2eCache.guild.id, {
|
||||
name: 'e2e-afk-channel',
|
||||
type: ChannelTypes.GuildVoice,
|
||||
})
|
||||
expect(voiceChannel.id).to.be.exist
|
||||
|
||||
// Set the AFK channel
|
||||
const edited = await rest.editGuild(e2eCache.guild.id, {
|
||||
afkChannelId: voiceChannel.id,
|
||||
})
|
||||
|
||||
expect(e2eCache.guild.afkChannelId).to.not.equal(voiceChannel.id)
|
||||
expect(edited.afkChannelId).to.equal(voiceChannel.id)
|
||||
expect(edited.afkChannelId).to.not.be.null
|
||||
|
||||
// Reset the AFK channel
|
||||
const edited2 = await rest.editGuild(e2eCache.guild.id, { afkChannelId: null })
|
||||
expect(edited2.afkChannelId).to.be.null
|
||||
|
||||
// Clean up the AFK channel
|
||||
await rest.deleteChannel(voiceChannel.id)
|
||||
})
|
||||
|
||||
// it("Edit a guild's afk settings", async () => {
|
||||
|
||||
// });
|
||||
|
||||
it.skip('Get audit logs', async () => {
|
||||
// const auditLogs = await rest.getAuditLog(e2eCache.guild.id, { limit: 1 })
|
||||
// expect(auditLogs.auditLogEntries.length).to.be.exist
|
||||
it('Get audit logs', async () => {
|
||||
const auditLogs = await rest.getAuditLog(e2eCache.guild.id, { limit: 1 })
|
||||
expect(auditLogs.auditLogEntries).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
// Get available voice regions
|
||||
it.skip('Get available voice regions', async () => {
|
||||
// const regions = await rest.getVoiceRegions(e2eCache.guild.id)
|
||||
// expect(regions.length).to.be.exist
|
||||
it('Get available voice regions', async () => {
|
||||
const regions = await rest.getVoiceRegions(e2eCache.guild.id)
|
||||
expect(regions).to.have.length.greaterThan(0)
|
||||
})
|
||||
|
||||
it.skip('Banning members', async () => {
|
||||
// await rest.banMember(
|
||||
// e2eCache.guild.id,
|
||||
// '379643682984296448',
|
||||
// {
|
||||
// deleteMessageSeconds: 604800,
|
||||
// },
|
||||
// 'Blame Wolf',
|
||||
// )
|
||||
// const fetchedBan = await rest.getBan(e2eCache.guild.id, '379643682984296448')
|
||||
// // Assertions
|
||||
// expect(fetchedBan).to.be.exist
|
||||
// expect(fetchedBan.user.id).to.equal('379643682984296448')
|
||||
// await rest.banMember(e2eCache.guild.id, '416477607966670869')
|
||||
// const fetchedBans = await rest.getBans(e2eCache.guild.id)
|
||||
// // Assertions
|
||||
// expect(fetchedBans).to.be.exist
|
||||
// expect(fetchedBans.length).to.greaterThanOrEqual(2)
|
||||
// await rest.unbanMember(e2eCache.guild.id, '416477607966670869')
|
||||
// await rest.unbanMember(e2eCache.guild.id, '379643682984296448')
|
||||
// const unbanned = await rest.getBans(e2eCache.guild.id)
|
||||
// expect(unbanned.length).to.equal(0)
|
||||
it('Banning members', async () => {
|
||||
// Ban members
|
||||
await rest.banMember(
|
||||
e2eCache.guild.id,
|
||||
'379643682984296448',
|
||||
{
|
||||
deleteMessageSeconds: 604800,
|
||||
},
|
||||
'Blame Wolf',
|
||||
)
|
||||
await rest.banMember(e2eCache.guild.id, '416477607966670869')
|
||||
|
||||
const fetchedBan = await rest.getBan(e2eCache.guild.id, '379643682984296448')
|
||||
const fetchedBans = await rest.getBans(e2eCache.guild.id)
|
||||
|
||||
// Assertions
|
||||
expect(fetchedBan).to.be.exist
|
||||
expect(fetchedBan.user.id).to.equal('379643682984296448')
|
||||
|
||||
// Assertions
|
||||
expect(fetchedBans).to.be.exist
|
||||
expect(fetchedBans.length).to.greaterThanOrEqual(2)
|
||||
|
||||
// Unban members
|
||||
await rest.unbanMember(e2eCache.guild.id, '416477607966670869')
|
||||
await rest.unbanMember(e2eCache.guild.id, '379643682984296448')
|
||||
|
||||
const unbanned = await rest.getBans(e2eCache.guild.id)
|
||||
expect(unbanned.length).to.equal(0)
|
||||
})
|
||||
|
||||
// Get vanity URL
|
||||
it.skip('Get vanity URL', async () => {
|
||||
// await expect(rest.getVanityUrl(e2eCache.guild.id)).to.eventually.rejected
|
||||
it('Get vanity URL', async () => {
|
||||
if (!e2eCache.guild.vanityUrlCode) {
|
||||
await expect(rest.getVanityUrl(e2eCache.guild.id)).to.eventually.rejected
|
||||
return
|
||||
}
|
||||
|
||||
await expect(rest.getVanityUrl(e2eCache.guild.id)).to.eventually.fulfilled
|
||||
})
|
||||
|
||||
// Get a welcome screen
|
||||
|
||||
@@ -4,30 +4,15 @@ import { describe, it } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
|
||||
describe('Member tests', () => {
|
||||
it("Fetches the bot and compares the bot's id with the fetched member's id", async () => {
|
||||
const member = await rest.getMember(e2eCache.communityGuildId, rest.applicationId)
|
||||
const member = await rest.getMember(e2eCache.guildId, rest.applicationId)
|
||||
expect(member?.user.id).to.exist
|
||||
expect(member?.user.id).to.equal(rest.applicationId.toString())
|
||||
})
|
||||
|
||||
it('Gets a member list and checks if the bot is in the member list', async () => {
|
||||
const members = await rest.getMembers(e2eCache.communityGuildId, {
|
||||
const members = await rest.getMembers(e2eCache.guildId, {
|
||||
limit: 10,
|
||||
})
|
||||
expect(members.some((m) => m.user.id === rest.applicationId.toString())).to.equal(true)
|
||||
@@ -35,20 +20,20 @@ describe('Member tests', () => {
|
||||
|
||||
// fetch a single member by id
|
||||
it('Fetch a single member by id', async () => {
|
||||
const member = await rest.getMember(e2eCache.communityGuildId, rest.applicationId)
|
||||
const member = await rest.getMember(e2eCache.guildId, rest.applicationId)
|
||||
|
||||
expect(member?.user.id).to.exist
|
||||
})
|
||||
|
||||
it("Edit a bot's nickname", async () => {
|
||||
const nick = 'lts20050703'
|
||||
const member = await rest.editBotMember(e2eCache.communityGuildId, {
|
||||
const member = await rest.editBotMember(e2eCache.guildId, {
|
||||
nick,
|
||||
})
|
||||
expect(member.nick).to.equal(nick)
|
||||
|
||||
// Change nickname back
|
||||
const member2 = await rest.editBotMember(e2eCache.communityGuildId, {
|
||||
const member2 = await rest.editBotMember(e2eCache.guildId, {
|
||||
nick: null,
|
||||
})
|
||||
expect(member2.nick).to.null
|
||||
|
||||
@@ -1,182 +1,204 @@
|
||||
import { processReactionString, urlToBase64 } from '@discordeno/utils'
|
||||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
// TODO: we need to create this many channels?
|
||||
|
||||
describe('Send a message', () => {
|
||||
it.skip('With content', async () => {
|
||||
// const message = await rest.sendMessage(e2eCache.channel.id, { content: 'testing rate limit manager' })
|
||||
// expect(message.content).to.be.equal('testing rate limit manager')
|
||||
// const edited = await rest.editMessage(message.channelId, message.id, { content: 'testing rate limit manager edited' })
|
||||
// expect(message.content).to.be.not.equal(edited.content)
|
||||
// await rest.deleteMessage(message.channelId, message.id)
|
||||
it('With content', async () => {
|
||||
const message = await rest.sendMessage(e2eCache.channel.id, { content: 'testing rate limit manager' })
|
||||
expect(message.content).to.be.equal('testing rate limit manager')
|
||||
const edited = await rest.editMessage(message.channelId, message.id, { content: 'testing rate limit manager edited' })
|
||||
expect(message.content).to.be.not.equal(edited.content)
|
||||
await rest.deleteMessage(message.channelId, message.id)
|
||||
})
|
||||
|
||||
it.skip('With an image', async () => {
|
||||
// const image = await fetch('https://cdn.discordapp.com/avatars/270010330782892032/d031ea881688526d1ae235fd2843e53c.jpg?size=2048')
|
||||
// .then(async (res) => await res.blob())
|
||||
// .catch(() => undefined)
|
||||
// expect(image).to.not.be.undefined
|
||||
// if (!image) throw new Error('Was not able to fetch the image.')
|
||||
// const message = await rest.sendMessage(e2eCache.channel.id, { files: [{ blob: image, name: 'gamer' }] })
|
||||
// expect(message.attachments.length).to.be.greaterThan(0)
|
||||
// const [attachment] = message.attachments
|
||||
// expect(attachment.filename).to.be.equal('gamer')
|
||||
it('With an image', async () => {
|
||||
const image = await fetch('https://cdn.discordapp.com/avatars/270010330782892032/d031ea881688526d1ae235fd2843e53c.jpg?size=2048')
|
||||
.then(async (res) => await res.blob())
|
||||
.catch(() => undefined)
|
||||
expect(image).to.not.be.undefined
|
||||
if (!image) throw new Error('Was not able to fetch the image.')
|
||||
const message = await rest.sendMessage(e2eCache.channel.id, { files: [{ blob: image, name: 'gamer' }] })
|
||||
expect(message.attachments.length).to.be.greaterThan(0)
|
||||
const [attachment] = message.attachments
|
||||
expect(attachment.filename).to.be.equal('gamer')
|
||||
})
|
||||
|
||||
it.skip('With a file attachment', async () => {
|
||||
// const txtFile = new Blob(['hello world'], { type: 'text/plain' })
|
||||
// const fileMsg = await rest.sendMessage(e2eCache.channel.id, {
|
||||
// content: '222',
|
||||
// files: [
|
||||
// {
|
||||
// name: 'application.txt',
|
||||
// blob: txtFile,
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(fileMsg.id).not.equals(undefined)
|
||||
// expect(fileMsg.content).equals('222')
|
||||
// expect(fileMsg.attachments.length).equals(1)
|
||||
// expect(fileMsg.attachments.at(0)?.filename).equals('application.txt')
|
||||
// expect(fileMsg.attachments.at(0)?.size).equals(11)
|
||||
// const txtFile2 = new Blob(['hello world edit'], { type: 'text/plain' })
|
||||
// const edited = await rest.editMessage(e2eCache.channel.id, fileMsg.id, {
|
||||
// content: '222 edit',
|
||||
// files: [
|
||||
// {
|
||||
// name: 'application_edit.txt',
|
||||
// blob: txtFile2,
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// expect(edited.id).not.equals(undefined)
|
||||
// expect(edited.content).equals('222 edit')
|
||||
// expect(edited.attachments.length).equals(1)
|
||||
// expect(edited.attachments.at(0)?.filename).equals('application_edit.txt')
|
||||
// expect(edited.attachments.at(0)?.size).equals(16)
|
||||
it('With a file attachment', async () => {
|
||||
const txtFile = new Blob(['hello world'], { type: 'text/plain' })
|
||||
const fileMsg = await rest.sendMessage(e2eCache.channel.id, {
|
||||
content: '222',
|
||||
files: [
|
||||
{
|
||||
name: 'application.txt',
|
||||
blob: txtFile,
|
||||
},
|
||||
],
|
||||
})
|
||||
expect(fileMsg.id).not.equals(undefined)
|
||||
expect(fileMsg.content).equals('222')
|
||||
expect(fileMsg.attachments.length).equals(1)
|
||||
expect(fileMsg.attachments.at(0)?.filename).equals('application.txt')
|
||||
expect(fileMsg.attachments.at(0)?.size).equals(11)
|
||||
const txtFile2 = new Blob(['hello world edit'], { type: 'text/plain' })
|
||||
const edited = await rest.editMessage(e2eCache.channel.id, fileMsg.id, {
|
||||
content: '222 edit',
|
||||
files: [
|
||||
{
|
||||
name: 'application_edit.txt',
|
||||
blob: txtFile2,
|
||||
},
|
||||
],
|
||||
})
|
||||
expect(edited.id).not.equals(undefined)
|
||||
expect(edited.content).equals('222 edit')
|
||||
expect(edited.attachments.length).equals(1)
|
||||
expect(edited.attachments.at(0)?.filename).equals('application_edit.txt')
|
||||
expect(edited.attachments.at(0)?.size).equals(16)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Manage reactions', async () => {
|
||||
it.skip('Add and delete a unicode reaction', async () => {
|
||||
// const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
// const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
// await rest.addReaction(message.channelId, message.id, '📙')
|
||||
// const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
// expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
// await rest.deleteOwnReaction(message.channelId, message.id, '📙')
|
||||
// const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// // Use boolean comparison because when its 0 length discord sends undefined
|
||||
// expect(!!unreacted.reactions?.length).to.be.equal(false)
|
||||
it('Add and delete a unicode reaction', async () => {
|
||||
const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(reactionChannel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
await rest.addReaction(message.channelId, message.id, '📙')
|
||||
const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
await rest.deleteOwnReaction(message.channelId, message.id, '📙')
|
||||
const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// Use boolean comparison because when its 0 length discord sends undefined
|
||||
expect(!!unreacted.reactions?.length).to.be.equal(false)
|
||||
})
|
||||
|
||||
it.skip('Add and delete a custom reaction', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'discordeno',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
// })
|
||||
// const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
// const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
// const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
// await rest.addReaction(message.channelId, message.id, emojiCode)
|
||||
// const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
// expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
// const reactions = await rest.getReactions(reactionChannel.id, message.id, processReactionString(emojiCode))
|
||||
// expect(reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
// await rest.deleteOwnReaction(message.channelId, message.id, emojiCode)
|
||||
// const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// // Use boolean comparison because when its 0 length discord sends undefined
|
||||
// expect(!!unreacted.reactions?.length).to.be.equal(false)
|
||||
it('Add and delete a custom reaction', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'discordeno',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
})
|
||||
const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(reactionChannel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
await rest.addReaction(message.channelId, message.id, emojiCode)
|
||||
const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
const reactions = await rest.getReactions(reactionChannel.id, message.id, processReactionString(emojiCode))
|
||||
expect(reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
await rest.deleteOwnReaction(message.channelId, message.id, emojiCode)
|
||||
const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// Use boolean comparison because when its 0 length discord sends undefined
|
||||
expect(!!unreacted.reactions?.length).to.be.equal(false)
|
||||
})
|
||||
|
||||
it.skip('Add several reactions with random order and delete all of them', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'discordeno',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
// })
|
||||
// const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
// const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
// const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
// await rest.addReactions(message.channelId, message.id, [emojiCode, '📙'])
|
||||
// const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
// expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
// await rest.deleteReactionsAll(message.channelId, message.id)
|
||||
// const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// // Use boolean comparison because when its 0 length discord sends undefined
|
||||
// expect(!!unreacted.reactions?.length).to.equal(false)
|
||||
it('Add several reactions with random order and delete all of them', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'discordeno',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
})
|
||||
const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(reactionChannel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
await rest.addReactions(message.channelId, message.id, [emojiCode, '📙'])
|
||||
const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
await rest.deleteReactionsAll(message.channelId, message.id)
|
||||
const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// Use boolean comparison because when its 0 length discord sends undefined
|
||||
expect(!!unreacted.reactions?.length).to.equal(false)
|
||||
})
|
||||
|
||||
it.skip('Add several reactions in an order and delete emoji reaction', async () => {
|
||||
// const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
// name: 'discordeno',
|
||||
// image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
// })
|
||||
// const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
// const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
// const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
// await rest.addReactions(message.channelId, message.id, [emojiCode, '📙'], true)
|
||||
// const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
// expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
// await rest.deleteReactionsEmoji(message.channelId, message.id, emojiCode)
|
||||
// const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// expect(unreacted.reactions?.length).to.greaterThanOrEqual(1)
|
||||
// await rest.deleteUserReaction(message.channelId, message.id, rest.applicationId.toString(), '📙')
|
||||
// const noreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// // Use boolean comparison because when its 0 length discord sends undefined
|
||||
// expect(!!noreacted.reactions?.length).to.equal(false)
|
||||
it('Add several reactions in an order and delete emoji reaction', async () => {
|
||||
const emoji = await rest.createEmoji(e2eCache.guild.id, {
|
||||
name: 'discordeno',
|
||||
image: await urlToBase64('https://cdn.discordapp.com/emojis/785403373817823272.webp?size=96'),
|
||||
})
|
||||
const emojiCode = `<:${emoji.name!}:${emoji.id!}>`
|
||||
const reactionChannel = await rest.createChannel(e2eCache.guild.id, { name: 'reactions' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(reactionChannel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(reactionChannel.id, { content: 'add reaction test' })
|
||||
await rest.addReactions(message.channelId, message.id, [emojiCode, '📙'], true)
|
||||
const reacted = await rest.getMessage(message.channelId, message.id)
|
||||
expect(reacted.reactions?.length).to.be.greaterThanOrEqual(1)
|
||||
await rest.deleteReactionsEmoji(message.channelId, message.id, emojiCode)
|
||||
const unreacted = await rest.getMessage(message.channelId, message.id)
|
||||
expect(unreacted.reactions?.length).to.greaterThanOrEqual(1)
|
||||
await rest.deleteUserReaction(message.channelId, message.id, rest.applicationId.toString(), '📙')
|
||||
const noreacted = await rest.getMessage(message.channelId, message.id)
|
||||
// Use boolean comparison because when its 0 length discord sends undefined
|
||||
expect(!!noreacted.reactions?.length).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Manage pins', () => {
|
||||
it.skip('Pin, get, and unpin messages', async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, { name: 'pinning' })
|
||||
// const message = await rest.sendMessage(channel.id, { content: 'pin me' })
|
||||
// const message2 = await rest.sendMessage(channel.id, { content: 'pin me 2' })
|
||||
// await rest.pinMessage(channel.id, message.id)
|
||||
// await rest.pinMessage(channel.id, message2.id, 'with a reason')
|
||||
// const pins = await rest.getPinnedMessages(channel.id)
|
||||
// expect(pins.length).to.equal(2)
|
||||
// expect(pins.some((p) => p.id === message.id)).to.equal(true)
|
||||
// await rest.unpinMessage(channel.id, message.id)
|
||||
// await rest.unpinMessage(channel.id, message2.id, 'with a reason')
|
||||
// const unpinned = await rest.getPinnedMessages(channel.id)
|
||||
// expect(unpinned.length).to.equal(0)
|
||||
it('Pin, get, and unpin messages', async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, { name: 'pinning' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(channel.id, { content: 'pin me' })
|
||||
const message2 = await rest.sendMessage(channel.id, { content: 'pin me 2' })
|
||||
await rest.pinMessage(channel.id, message.id)
|
||||
await rest.pinMessage(channel.id, message2.id, 'with a reason')
|
||||
const pins = await rest.getPinnedMessages(channel.id)
|
||||
expect(pins.length).to.equal(2)
|
||||
expect(pins.some((p) => p.id === message.id)).to.equal(true)
|
||||
await rest.unpinMessage(channel.id, message.id)
|
||||
await rest.unpinMessage(channel.id, message2.id, 'with a reason')
|
||||
const unpinned = await rest.getPinnedMessages(channel.id)
|
||||
expect(unpinned.length).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Rate limit manager testing', () => {
|
||||
it.skip('Send 10 messages to 1 channel', async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, { name: 'rate-limit-1' })
|
||||
// await Promise.all(
|
||||
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(async (i) => {
|
||||
// await rest.sendMessage(channel.id, { content: `10 messages to 1 channel testing rate limit manager ${i}` })
|
||||
// }),
|
||||
// )
|
||||
it('Send 10 messages to 1 channel', async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, { name: 'rate-limit-1' })
|
||||
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
|
||||
await Promise.all(
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(async (i) => {
|
||||
await rest.sendMessage(channel.id, { content: `10 messages to 1 channel testing rate limit manager ${i}` })
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it.skip('Send 10 messages to 10 channels', async () => {
|
||||
// await Promise.all(
|
||||
// [...Array(10).keys()].map(async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, { name: 'rate-limit-x' })
|
||||
// await Promise.all(
|
||||
// [...Array(10).keys()].map(async (_, index) => {
|
||||
// await rest.sendMessage(channel.id, { content: `testing rate limit manager ${index}` })
|
||||
// }),
|
||||
// )
|
||||
// }),
|
||||
// )
|
||||
it('Send 10 messages to 10 channels', async () => {
|
||||
await Promise.all(
|
||||
[...Array(10).keys()].map(async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, { name: 'rate-limit-x' })
|
||||
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
|
||||
await Promise.all(
|
||||
[...Array(10).keys()].map(async (_, index) => {
|
||||
await rest.sendMessage(channel.id, { content: `testing rate limit manager ${index}` })
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { describe } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
|
||||
describe('Typings', () => {
|
||||
it.skip('Trigger Typing Indication', async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, { name: 'typing' })
|
||||
// await rest.triggerTypingIndicator(channel.id)
|
||||
it('Trigger Typing Indication', async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, { name: 'typing' })
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
await rest.triggerTypingIndicator(channel.id)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,95 +1,99 @@
|
||||
import { calculateBits } from '@discordeno/utils'
|
||||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
|
||||
describe('Role tests', async () => {
|
||||
// Create a role with a reason
|
||||
it.skip('Create a role with a reason', async () => {
|
||||
// const role = await rest.createRole(
|
||||
// e2eCache.guild?.id,
|
||||
// {
|
||||
// name: `test role ${Date.now()}`,
|
||||
// },
|
||||
// 'test reason',
|
||||
// )
|
||||
// expect(role.id).to.exist
|
||||
it('Create a role with a reason', async () => {
|
||||
const role = await rest.createRole(
|
||||
e2eCache.guild?.id,
|
||||
{
|
||||
name: `test role ${Date.now()}`,
|
||||
},
|
||||
'test reason',
|
||||
)
|
||||
after(async () => {
|
||||
// Clean up the role created for testing
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
})
|
||||
expect(role.id).to.exist
|
||||
})
|
||||
|
||||
// Create a role without a reason
|
||||
it.skip('Create a role without a reason', async () => {
|
||||
// const role = await rest.createRole(e2eCache.guild.id, {
|
||||
// name: `test role ${Date.now()}`,
|
||||
// })
|
||||
// expect(role.id).to.exist
|
||||
it('Create a role without a reason', async () => {
|
||||
const role = await rest.createRole(e2eCache.guild.id, {
|
||||
name: `test role ${Date.now()}`,
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the role created for testing
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
})
|
||||
expect(role.id).to.exist
|
||||
})
|
||||
|
||||
// Delete a role
|
||||
it.skip('Delete a role', async () => {
|
||||
// const role = await rest.createRole(e2eCache.guild.id, {
|
||||
// name: `test role ${Date.now()}`,
|
||||
// })
|
||||
// await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
// const deletedRoles = await rest.getRoles(e2eCache.guild.id)
|
||||
// expect(deletedRoles.some((r) => r.id === role.id)).to.equal(false)
|
||||
it('Delete a role', async () => {
|
||||
const role = await rest.createRole(e2eCache.guild.id, {
|
||||
name: `test role ${Date.now()}`,
|
||||
})
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
const deletedRoles = await rest.getRoles(e2eCache.guild.id)
|
||||
expect(deletedRoles.some((r) => r.id === role.id)).to.equal(false)
|
||||
})
|
||||
|
||||
// Edit a role
|
||||
it.skip('Edit a role', async () => {
|
||||
// const role = await rest.createRole(e2eCache.guild.id, {
|
||||
// name: `test role ${Date.now()}`,
|
||||
// })
|
||||
// const edited = await rest.editRole(e2eCache.guild.id, role.id, {
|
||||
// name: 'test role 4',
|
||||
// color: 0x0000ff,
|
||||
// hoist: true,
|
||||
// mentionable: true,
|
||||
// permissions: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
|
||||
// })
|
||||
// expect(edited.name).to.equal('test role 4')
|
||||
// expect(edited.color).to.equal(0x0000ff)
|
||||
// expect(edited.hoist).to.equal(true)
|
||||
// expect(edited.mentionable).to.equal(true)
|
||||
// expect(edited.permissions.toString()).to.equal(calculateBits(['SEND_MESSAGES', 'VIEW_CHANNEL']))
|
||||
// await rest.editRole(e2eCache.guild.id, role.id, {
|
||||
// hoist: false,
|
||||
// mentionable: false,
|
||||
// })
|
||||
// const roles = await rest.getRoles(e2eCache.guild.id)
|
||||
// const unedited = roles.find((r) => r.id === role.id)
|
||||
// expect(unedited?.hoist).to.equal(false)
|
||||
// expect(unedited?.mentionable).to.equal(false)
|
||||
it('Edit a role', async () => {
|
||||
const role = await rest.createRole(e2eCache.guild.id, {
|
||||
name: `test role ${Date.now()}`,
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the role created for testing
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
})
|
||||
const edited = await rest.editRole(e2eCache.guild.id, role.id, {
|
||||
name: 'test role 4',
|
||||
color: 0x0000ff,
|
||||
hoist: true,
|
||||
mentionable: true,
|
||||
permissions: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
|
||||
})
|
||||
expect(edited.name).to.equal('test role 4')
|
||||
expect(edited.color).to.equal(0x0000ff)
|
||||
expect(edited.hoist).to.equal(true)
|
||||
expect(edited.mentionable).to.equal(true)
|
||||
expect(edited.permissions.toString()).to.equal(calculateBits(['SEND_MESSAGES', 'VIEW_CHANNEL']))
|
||||
await rest.editRole(e2eCache.guild.id, role.id, {
|
||||
hoist: false,
|
||||
mentionable: false,
|
||||
})
|
||||
const roles = await rest.getRoles(e2eCache.guild.id)
|
||||
const unedited = roles.find((r) => r.id === role.id)
|
||||
expect(unedited?.hoist).to.equal(false)
|
||||
expect(unedited?.mentionable).to.equal(false)
|
||||
})
|
||||
|
||||
it.skip('Add and remove role from user', async () => {
|
||||
// const role = await rest.createRole(e2eCache.guild.id, {
|
||||
// name: `test role ${Date.now()}`,
|
||||
// })
|
||||
// // Assign the role to the user
|
||||
// await rest.addRole(e2eCache.guild.id, rest.applicationId, role.id)
|
||||
// const member = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
// expect(member?.roles.includes(role.id)).to.equal(true)
|
||||
// await rest.removeRole(e2eCache.guild.id, rest.applicationId, role.id)
|
||||
// const removed = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
// // console.log('member', member.errors.userId.Errors)
|
||||
// expect(removed?.roles.includes(role.id)).to.equal(false)
|
||||
// // With a reason
|
||||
// await rest.addRole(e2eCache.guild.id, rest.applicationId, role.id, 'test reason')
|
||||
// const member2 = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
// expect(member2?.roles.includes(role.id)).to.equal(true)
|
||||
// await rest.removeRole(e2eCache.guild.id, rest.applicationId, role.id, 'test reason')
|
||||
// const member3 = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
// expect(member3?.roles.includes(role.id)).to.equal(false)
|
||||
it('Add and remove role from user', async () => {
|
||||
const role = await rest.createRole(e2eCache.guild.id, {
|
||||
name: `test role ${Date.now()}`,
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the role created for testing
|
||||
await rest.deleteRole(e2eCache.guild.id, role.id)
|
||||
})
|
||||
// Assign the role to the user
|
||||
await rest.addRole(e2eCache.guild.id, rest.applicationId, role.id)
|
||||
const member = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
expect(member?.roles.includes(role.id)).to.equal(true)
|
||||
await rest.removeRole(e2eCache.guild.id, rest.applicationId, role.id)
|
||||
const removed = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
expect(removed?.roles.includes(role.id)).to.equal(false)
|
||||
// With a reason
|
||||
await rest.addRole(e2eCache.guild.id, rest.applicationId, role.id, 'test reason')
|
||||
const member2 = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
expect(member2?.roles.includes(role.id)).to.equal(true)
|
||||
await rest.removeRole(e2eCache.guild.id, rest.applicationId, role.id, 'test reason')
|
||||
const member3 = await rest.getMember(e2eCache.guild.id, rest.applicationId)
|
||||
expect(member3?.roles.includes(role.id)).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
import { StickerFormatTypes } from '@discordeno/types'
|
||||
import { use as chaiUse, expect } from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import { describe, it } from 'mocha'
|
||||
import { rest } from './utils.js'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
|
||||
// waiting for channel
|
||||
describe('Sticker tests', async () => {
|
||||
it('Can get a sticker', async () => {
|
||||
@@ -26,52 +12,60 @@ describe('Sticker tests', async () => {
|
||||
expect(sticker.name).to.equal('Wave')
|
||||
})
|
||||
|
||||
it.skip('Create, edit, get, and delete guild sticker', async () => {
|
||||
// const sticker = await rest.createGuildSticker(e2eCache.guild.id, {
|
||||
// name: 'sticker name',
|
||||
// description: 'sticker description',
|
||||
// tags: 'sticker tags',
|
||||
// file: {
|
||||
// blob: await (await fetch('https://i.imgur.com/ejqd6Ro.png')).blob(),
|
||||
// name: 'ddlogo.png',
|
||||
// },
|
||||
// })
|
||||
// expect(sticker.name).to.equal('sticker name')
|
||||
// expect(sticker.description).to.equal('sticker description')
|
||||
// expect(sticker.tags).to.equal('sticker tags')
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
// name: 'test',
|
||||
// })
|
||||
// const message = await rest.sendMessage(channel.id, {
|
||||
// stickerIds: [sticker.id],
|
||||
// })
|
||||
// expect(message.stickerItems?.[0].formatType).to.equal(StickerFormatTypes.Png)
|
||||
// expect(message.stickerItems?.[0].id).to.equal(sticker.id)
|
||||
// expect(message.stickerItems?.[0].name).to.equal(sticker.name)
|
||||
// const getSticker = await rest.getGuildSticker(e2eCache.guild.id, sticker.id)
|
||||
// expect(getSticker.name).to.equal('sticker name')
|
||||
// expect(getSticker.description).to.equal('sticker description')
|
||||
// expect(getSticker.tags).to.equal('sticker tags')
|
||||
// const editSticker = await rest.editGuildSticker(e2eCache.guild.id, sticker.id, {
|
||||
// name: 'sticker name',
|
||||
// description: 'sticker description',
|
||||
// tags: 'sticker tags',
|
||||
// })
|
||||
// expect(editSticker.name).to.equal('sticker name')
|
||||
// expect(editSticker.description).to.equal('sticker description')
|
||||
// expect(editSticker.tags).to.equal('sticker tags')
|
||||
// await rest.createGuildSticker(e2eCache.guild.id, {
|
||||
// name: 'sticker 2',
|
||||
// description: 'sticker 2',
|
||||
// tags: 'sticker tags 2',
|
||||
// file: {
|
||||
// blob: await (await fetch('https://i.imgur.com/ejqd6Ro.png')).blob(),
|
||||
// name: 'ddlogo.png',
|
||||
// },
|
||||
// })
|
||||
// const stickers = await rest.getGuildStickers(e2eCache.guild.id)
|
||||
// expect(stickers.length).to.greaterThan(1)
|
||||
// await rest.deleteGuildSticker(e2eCache.guild.id, sticker.id)
|
||||
// await expect(rest.getGuildSticker(e2eCache.guild.id, sticker.id)).to.eventually.rejected
|
||||
it('Create, edit, get, and delete guild sticker', async () => {
|
||||
const sticker = await rest.createGuildSticker(e2eCache.guild.id, {
|
||||
name: 'sticker name',
|
||||
description: 'sticker description',
|
||||
tags: 'sticker tags',
|
||||
file: {
|
||||
blob: await (await fetch('https://i.imgur.com/ejqd6Ro.png')).blob(),
|
||||
name: 'ddlogo.png',
|
||||
},
|
||||
})
|
||||
expect(sticker.name).to.equal('sticker name')
|
||||
expect(sticker.description).to.equal('sticker description')
|
||||
expect(sticker.tags).to.equal('sticker tags')
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
name: 'test',
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
const message = await rest.sendMessage(channel.id, {
|
||||
stickerIds: [sticker.id],
|
||||
})
|
||||
expect(message.stickerItems?.[0].formatType).to.equal(StickerFormatTypes.Png)
|
||||
expect(message.stickerItems?.[0].id).to.equal(sticker.id)
|
||||
expect(message.stickerItems?.[0].name).to.equal(sticker.name)
|
||||
const getSticker = await rest.getGuildSticker(e2eCache.guild.id, sticker.id)
|
||||
expect(getSticker.name).to.equal('sticker name')
|
||||
expect(getSticker.description).to.equal('sticker description')
|
||||
expect(getSticker.tags).to.equal('sticker tags')
|
||||
const editSticker = await rest.editGuildSticker(e2eCache.guild.id, sticker.id, {
|
||||
name: 'sticker name',
|
||||
description: 'sticker description',
|
||||
tags: 'sticker tags',
|
||||
})
|
||||
expect(editSticker.name).to.equal('sticker name')
|
||||
expect(editSticker.description).to.equal('sticker description')
|
||||
expect(editSticker.tags).to.equal('sticker tags')
|
||||
const sticker2 = await rest.createGuildSticker(e2eCache.guild.id, {
|
||||
name: 'sticker 2',
|
||||
description: 'sticker 2',
|
||||
tags: 'sticker tags 2',
|
||||
file: {
|
||||
blob: await (await fetch('https://i.imgur.com/ejqd6Ro.png')).blob(),
|
||||
name: 'ddlogo.png',
|
||||
},
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the sticker created for testing
|
||||
await rest.deleteGuildSticker(e2eCache.guild.id, sticker2.id)
|
||||
})
|
||||
const stickers = await rest.getGuildStickers(e2eCache.guild.id)
|
||||
expect(stickers.length).to.greaterThan(1)
|
||||
await rest.deleteGuildSticker(e2eCache.guild.id, sticker.id)
|
||||
await expect(rest.getGuildSticker(e2eCache.guild.id, sticker.id)).to.eventually.rejected
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,20 +4,6 @@ import { describe, it } from 'mocha'
|
||||
import { rest } from './utils.js'
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
|
||||
describe('Get a user from the api', () => {
|
||||
it('With a valid user id', async () => {
|
||||
const user = await rest.getUser('130136895395987456')
|
||||
@@ -45,6 +31,6 @@ describe('Get a user from the api', () => {
|
||||
})
|
||||
|
||||
it('With an invalid user id', async () => {
|
||||
await expect(rest.getUser('123')).eventually.throws
|
||||
await expect(rest.getUser('123')).eventually.rejected
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { after } from 'mocha'
|
||||
import { createRestManager } from '../../src/manager.js'
|
||||
import { E2E_TEST_GUILD_ID, token } from './constants.js'
|
||||
// For debugging purposes
|
||||
@@ -9,12 +10,22 @@ export const rest = createRestManager({
|
||||
})
|
||||
rest.deleteQueueDelay = 10000
|
||||
|
||||
// const guild = await rest.createGuild({ name: 'ddenotester' })
|
||||
// const channel = await rest.createChannel(guild.id, { name: 'ddenotestchannel' })
|
||||
const guild = await rest.getGuild(E2E_TEST_GUILD_ID)
|
||||
if (!guild) throw new Error('E2E_TEST_GUILD_ID does not exist or is not accessible.')
|
||||
|
||||
const channel = await rest.createChannel(guild.id, {
|
||||
name: 'discordeno-e2e',
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
// Clean up the channel created for testing
|
||||
if (channel.id) {
|
||||
await rest.deleteChannel(channel.id)
|
||||
}
|
||||
})
|
||||
|
||||
export const e2eCache = {
|
||||
// guild,
|
||||
// channel,
|
||||
// deletedGuild: false,
|
||||
communityGuildId: E2E_TEST_GUILD_ID,
|
||||
guildId: E2E_TEST_GUILD_ID,
|
||||
guild,
|
||||
channel,
|
||||
}
|
||||
|
||||
@@ -1,87 +1,82 @@
|
||||
import { use as chaiUse } from 'chai'
|
||||
import { use as chaiUse, expect } from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import { describe, it } from 'mocha'
|
||||
import { e2eCache, rest } from './utils.js'
|
||||
chaiUse(chaiAsPromised)
|
||||
|
||||
// before(async () => {
|
||||
// if (!e2eCache.guild) {
|
||||
// e2eCache.guild = await rest.createGuild({
|
||||
// name: 'Discordeno-test',
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (e2eCache.guild.id && !e2eCache.deletedGuild) {
|
||||
// e2eCache.deletedGuild = true
|
||||
// await rest.deleteGuild(e2eCache.guild.id)
|
||||
// }
|
||||
// })
|
||||
|
||||
describe('Webhook helpers', async () => {
|
||||
it.skip('Manage webhooks', async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
// name: 'wbhook',
|
||||
// })
|
||||
// const webhook = await rest.createWebhook(channel.id, {
|
||||
// name: 'idk',
|
||||
// })
|
||||
// expect(webhook).to.exist
|
||||
// expect(webhook.name).to.equal('idk')
|
||||
// expect(webhook.token).to.exist
|
||||
// const fetched = await rest.getWebhook(webhook.id)
|
||||
// expect(fetched).to.exist
|
||||
// expect(webhook.id).to.equal(fetched.id)
|
||||
// const fetched2 = await rest.getWebhookWithToken(webhook.id, webhook.token!)
|
||||
// expect(webhook.id).to.equal(fetched2.id)
|
||||
// const edited = await rest.editWebhook(webhook.id, {
|
||||
// name: 'edited',
|
||||
// })
|
||||
// expect(webhook.name).to.not.equal(edited.name)
|
||||
// const edited2 = await rest.editWebhookWithToken(webhook.id, webhook.token!, {
|
||||
// name: 'editedtoken',
|
||||
// })
|
||||
// expect(edited.name).to.not.equal(edited2.name)
|
||||
// await rest.createWebhook(channel.id, { name: 'idkk' })
|
||||
// const hooks = await rest.getChannelWebhooks(channel.id)
|
||||
// expect(hooks.length).to.greaterThan(1)
|
||||
// const guildHooks = await rest.getGuildWebhooks(channel.guildId!)
|
||||
// expect(guildHooks.length).to.greaterThan(1)
|
||||
// await rest.deleteWebhook(webhook.id)
|
||||
// // Fetch the webhook to validate it was deleted
|
||||
// await expect(rest.getWebhook(webhook.id)).to.eventually.rejected
|
||||
// const hookToDelete = await rest.createWebhook(channel.id, {
|
||||
// name: 'delme',
|
||||
// })
|
||||
// expect(hookToDelete?.id).to.exist
|
||||
// expect(hookToDelete.token).to.exist
|
||||
// await rest.deleteWebhookWithToken(hookToDelete.id, hookToDelete.token!)
|
||||
// // Fetch the webhook to validate it was deleted
|
||||
// await expect(rest.getWebhook(hookToDelete.id)).to.eventually.rejected
|
||||
it('Manage webhooks', async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
name: 'wbhook',
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the channel after the tests
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
|
||||
const webhook = await rest.createWebhook(channel.id, {
|
||||
name: 'idk',
|
||||
})
|
||||
expect(webhook).to.exist
|
||||
expect(webhook.name).to.equal('idk')
|
||||
expect(webhook.token).to.exist
|
||||
const fetched = await rest.getWebhook(webhook.id)
|
||||
expect(fetched).to.exist
|
||||
expect(webhook.id).to.equal(fetched.id)
|
||||
const fetched2 = await rest.getWebhookWithToken(webhook.id, webhook.token!)
|
||||
expect(webhook.id).to.equal(fetched2.id)
|
||||
const edited = await rest.editWebhook(webhook.id, {
|
||||
name: 'edited',
|
||||
})
|
||||
expect(webhook.name).to.not.equal(edited.name)
|
||||
const edited2 = await rest.editWebhookWithToken(webhook.id, webhook.token!, {
|
||||
name: 'editedtoken',
|
||||
})
|
||||
expect(edited.name).to.not.equal(edited2.name)
|
||||
await rest.createWebhook(channel.id, { name: 'idkk' })
|
||||
const hooks = await rest.getChannelWebhooks(channel.id)
|
||||
expect(hooks.length).to.greaterThan(1)
|
||||
const guildHooks = await rest.getGuildWebhooks(channel.guildId!)
|
||||
expect(guildHooks.length).to.greaterThan(1)
|
||||
await rest.deleteWebhook(webhook.id)
|
||||
// Fetch the webhook to validate it was deleted
|
||||
await expect(rest.getWebhook(webhook.id)).to.eventually.rejected
|
||||
const hookToDelete = await rest.createWebhook(channel.id, {
|
||||
name: 'delme',
|
||||
})
|
||||
expect(hookToDelete?.id).to.exist
|
||||
expect(hookToDelete.token).to.exist
|
||||
await rest.deleteWebhookWithToken(hookToDelete.id, hookToDelete.token!)
|
||||
// Fetch the webhook to validate it was deleted
|
||||
await expect(rest.getWebhook(hookToDelete.id)).to.eventually.rejected
|
||||
})
|
||||
|
||||
it.skip('Manage webhook messages', async () => {
|
||||
// const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
// name: 'wbhook',
|
||||
// })
|
||||
// const webhook = await rest.createWebhook(channel.id, {
|
||||
// name: 'idk',
|
||||
// })
|
||||
// expect(webhook).to.exist
|
||||
// const message = await rest.executeWebhook(webhook.id, webhook.token!, {
|
||||
// content: 'discordeno is best lib',
|
||||
// wait: true,
|
||||
// })
|
||||
// expect(message?.id).to.exist
|
||||
// const message2 = await rest.getWebhookMessage(webhook.id, webhook.token!, message!.id)
|
||||
// expect(message2).to.exist
|
||||
// expect(message2.content).to.equal(message?.content)
|
||||
// const edited3 = await rest.editWebhookMessage(webhook.id, webhook.token!, message!.id, {
|
||||
// content: 'different',
|
||||
// })
|
||||
// expect(edited3).to.exist
|
||||
// expect(edited3.content).to.not.equal(message2.content)
|
||||
// await rest.deleteWebhookMessage(webhook.id, webhook.token!, message!.id)
|
||||
// await expect(rest.getWebhookMessage(webhook.id, webhook.token!, message!.id)).to.eventually.rejected
|
||||
it('Manage webhook messages', async () => {
|
||||
const channel = await rest.createChannel(e2eCache.guild.id, {
|
||||
name: 'wbhook',
|
||||
})
|
||||
after(async () => {
|
||||
// Clean up the channel after the tests
|
||||
await rest.deleteChannel(channel.id)
|
||||
})
|
||||
const webhook = await rest.createWebhook(channel.id, {
|
||||
name: 'idk',
|
||||
})
|
||||
expect(webhook).to.exist
|
||||
const message = await rest.executeWebhook(webhook.id, webhook.token!, {
|
||||
content: 'discordeno is best lib',
|
||||
wait: true,
|
||||
})
|
||||
expect(message?.id).to.exist
|
||||
const message2 = await rest.getWebhookMessage(webhook.id, webhook.token!, message!.id)
|
||||
expect(message2).to.exist
|
||||
expect(message2.content).to.equal(message?.content)
|
||||
const edited3 = await rest.editWebhookMessage(webhook.id, webhook.token!, message!.id, {
|
||||
content: 'different',
|
||||
})
|
||||
expect(edited3).to.exist
|
||||
expect(edited3.content).to.not.equal(message2.content)
|
||||
await rest.deleteWebhookMessage(webhook.id, webhook.token!, message!.id)
|
||||
await expect(rest.getWebhookMessage(webhook.id, webhook.token!, message!.id)).to.eventually.rejected
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user