integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
103
tests/integration/teams/admin/update-team.test.ts
Normal file
103
tests/integration/teams/admin/update-team.test.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { TeamsTestContext } from '../TeamsTestContext';
|
||||
import { Team } from '../../../../core/racing/domain/entities/Team';
|
||||
|
||||
describe('UpdateTeamUseCase', () => {
|
||||
const context = new TeamsTestContext();
|
||||
const updateTeamUseCase = context.createUpdateTeamUseCase();
|
||||
|
||||
beforeEach(() => {
|
||||
context.clear();
|
||||
});
|
||||
|
||||
describe('Success Path', () => {
|
||||
it('should update team details when called by owner', async () => {
|
||||
const teamId = 't1';
|
||||
const ownerId = 'o1';
|
||||
const team = Team.create({ id: teamId, name: 'Old Name', tag: 'OLD', description: 'Old Desc', ownerId, leagues: [] });
|
||||
await context.teamRepository.create(team);
|
||||
|
||||
await context.membershipRepository.saveMembership({
|
||||
teamId,
|
||||
driverId: ownerId,
|
||||
role: 'owner',
|
||||
status: 'active',
|
||||
joinedAt: new Date()
|
||||
});
|
||||
|
||||
const result = await updateTeamUseCase.execute({
|
||||
teamId,
|
||||
updatedBy: ownerId,
|
||||
updates: {
|
||||
name: 'New Name',
|
||||
tag: 'NEW',
|
||||
description: 'New Desc'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const { team: updatedTeam } = result.unwrap();
|
||||
expect(updatedTeam.name.toString()).toBe('New Name');
|
||||
expect(updatedTeam.tag.toString()).toBe('NEW');
|
||||
expect(updatedTeam.description.toString()).toBe('New Desc');
|
||||
|
||||
const savedTeam = await context.teamRepository.findById(teamId);
|
||||
expect(savedTeam?.name.toString()).toBe('New Name');
|
||||
});
|
||||
|
||||
it('should update team details when called by manager', async () => {
|
||||
const teamId = 't2';
|
||||
const managerId = 'm2';
|
||||
const team = Team.create({ id: teamId, name: 'Team 2', tag: 'T2', description: 'Desc', ownerId: 'owner', leagues: [] });
|
||||
await context.teamRepository.create(team);
|
||||
|
||||
await context.membershipRepository.saveMembership({
|
||||
teamId,
|
||||
driverId: managerId,
|
||||
role: 'manager',
|
||||
status: 'active',
|
||||
joinedAt: new Date()
|
||||
});
|
||||
|
||||
const result = await updateTeamUseCase.execute({
|
||||
teamId,
|
||||
updatedBy: managerId,
|
||||
updates: {
|
||||
name: 'Updated by Manager'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const { team: updatedTeam } = result.unwrap();
|
||||
expect(updatedTeam.name.toString()).toBe('Updated by Manager');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Validation', () => {
|
||||
it('should reject update when called by regular member', async () => {
|
||||
const teamId = 't3';
|
||||
const memberId = 'd3';
|
||||
const team = Team.create({ id: teamId, name: 'Team 3', tag: 'T3', description: 'Desc', ownerId: 'owner', leagues: [] });
|
||||
await context.teamRepository.create(team);
|
||||
|
||||
await context.membershipRepository.saveMembership({
|
||||
teamId,
|
||||
driverId: memberId,
|
||||
role: 'driver',
|
||||
status: 'active',
|
||||
joinedAt: new Date()
|
||||
});
|
||||
|
||||
const result = await updateTeamUseCase.execute({
|
||||
teamId,
|
||||
updatedBy: memberId,
|
||||
updates: {
|
||||
name: 'Unauthorized Update'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('PERMISSION_DENIED');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user