website refactor
This commit is contained in:
@@ -19,8 +19,7 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
findById: Mock;
|
||||
update: Mock;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
leagueRepository = {
|
||||
findById: vi.fn(),
|
||||
@@ -29,11 +28,10 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
findById: vi.fn(),
|
||||
update: vi.fn(),
|
||||
};
|
||||
};
|
||||
useCase = new ManageSeasonLifecycleUseCase(leagueRepository as unknown as ILeagueRepository,
|
||||
seasonRepository as unknown as ISeasonRepository);
|
||||
useCase = new ManageSeasonLifecycleUseCase(leagueRepository as any,
|
||||
seasonRepository as any);
|
||||
});
|
||||
|
||||
|
||||
it('applies activate → complete → archive transitions and persists state', async () => {
|
||||
const league = { id: 'league-1' };
|
||||
let currentSeason = Season.create({
|
||||
@@ -43,57 +41,48 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
name: 'Lifecycle Season',
|
||||
status: 'planned',
|
||||
});
|
||||
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findById.mockImplementation(() => Promise.resolve(currentSeason));
|
||||
seasonRepository.update.mockImplementation((s) => {
|
||||
currentSeason = s;
|
||||
return Promise.resolve(s);
|
||||
});
|
||||
|
||||
|
||||
const activateInput: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: currentSeason.id,
|
||||
transition: 'activate',
|
||||
};
|
||||
|
||||
|
||||
const activated = await useCase.execute(activateInput);
|
||||
expect(activated.isOk()).toBe(true);
|
||||
expect(activated.unwrap()).toBeUndefined();
|
||||
const [firstCall] = const [firstArg] = firstCall as [ManageSeasonLifecycleResult];
|
||||
let presented = firstArg;
|
||||
let presented = activated.unwrap();
|
||||
expect(presented.season.status.toString()).toBe('active');
|
||||
|
||||
(const completeInput: ManageSeasonLifecycleInput = {
|
||||
|
||||
const completeInput: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: currentSeason.id,
|
||||
transition: 'complete',
|
||||
};
|
||||
|
||||
|
||||
const completed = await useCase.execute(completeInput);
|
||||
expect(completed.isOk()).toBe(true);
|
||||
expect(completed.unwrap()).toBeUndefined();
|
||||
{
|
||||
const [[arg]] = presented = arg;
|
||||
}
|
||||
presented = completed.unwrap();
|
||||
expect(presented.season.status.toString()).toBe('completed');
|
||||
|
||||
(const archiveInput: ManageSeasonLifecycleInput = {
|
||||
|
||||
const archiveInput: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: currentSeason.id,
|
||||
transition: 'archive',
|
||||
};
|
||||
|
||||
|
||||
const archived = await useCase.execute(archiveInput);
|
||||
expect(archived.isOk()).toBe(true);
|
||||
expect(archived.unwrap()).toBeUndefined();
|
||||
{
|
||||
const presentedRaw = expect(presentedRaw).toBeDefined();
|
||||
presented = presentedRaw as ManageSeasonLifecycleResult;
|
||||
}
|
||||
presented = archived.unwrap();
|
||||
expect(presented.season.status.toString()).toBe('archived');
|
||||
});
|
||||
|
||||
|
||||
it('propagates domain invariant errors for invalid transitions', async () => {
|
||||
const league = { id: 'league-1' };
|
||||
const season = Season.create({
|
||||
@@ -103,16 +92,16 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
name: 'Lifecycle Season',
|
||||
status: 'planned',
|
||||
});
|
||||
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findById.mockResolvedValue(season);
|
||||
|
||||
|
||||
const completeInput: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: season.id,
|
||||
transition: 'complete',
|
||||
};
|
||||
|
||||
|
||||
const result = await useCase.execute(completeInput);
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr() as ApplicationErrorCode<
|
||||
@@ -120,17 +109,17 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
{ message: string }
|
||||
>;
|
||||
expect(error.code).toEqual('INVALID_TRANSITION');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('returns error when league not found', async () => {
|
||||
leagueRepository.findById.mockResolvedValue(null);
|
||||
|
||||
|
||||
const input: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: 'season-1',
|
||||
transition: 'activate',
|
||||
};
|
||||
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr() as ApplicationErrorCode<
|
||||
@@ -139,19 +128,19 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
>;
|
||||
expect(error.code).toEqual('LEAGUE_NOT_FOUND');
|
||||
expect(error.details).toEqual({ message: 'League not found: league-1' });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('returns error when season not found', async () => {
|
||||
const league = { id: 'league-1' };
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findById.mockResolvedValue(null);
|
||||
|
||||
|
||||
const input: ManageSeasonLifecycleInput = {
|
||||
leagueId: 'league-1',
|
||||
seasonId: 'season-1',
|
||||
transition: 'activate',
|
||||
};
|
||||
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr() as ApplicationErrorCode<
|
||||
@@ -162,5 +151,5 @@ describe('ManageSeasonLifecycleUseCase', () => {
|
||||
expect(error.details).toEqual({
|
||||
message: 'Season season-1 does not belong to league league-1',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user