integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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 4m51s
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:
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { DatabaseTestContext, DriverData } from '../DatabaseTestContext';
|
||||
|
||||
describe('Database Constraints - Foreign Key Constraint Violations', () => {
|
||||
let context: DatabaseTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = DatabaseTestContext.create();
|
||||
});
|
||||
|
||||
it('should handle non-existent driver in team creation', async () => {
|
||||
// Given: No driver exists with the given ID
|
||||
// When: Attempt to create a team with non-existent owner
|
||||
const result = await context.createTeamUseCase.execute({
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
description: 'A test team',
|
||||
ownerId: 'non-existent-driver',
|
||||
leagues: [],
|
||||
});
|
||||
|
||||
// Then: Should fail with appropriate error
|
||||
expect(result.isErr()).toBe(true);
|
||||
if (result.isErr()) {
|
||||
expect(result.error.code).toBe('VALIDATION_ERROR');
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle non-existent team in join request', async () => {
|
||||
// Given: A driver exists
|
||||
const driver: DriverData = {
|
||||
id: 'driver-123',
|
||||
iracingId: '12345',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
joinedAt: new Date(),
|
||||
};
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
// When: Attempt to join non-existent team
|
||||
const result = await context.joinTeamUseCase.execute({
|
||||
teamId: 'non-existent-team',
|
||||
driverId: driver.id,
|
||||
});
|
||||
|
||||
// Then: Should fail with appropriate error
|
||||
expect(result.isErr()).toBe(true);
|
||||
if (result.isErr()) {
|
||||
expect(result.error.code).toBe('TEAM_NOT_FOUND');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { DatabaseTestContext, DriverData } from '../DatabaseTestContext';
|
||||
|
||||
describe('Database Constraints - Unique Constraint Violations', () => {
|
||||
let context: DatabaseTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = DatabaseTestContext.create();
|
||||
});
|
||||
|
||||
it('should handle duplicate team creation gracefully', async () => {
|
||||
// Given: A driver exists
|
||||
const driver: DriverData = {
|
||||
id: 'driver-123',
|
||||
iracingId: '12345',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
joinedAt: new Date(),
|
||||
};
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
// And: A team is created successfully
|
||||
const teamResult1 = await context.createTeamUseCase.execute({
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
description: 'A test team',
|
||||
ownerId: driver.id,
|
||||
leagues: [],
|
||||
});
|
||||
expect(teamResult1.isOk()).toBe(true);
|
||||
|
||||
// When: Attempt to create the same team again (same name/tag)
|
||||
const teamResult2 = await context.createTeamUseCase.execute({
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
description: 'Another test team',
|
||||
ownerId: driver.id,
|
||||
leagues: [],
|
||||
});
|
||||
|
||||
// Then: Should fail with appropriate error
|
||||
expect(teamResult2.isErr()).toBe(true);
|
||||
if (teamResult2.isErr()) {
|
||||
expect(teamResult2.error.code).toBe('VALIDATION_ERROR');
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle duplicate membership gracefully', async () => {
|
||||
// Given: A driver and team exist
|
||||
const driver: DriverData = {
|
||||
id: 'driver-123',
|
||||
iracingId: '12345',
|
||||
name: 'Test Driver',
|
||||
country: 'US',
|
||||
joinedAt: new Date(),
|
||||
};
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const team = {
|
||||
id: 'team-123',
|
||||
name: 'Test Team',
|
||||
tag: 'TT',
|
||||
description: 'A test team',
|
||||
ownerId: 'other-driver',
|
||||
leagues: [],
|
||||
isRecruiting: false,
|
||||
createdAt: new Date(),
|
||||
};
|
||||
await context.teamRepository.create(team);
|
||||
|
||||
// And: Driver joins the team successfully
|
||||
const joinResult1 = await context.joinTeamUseCase.execute({
|
||||
teamId: team.id,
|
||||
driverId: driver.id,
|
||||
});
|
||||
expect(joinResult1.isOk()).toBe(true);
|
||||
|
||||
// When: Driver attempts to join the same team again
|
||||
const joinResult2 = await context.joinTeamUseCase.execute({
|
||||
teamId: team.id,
|
||||
driverId: driver.id,
|
||||
});
|
||||
|
||||
// Then: Should fail with appropriate error
|
||||
expect(joinResult2.isErr()).toBe(true);
|
||||
if (joinResult2.isErr()) {
|
||||
expect(joinResult2.error.code).toBe('ALREADY_MEMBER');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user