mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
* build(deps-dev): bump chai from 4.3.10 to 5.0.0 Bumps [chai](https://github.com/chaijs/chai) from 4.3.10 to 5.0.0. - [Release notes](https://github.com/chaijs/chai/releases) - [Changelog](https://github.com/chaijs/chai/blob/main/History.md) - [Commits](https://github.com/chaijs/chai/compare/v4.3.10...v5.0.0) --- updated-dependencies: - dependency-name: chai dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: chai to v5 * fix: missing chaiuse * fix: missing chai import fix * test: fix add delete guild --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: H01001000 <heiheiho000@gmail.com>
109 lines
3.2 KiB
TypeScript
109 lines
3.2 KiB
TypeScript
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('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 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
|
|
})
|
|
})
|