Files
gridpilot.gg/adapters/notifications/gateways/InAppNotificationGateway.test.ts
Marc Mintel cfc30c79a8
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
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
code quality
2026-01-26 12:52:24 +01:00

58 lines
1.7 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { InAppNotificationAdapter } from './InAppNotificationGateway';
import { Notification } from '@core/notifications/domain/entities/Notification';
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
describe('InAppNotificationAdapter', () => {
let adapter: InAppNotificationAdapter;
beforeEach(() => {
adapter = new InAppNotificationAdapter();
vi.spyOn(console, 'log').mockImplementation(() => {});
});
const createNotification = (overrides: Partial<Parameters<typeof Notification.create>[0]> = {}) => {
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: 'in_app',
...overrides,
});
};
describe('send', () => {
it('should return success', async () => {
// Given
const notification = createNotification();
// When
const result = await adapter.send(notification);
// Then
expect(result.success).toBe(true);
expect(result.channel).toBe('in_app');
expect(result.externalId).toBe('notif-123');
expect(result.attemptedAt).toBeInstanceOf(Date);
});
});
describe('supportsChannel', () => {
it('should return true for in_app channel', () => {
expect(adapter.supportsChannel('in_app')).toBe(true);
});
it('should return false for other channels', () => {
expect(adapter.supportsChannel('email' as any)).toBe(false);
});
});
describe('isConfigured', () => {
it('should always return true', () => {
expect(adapter.isConfigured()).toBe(true);
});
});
});