code quality
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

This commit is contained in:
2026-01-26 12:52:24 +01:00
parent f877f821ef
commit cfc30c79a8
62 changed files with 227 additions and 173 deletions

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { DiscordNotificationAdapter } from './DiscordNotificationGateway';
import { Notification } from '@core/notifications/domain/entities/Notification';
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
describe('DiscordNotificationAdapter', () => {
const webhookUrl = 'https://discord.com/api/webhooks/123/abc';
@@ -11,7 +12,7 @@ describe('DiscordNotificationAdapter', () => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
const createNotification = (overrides: any = {}) => {
const createNotification = (overrides: Partial<Parameters<typeof Notification.create>[0]> = {}) => {
return Notification.create({
id: 'notif-123',
recipientId: 'driver-456',
@@ -58,7 +59,7 @@ describe('DiscordNotificationAdapter', () => {
});
it('should return false for other channels', () => {
expect(adapter.supportsChannel('email' as any)).toBe(false);
expect(adapter.supportsChannel('email' as unknown as NotificationChannel)).toBe(false);
});
});

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { EmailNotificationAdapter } from './EmailNotificationGateway';
import { Notification } from '@core/notifications/domain/entities/Notification';
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
describe('EmailNotificationAdapter', () => {
const config = {
@@ -14,7 +15,7 @@ describe('EmailNotificationAdapter', () => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
const createNotification = (overrides: any = {}) => {
const createNotification = (overrides: Partial<Parameters<typeof Notification.create>[0]> = {}) => {
return Notification.create({
id: 'notif-123',
recipientId: 'driver-456',

View File

@@ -1,6 +1,7 @@
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;
@@ -10,7 +11,7 @@ describe('InAppNotificationAdapter', () => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
const createNotification = (overrides: any = {}) => {
const createNotification = (overrides: Partial<Parameters<typeof Notification.create>[0]> = {}) => {
return Notification.create({
id: 'notif-123',
recipientId: 'driver-456',

View File

@@ -2,7 +2,6 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
import { NotificationGatewayRegistry } from './NotificationGatewayRegistry';
import { Notification } from '@core/notifications/domain/entities/Notification';
import type { NotificationGateway, NotificationDeliveryResult } from '@core/notifications/application/ports/NotificationGateway';
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
describe('NotificationGatewayRegistry', () => {
let registry: NotificationGatewayRegistry;
@@ -18,7 +17,7 @@ describe('NotificationGatewayRegistry', () => {
registry = new NotificationGatewayRegistry([mockGateway]);
});
const createNotification = (overrides: any = {}) => {
const createNotification = (overrides: Partial<Parameters<typeof Notification.create>[0]> = {}) => {
return Notification.create({
id: 'notif-123',
recipientId: 'driver-456',
@@ -35,7 +34,7 @@ describe('NotificationGatewayRegistry', () => {
const discordGateway = {
...mockGateway,
getChannel: vi.fn().mockReturnValue('discord'),
} as any;
} as unknown as NotificationGateway;
registry.register(discordGateway);
expect(registry.getGateway('discord')).toBe(discordGateway);

View File

@@ -1,4 +1,5 @@
import { Notification } from '@core/notifications/domain/entities/Notification';
import { Notification, type NotificationStatus, type NotificationUrgency } from '@core/notifications/domain/entities/Notification';
import type { NotificationChannel, NotificationType } from '@core/notifications/domain/types/NotificationTypes';
import { NotificationOrmEntity } from '../entities/NotificationOrmEntity';
import { TypeOrmPersistenceSchemaError } from '../errors/TypeOrmPersistenceSchemaError';
import {
@@ -44,40 +45,40 @@ export class NotificationOrmMapper {
}
try {
const domainProps: any = {
const domainProps = {
id: entity.id,
recipientId: entity.recipientId,
type: entity.type,
type: entity.type as NotificationType,
title: entity.title,
body: entity.body,
channel: entity.channel,
status: entity.status,
urgency: entity.urgency,
channel: entity.channel as NotificationChannel,
status: entity.status as NotificationStatus,
urgency: entity.urgency as NotificationUrgency,
createdAt: entity.createdAt,
requiresResponse: entity.requiresResponse,
};
if (entity.data !== null && entity.data !== undefined) {
domainProps.data = entity.data as Record<string, unknown>;
(domainProps as any).data = entity.data;
}
if (entity.actionUrl !== null && entity.actionUrl !== undefined) {
domainProps.actionUrl = entity.actionUrl;
(domainProps as any).actionUrl = entity.actionUrl;
}
if (entity.actions !== null && entity.actions !== undefined) {
domainProps.actions = entity.actions;
(domainProps as any).actions = entity.actions;
}
if (entity.readAt !== null && entity.readAt !== undefined) {
domainProps.readAt = entity.readAt;
(domainProps as any).readAt = entity.readAt;
}
if (entity.respondedAt !== null && entity.respondedAt !== undefined) {
domainProps.respondedAt = entity.respondedAt;
(domainProps as any).respondedAt = entity.respondedAt;
}
return Notification.create(domainProps);
return Notification.create(domainProps as any);
} catch (error) {
const message = error instanceof Error ? error.message : 'Invalid persisted Notification';
throw new TypeOrmPersistenceSchemaError({ entityName, fieldName: 'unknown', reason: 'invalid_shape', message });

View File

@@ -34,7 +34,7 @@ export class NotificationPreferenceOrmMapper {
}
try {
const domainProps: any = {
const domainProps = {
id: entity.id,
driverId: entity.driverId,
channels: entity.channels,
@@ -43,22 +43,22 @@ export class NotificationPreferenceOrmMapper {
};
if (entity.typePreferences !== null && entity.typePreferences !== undefined) {
domainProps.typePreferences = entity.typePreferences;
(domainProps as unknown as { typePreferences: unknown }).typePreferences = entity.typePreferences;
}
if (entity.digestFrequencyHours !== null && entity.digestFrequencyHours !== undefined) {
domainProps.digestFrequencyHours = entity.digestFrequencyHours;
(domainProps as unknown as { digestFrequencyHours: unknown }).digestFrequencyHours = entity.digestFrequencyHours;
}
if (entity.quietHoursStart !== null && entity.quietHoursStart !== undefined) {
domainProps.quietHoursStart = entity.quietHoursStart;
(domainProps as unknown as { quietHoursStart: unknown }).quietHoursStart = entity.quietHoursStart;
}
if (entity.quietHoursEnd !== null && entity.quietHoursEnd !== undefined) {
domainProps.quietHoursEnd = entity.quietHoursEnd;
(domainProps as unknown as { quietHoursEnd: unknown }).quietHoursEnd = entity.quietHoursEnd;
}
return NotificationPreference.create(domainProps);
return NotificationPreference.create(domainProps as unknown as Parameters<typeof NotificationPreference.create>[0]);
} catch (error) {
const message = error instanceof Error ? error.message : 'Invalid persisted NotificationPreference';
throw new TypeOrmPersistenceSchemaError({ entityName, fieldName: 'unknown', reason: 'invalid_shape', message });

View File

@@ -1,4 +1,7 @@
import { describe, expect, it, vi } from 'vitest';
import type { DataSource } from 'typeorm';
import type { NotificationPreference } from '@core/notifications/domain/entities/NotificationPreference';
import type { NotificationPreferenceOrmMapper } from '../mappers/NotificationPreferenceOrmMapper';
import { TypeOrmNotificationPreferenceRepository } from './TypeOrmNotificationPreferenceRepository';
@@ -33,7 +36,7 @@ describe('TypeOrmNotificationPreferenceRepository', () => {
toOrmEntity: vi.fn().mockReturnValue({ id: 'orm-preference-1' }),
};
const repo = new TypeOrmNotificationPreferenceRepository(dataSource as any, mapper as any);
const repo = new TypeOrmNotificationPreferenceRepository(dataSource as unknown as DataSource, mapper as unknown as NotificationPreferenceOrmMapper);
// Test findByDriverId
const preference = await repo.findByDriverId('driver-123');
@@ -43,8 +46,8 @@ describe('TypeOrmNotificationPreferenceRepository', () => {
expect(preference).toEqual({ id: 'domain-preference-1' });
// Test save
const domainPreference = { id: 'driver-123', driverId: 'driver-123', toJSON: () => ({ id: 'driver-123', driverId: 'driver-123' }) };
await repo.save(domainPreference as any);
const domainPreference = { id: 'driver-123', driverId: 'driver-123', toJSON: () => ({ id: 'driver-123', driverId: 'driver-123' }) } as unknown as NotificationPreference;
await repo.save(domainPreference);
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainPreference);
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-preference-1' });

View File

@@ -1,4 +1,6 @@
import { describe, expect, it, vi } from 'vitest';
import type { DataSource } from 'typeorm';
import type { NotificationOrmMapper } from '../mappers/NotificationOrmMapper';
import { TypeOrmNotificationRepository } from './TypeOrmNotificationRepository';
@@ -36,7 +38,7 @@ describe('TypeOrmNotificationRepository', () => {
toOrmEntity: vi.fn().mockReturnValue({ id: 'orm-notification-1' }),
};
const repo = new TypeOrmNotificationRepository(dataSource as any, mapper as any);
const repo = new TypeOrmNotificationRepository(dataSource as unknown as DataSource, mapper as unknown as NotificationOrmMapper);
// Test findById
const notification = await repo.findById('notification-1');
@@ -61,13 +63,13 @@ describe('TypeOrmNotificationRepository', () => {
expect(count).toBe(1);
// Test create
const domainNotification = { id: 'new-notification', toJSON: () => ({ id: 'new-notification' }) };
await repo.create(domainNotification as any);
const domainNotification = { id: 'new-notification', toJSON: () => ({ id: 'new-notification' }) } as unknown as Notification;
await repo.create(domainNotification);
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainNotification);
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-notification-1' });
// Test update
await repo.update(domainNotification as any);
await repo.update(domainNotification);
expect(mapper.toOrmEntity).toHaveBeenCalledWith(domainNotification);
expect(ormRepo.save).toHaveBeenCalledWith({ id: 'orm-notification-1' });