adapter tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { DiscordNotificationAdapter } from './DiscordNotificationGateway';
|
||||
import { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
|
||||
describe('DiscordNotificationAdapter', () => {
|
||||
const webhookUrl = 'https://discord.com/api/webhooks/123/abc';
|
||||
let adapter: DiscordNotificationAdapter;
|
||||
|
||||
beforeEach(() => {
|
||||
adapter = new DiscordNotificationAdapter({ webhookUrl });
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
const createNotification = (overrides: any = {}) => {
|
||||
return Notification.create({
|
||||
id: 'notif-123',
|
||||
recipientId: 'driver-456',
|
||||
type: 'protest_filed',
|
||||
title: 'New Protest',
|
||||
body: 'A new protest has been filed against you.',
|
||||
channel: 'discord',
|
||||
...overrides,
|
||||
});
|
||||
};
|
||||
|
||||
describe('send', () => {
|
||||
it('should return success when configured', async () => {
|
||||
// Given
|
||||
const notification = createNotification();
|
||||
|
||||
// When
|
||||
const result = await adapter.send(notification);
|
||||
|
||||
// Then
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.channel).toBe('discord');
|
||||
expect(result.externalId).toContain('discord-stub-');
|
||||
expect(result.attemptedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('should return failure when not configured', async () => {
|
||||
// Given
|
||||
const unconfiguredAdapter = new DiscordNotificationAdapter();
|
||||
const notification = createNotification();
|
||||
|
||||
// When
|
||||
const result = await unconfiguredAdapter.send(notification);
|
||||
|
||||
// Then
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toBe('Discord webhook URL not configured');
|
||||
});
|
||||
});
|
||||
|
||||
describe('supportsChannel', () => {
|
||||
it('should return true for discord channel', () => {
|
||||
expect(adapter.supportsChannel('discord')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for other channels', () => {
|
||||
expect(adapter.supportsChannel('email' as any)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isConfigured', () => {
|
||||
it('should return true when webhookUrl is set', () => {
|
||||
expect(adapter.isConfigured()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when webhookUrl is missing', () => {
|
||||
const unconfigured = new DiscordNotificationAdapter();
|
||||
expect(unconfigured.isConfigured()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setWebhookUrl', () => {
|
||||
it('should update the webhook URL', () => {
|
||||
const unconfigured = new DiscordNotificationAdapter();
|
||||
unconfigured.setWebhookUrl(webhookUrl);
|
||||
expect(unconfigured.isConfigured()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user