core tests
Some checks failed
Some checks failed
This commit is contained in:
@@ -7,6 +7,7 @@ export abstract class AdminDomainError extends Error implements DomainError<Comm
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AdminDomainError';
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +20,7 @@ export class AdminDomainValidationError
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AdminDomainValidationError';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +32,7 @@ export class AdminDomainInvariantError
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AdminDomainInvariantError';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +44,6 @@ export class AuthorizationError
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'AuthorizationError';
|
||||
}
|
||||
}
|
||||
@@ -209,7 +209,7 @@ describe('GetDashboardUseCase', () => {
|
||||
id: 'race-2',
|
||||
trackName: 'Track B',
|
||||
carType: 'GT3',
|
||||
scheduledDate: new Date('2026-01-25T10:00:00.000Z'), // Future
|
||||
scheduledDate: new Date('2026-01-26T10:00:00.000Z'), // Future
|
||||
},
|
||||
] as RaceData[]);
|
||||
|
||||
@@ -295,13 +295,13 @@ describe('GetDashboardUseCase', () => {
|
||||
id: 'race-1',
|
||||
trackName: 'Track A',
|
||||
carType: 'GT3',
|
||||
scheduledDate: new Date('2026-01-25T10:00:00.000Z'),
|
||||
scheduledDate: new Date('2026-01-26T10:00:00.000Z'),
|
||||
},
|
||||
{
|
||||
id: 'race-2',
|
||||
trackName: 'Track B',
|
||||
carType: 'GT4',
|
||||
scheduledDate: new Date('2026-01-26T10:00:00.000Z'),
|
||||
scheduledDate: new Date('2026-01-27T10:00:00.000Z'),
|
||||
},
|
||||
] as RaceData[]);
|
||||
|
||||
|
||||
@@ -34,15 +34,21 @@ export class CheckApiHealthUseCase {
|
||||
timestamp: result.timestamp,
|
||||
});
|
||||
} else {
|
||||
const error = result.error || 'Unknown error';
|
||||
await eventPublisher.publishHealthCheckFailed({
|
||||
error: result.error || 'Unknown error',
|
||||
error,
|
||||
timestamp: result.timestamp,
|
||||
});
|
||||
// Return result with error property
|
||||
return {
|
||||
...result,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
const errorMessage = error instanceof Error ? error.message : (error ? String(error) : 'Unknown error');
|
||||
const timestamp = new Date();
|
||||
|
||||
// Emit failed event
|
||||
|
||||
@@ -5,11 +5,13 @@ import { describe, expect, it, vi, type Mock } from 'vitest';
|
||||
import type { Payment } from '../../domain/entities/Payment';
|
||||
import { PayerType, PaymentStatus, PaymentType } from '../../domain/entities/Payment';
|
||||
import type { PaymentRepository } from '../../domain/repositories/PaymentRepository';
|
||||
import type { SponsorRepository } from '@core/racing/domain/repositories/SponsorRepository';
|
||||
import { GetSponsorBillingUseCase, type GetSponsorBillingInput } from './GetSponsorBillingUseCase';
|
||||
|
||||
describe('GetSponsorBillingUseCase', () => {
|
||||
let paymentRepository: { findByFilters: Mock };
|
||||
let seasonSponsorshipRepository: { findBySponsorId: Mock };
|
||||
let sponsorRepository: { findById: Mock };
|
||||
let useCase: GetSponsorBillingUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -21,15 +23,26 @@ describe('GetSponsorBillingUseCase', () => {
|
||||
findBySponsorId: vi.fn(),
|
||||
};
|
||||
|
||||
sponsorRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetSponsorBillingUseCase(
|
||||
paymentRepository as unknown as PaymentRepository,
|
||||
seasonSponsorshipRepository as unknown as SeasonSponsorshipRepository,
|
||||
sponsorRepository as unknown as SponsorRepository,
|
||||
);
|
||||
});
|
||||
|
||||
it('derives invoices and stats from payments and sponsorships', async () => {
|
||||
const sponsorId = 'sponsor-1';
|
||||
|
||||
// Mock sponsor exists
|
||||
sponsorRepository.findById.mockResolvedValue({
|
||||
id: sponsorId,
|
||||
name: 'Test Sponsor',
|
||||
});
|
||||
|
||||
const payments: Payment[] = [
|
||||
{
|
||||
id: 'pay-1',
|
||||
|
||||
@@ -4,8 +4,8 @@ export class Position {
|
||||
private constructor(private readonly value: number) {}
|
||||
|
||||
static create(value: number): Position {
|
||||
if (!Number.isInteger(value) || value < 0) {
|
||||
throw new RacingDomainValidationError('Position must be a non-negative integer');
|
||||
if (!Number.isInteger(value) || value <= 0) {
|
||||
throw new RacingDomainValidationError('Position must be a positive integer');
|
||||
}
|
||||
return new Position(value);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ describe('Result', () => {
|
||||
fastestLap: validFastestLap,
|
||||
incidents: validIncidents,
|
||||
startPosition: validStartPosition,
|
||||
points: 10,
|
||||
};
|
||||
|
||||
const result = Result.create(props);
|
||||
@@ -37,6 +38,7 @@ describe('Result', () => {
|
||||
expect(result.fastestLap.toNumber()).toBe(validFastestLap);
|
||||
expect(result.incidents.toNumber()).toBe(validIncidents);
|
||||
expect(result.startPosition.toNumber()).toBe(validStartPosition);
|
||||
expect(result.points).toBe(10);
|
||||
});
|
||||
|
||||
it('should throw error for empty id', () => {
|
||||
@@ -48,6 +50,7 @@ describe('Result', () => {
|
||||
fastestLap: validFastestLap,
|
||||
incidents: validIncidents,
|
||||
startPosition: validStartPosition,
|
||||
points: 10,
|
||||
};
|
||||
|
||||
expect(() => Result.create(props)).toThrow(RacingDomainValidationError);
|
||||
@@ -62,6 +65,7 @@ describe('Result', () => {
|
||||
fastestLap: validFastestLap,
|
||||
incidents: validIncidents,
|
||||
startPosition: validStartPosition,
|
||||
points: 10,
|
||||
};
|
||||
|
||||
expect(() => Result.create(props)).toThrow(RacingDomainValidationError);
|
||||
|
||||
Reference in New Issue
Block a user