56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
|
import { GetLeagueOwnerSummaryUseCase } from './GetLeagueOwnerSummaryUseCase';
|
|
import { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
|
import { Driver } from '../../domain/entities/Driver';
|
|
|
|
describe('GetLeagueOwnerSummaryUseCase', () => {
|
|
let useCase: GetLeagueOwnerSummaryUseCase;
|
|
let driverRepository: {
|
|
findById: Mock;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
driverRepository = {
|
|
findById: vi.fn(),
|
|
};
|
|
useCase = new GetLeagueOwnerSummaryUseCase(
|
|
driverRepository as unknown as IDriverRepository,
|
|
);
|
|
});
|
|
|
|
it('should return owner summary when driver exists', async () => {
|
|
const ownerId = 'owner-1';
|
|
const driver = Driver.create({
|
|
id: ownerId,
|
|
iracingId: '123',
|
|
name: 'Owner Name',
|
|
country: 'US',
|
|
});
|
|
|
|
driverRepository.findById.mockResolvedValue(driver);
|
|
|
|
const result = await useCase.execute({ ownerId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
expect(result.unwrap()).toEqual({
|
|
summary: {
|
|
driver: { id: ownerId, name: 'Owner Name' },
|
|
rating: 0,
|
|
rank: 0,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should return null summary when driver does not exist', async () => {
|
|
const ownerId = 'owner-1';
|
|
|
|
driverRepository.findById.mockResolvedValue(null);
|
|
|
|
const result = await useCase.execute({ ownerId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
expect(result.unwrap()).toEqual({
|
|
summary: null,
|
|
});
|
|
});
|
|
}); |