tests
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { CreateTeamPresenter } from './CreateTeamPresenter';
|
||||
|
||||
describe('CreateTeamPresenter', () => {
|
||||
let presenter: CreateTeamPresenter;
|
||||
|
||||
beforeEach(() => {
|
||||
presenter = new CreateTeamPresenter();
|
||||
});
|
||||
|
||||
describe('present', () => {
|
||||
it('should map result to response model', () => {
|
||||
const result = {
|
||||
team: {
|
||||
id: 'team-123',
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
expect(presenter.responseModel).toEqual({
|
||||
id: 'team-123',
|
||||
success: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle different team IDs', () => {
|
||||
const result = {
|
||||
team: {
|
||||
id: 'team-456',
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
expect(presenter.responseModel).toEqual({
|
||||
id: 'team-456',
|
||||
success: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('should clear the model', () => {
|
||||
presenter.present({ team: { id: 'team-123' } } as any);
|
||||
expect(presenter.responseModel).toBeDefined();
|
||||
|
||||
presenter.reset();
|
||||
expect(presenter.getResponseModel()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getResponseModel', () => {
|
||||
it('should return null before present()', () => {
|
||||
expect(presenter.getResponseModel()).toBeNull();
|
||||
});
|
||||
|
||||
it('should return model after present()', () => {
|
||||
presenter.present({ team: { id: 'team-123' } } as any);
|
||||
expect(presenter.getResponseModel()).toEqual({
|
||||
id: 'team-123',
|
||||
success: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('responseModel', () => {
|
||||
it('should throw error when accessed before present()', () => {
|
||||
expect(() => presenter.responseModel).toThrow('Presenter not presented');
|
||||
});
|
||||
|
||||
it('should return model after present()', () => {
|
||||
presenter.present({ team: { id: 'team-123' } } as any);
|
||||
expect(presenter.responseModel).toEqual({
|
||||
id: 'team-123',
|
||||
success: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
218
apps/api/src/domain/team/presenters/DriverTeamPresenter.test.ts
Normal file
218
apps/api/src/domain/team/presenters/DriverTeamPresenter.test.ts
Normal file
@@ -0,0 +1,218 @@
|
||||
import { DriverTeamPresenter } from './DriverTeamPresenter';
|
||||
|
||||
describe('DriverTeamPresenter', () => {
|
||||
let presenter: DriverTeamPresenter;
|
||||
|
||||
beforeEach(() => {
|
||||
presenter = new DriverTeamPresenter();
|
||||
});
|
||||
|
||||
describe('present', () => {
|
||||
it('should map result to response model for owner', () => {
|
||||
const result = {
|
||||
driverId: 'driver-123',
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: { toString: () => 'Team Alpha' } as any,
|
||||
tag: { toString: () => 'TA' } as any,
|
||||
description: { toString: () => 'Best team' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [{ toString: () => 'league-1' } as any],
|
||||
isRecruiting: true,
|
||||
createdAt: { toDate: () => new Date('2024-01-01') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'owner' as const,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const model = presenter.getResponseModel();
|
||||
expect(model).toEqual({
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: 'Team Alpha',
|
||||
tag: 'TA',
|
||||
description: 'Best team',
|
||||
ownerId: 'driver-123',
|
||||
leagues: ['league-1'],
|
||||
isRecruiting: true,
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
},
|
||||
membership: {
|
||||
role: 'owner',
|
||||
joinedAt: '2024-01-01T00:00:00.000Z',
|
||||
isActive: true,
|
||||
},
|
||||
isOwner: true,
|
||||
canManage: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should map result for manager', () => {
|
||||
const result = {
|
||||
driverId: 'driver-456',
|
||||
team: {
|
||||
id: 'team-789',
|
||||
name: { toString: () => 'Team Beta' } as any,
|
||||
tag: { toString: () => 'TB' } as any,
|
||||
description: { toString: () => '' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [] as any[],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-02') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'manager' as const,
|
||||
joinedAt: new Date('2024-01-02'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const model = presenter.getResponseModel();
|
||||
expect(model?.isOwner).toBe(false);
|
||||
expect(model?.canManage).toBe(true);
|
||||
expect(model?.membership.role).toBe('manager');
|
||||
});
|
||||
|
||||
it('should map result for member', () => {
|
||||
const result = {
|
||||
driverId: 'driver-789',
|
||||
team: {
|
||||
id: 'team-abc',
|
||||
name: { toString: () => 'Team Gamma' } as any,
|
||||
tag: { toString: () => 'TG' } as any,
|
||||
description: { toString: () => 'Test team' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [{ toString: () => 'league-2' } as any],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-03') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'driver' as const,
|
||||
joinedAt: new Date('2024-01-03'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const model = presenter.getResponseModel();
|
||||
expect(model?.isOwner).toBe(false);
|
||||
expect(model?.canManage).toBe(false);
|
||||
expect(model?.membership.role).toBe('member');
|
||||
});
|
||||
|
||||
it('should handle empty description', () => {
|
||||
const result = {
|
||||
driverId: 'driver-123',
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: { toString: () => 'Team' } as any,
|
||||
tag: { toString: () => 'T' } as any,
|
||||
description: { toString: () => '' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [] as any[],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-01') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'owner' as const,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const model = presenter.getResponseModel();
|
||||
expect(model?.team.description).toBe('');
|
||||
});
|
||||
|
||||
it('should handle empty leagues', () => {
|
||||
const result = {
|
||||
driverId: 'driver-123',
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: { toString: () => 'Team' } as any,
|
||||
tag: { toString: () => 'T' } as any,
|
||||
description: { toString: () => 'Test' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [] as any[],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-01') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'owner' as const,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
};
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const model = presenter.getResponseModel();
|
||||
expect(model?.team.leagues).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('should clear the model', () => {
|
||||
presenter.present({
|
||||
driverId: 'driver-123',
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: { toString: () => 'Team' } as any,
|
||||
tag: { toString: () => 'T' } as any,
|
||||
description: { toString: () => '' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [] as any[],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-01') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'owner' as const,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
});
|
||||
expect(presenter.getResponseModel()).toBeDefined();
|
||||
|
||||
presenter.reset();
|
||||
expect(presenter.getResponseModel()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getResponseModel', () => {
|
||||
it('should return null before present()', () => {
|
||||
expect(presenter.getResponseModel()).toBeNull();
|
||||
});
|
||||
|
||||
it('should return model after present()', () => {
|
||||
presenter.present({
|
||||
driverId: 'driver-123',
|
||||
team: {
|
||||
id: 'team-456',
|
||||
name: { toString: () => 'Team' } as any,
|
||||
tag: { toString: () => 'T' } as any,
|
||||
description: { toString: () => '' } as any,
|
||||
ownerId: { toString: () => 'driver-123' } as any,
|
||||
leagues: [] as any[],
|
||||
isRecruiting: false,
|
||||
createdAt: { toDate: () => new Date('2024-01-01') } as any,
|
||||
} as any,
|
||||
membership: {
|
||||
role: 'owner' as const,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
status: 'active' as const,
|
||||
} as any,
|
||||
});
|
||||
expect(presenter.getResponseModel()).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user