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