import { describe, it, expect, beforeEach } from '@jest/globals';
import { DiscordWebhookClient } from '../../src/discord/webhook.js';
import { sendEmbed } from '../../src/tools/send-embed.js';
import { ValidationError } from '../../src/utils/errors.js';
// Mock fetch
global.fetch = ((_input: string | URL | Request, _options?: RequestInit) => {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve({
id: '123456789',
type: 0,
channel_id: '987654321',
author: {
id: '111222333',
username: 'TestBot',
avatar: null,
discriminator: '0000',
bot: true,
},
}),
} as Response);
}) as typeof fetch;
describe('sendEmbed Tool', () => {
let client: DiscordWebhookClient;
beforeEach(() => {
client = new DiscordWebhookClient(
'https://discord.com/api/webhooks/123/abc'
);
});
it('should send embed with title and description', async () => {
const result = await sendEmbed(client, {
title: 'Test Title',
description: 'Test Description',
});
expect(result).toContain('Embed sent successfully');
});
it('should send embed with all features', async () => {
const result = await sendEmbed(client, {
title: 'Complete Embed',
description: 'Full featured embed',
color: 'blue',
timestamp: true,
footer_text: 'Footer',
author_name: 'Author',
thumbnail_url: 'https://example.com/thumb.png',
image_url: 'https://example.com/image.png',
});
expect(result).toContain('successfully');
});
it('should throw error when no content provided', async () => {
await expect(sendEmbed(client, {})).rejects.toThrow(ValidationError);
});
it('should send embed with content message', async () => {
const result = await sendEmbed(client, {
content: 'Check this out!',
title: 'Embed Title',
});
expect(result).toContain('successfully');
});
});