62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { Achievement } from '@core/identity/domain/entities/Achievement';
|
|
|
|
describe('Achievement', () => {
|
|
const baseProps = () => ({
|
|
id: 'ach-1',
|
|
name: 'First Win',
|
|
description: 'Win your first race',
|
|
category: 'driver' as const,
|
|
rarity: 'common' as const,
|
|
points: 10,
|
|
requirements: [{ type: 'wins' as const, value: 1, operator: '>=' as const }],
|
|
isSecret: false,
|
|
});
|
|
|
|
it('creates an Achievement with default iconUrl', () => {
|
|
const a = Achievement.create(baseProps());
|
|
|
|
expect(a.id).toBe('ach-1');
|
|
expect(a.iconUrl).toBe('');
|
|
expect(a.createdAt).toBeInstanceOf(Date);
|
|
});
|
|
|
|
it('throws if id is missing', () => {
|
|
expect(() => Achievement.create({ ...baseProps(), id: '' })).toThrow(Error);
|
|
expect(() => Achievement.create({ ...baseProps(), id: ' ' })).toThrow(Error);
|
|
});
|
|
|
|
it('throws if name is missing', () => {
|
|
expect(() => Achievement.create({ ...baseProps(), name: '' })).toThrow(Error);
|
|
expect(() => Achievement.create({ ...baseProps(), name: ' ' })).toThrow(Error);
|
|
});
|
|
|
|
it('throws if requirements is empty', () => {
|
|
expect(() => Achievement.create({ ...baseProps(), requirements: [] })).toThrow(Error);
|
|
});
|
|
|
|
it('checkRequirements evaluates all requirements', () => {
|
|
const a = Achievement.create({
|
|
...baseProps(),
|
|
requirements: [
|
|
{ type: 'wins', value: 2, operator: '>=' },
|
|
{ type: 'podiums', value: 1, operator: '>=' },
|
|
],
|
|
});
|
|
|
|
expect(a.checkRequirements({ wins: 2, podiums: 1 })).toBe(true);
|
|
expect(a.checkRequirements({ wins: 1, podiums: 1 })).toBe(false);
|
|
expect(a.checkRequirements({ wins: 2 })).toBe(false);
|
|
});
|
|
|
|
it('getRarityColor returns the configured color', () => {
|
|
expect(Achievement.create({ ...baseProps(), rarity: 'common' }).getRarityColor()).toBe('#9CA3AF');
|
|
expect(Achievement.create({ ...baseProps(), rarity: 'legendary' }).getRarityColor()).toBe('#F59E0B');
|
|
});
|
|
|
|
it('hides name/description when secret', () => {
|
|
const a = Achievement.create({ ...baseProps(), isSecret: true });
|
|
|
|
expect(a.getDisplayName()).toBe('???');
|
|
expect(a.getDisplayDescription()).toContain('secret');
|
|
});
|
|
}); |