resolve todos in website
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, vi, type Mock } from 'vitest';
|
||||
import { CreateAchievementUseCase, type IAchievementRepository } from './CreateAchievementUseCase';
|
||||
import { Achievement } from '@core/identity/domain/entities/Achievement';
|
||||
|
||||
describe('CreateAchievementUseCase', () => {
|
||||
let achievementRepository: {
|
||||
save: Mock;
|
||||
findById: Mock;
|
||||
};
|
||||
let useCase: CreateAchievementUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
achievementRepository = {
|
||||
save: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new CreateAchievementUseCase(achievementRepository as unknown as IAchievementRepository);
|
||||
});
|
||||
|
||||
it('creates an achievement and persists it', async () => {
|
||||
const props = {
|
||||
id: 'achv-1',
|
||||
name: 'First Win',
|
||||
description: 'Awarded for winning your first race',
|
||||
category: 'driver' as const,
|
||||
rarity: 'common' as const,
|
||||
iconUrl: 'https://example.com/icon.png',
|
||||
points: 50,
|
||||
requirements: [
|
||||
{
|
||||
type: 'wins',
|
||||
value: 1,
|
||||
operator: '>=',
|
||||
},
|
||||
],
|
||||
isSecret: false,
|
||||
};
|
||||
|
||||
achievementRepository.save.mockResolvedValue(undefined);
|
||||
|
||||
const result = await useCase.execute(props);
|
||||
|
||||
expect(result).toBeInstanceOf(Achievement);
|
||||
expect(result.id).toBe(props.id);
|
||||
expect(result.name).toBe(props.name);
|
||||
expect(result.description).toBe(props.description);
|
||||
expect(result.category).toBe(props.category);
|
||||
expect(result.points).toBe(props.points);
|
||||
expect(result.requirements).toHaveLength(1);
|
||||
expect(achievementRepository.save).toHaveBeenCalledWith(result);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user