80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { TeamJoinService } from './TeamJoinService';
|
|
import type { TeamsApiClient } from '../../api/teams/TeamsApiClient';
|
|
|
|
describe('TeamJoinService', () => {
|
|
let service: TeamJoinService;
|
|
let mockApiClient: TeamsApiClient;
|
|
|
|
beforeEach(() => {
|
|
mockApiClient = {
|
|
getJoinRequests: vi.fn(),
|
|
} as any;
|
|
|
|
service = new TeamJoinService(mockApiClient);
|
|
});
|
|
|
|
describe('getJoinRequests', () => {
|
|
it('should return view models for join requests', async () => {
|
|
const mockDto = {
|
|
requests: [
|
|
{
|
|
id: 'request-1',
|
|
teamId: 'team-1',
|
|
driverId: 'driver-1',
|
|
requestedAt: '2023-01-01T00:00:00Z',
|
|
message: 'Please accept me',
|
|
},
|
|
{
|
|
id: 'request-2',
|
|
teamId: 'team-1',
|
|
driverId: 'driver-2',
|
|
requestedAt: '2023-01-02T00:00:00Z',
|
|
},
|
|
],
|
|
};
|
|
|
|
mockApiClient.getJoinRequests = vi.fn().mockResolvedValue(mockDto);
|
|
|
|
const result = await service.getJoinRequests('team-1', 'user-1', true);
|
|
|
|
expect(mockApiClient.getJoinRequests).toHaveBeenCalledWith('team-1');
|
|
expect(result).toHaveLength(2);
|
|
expect(result[0].id).toBe('request-1');
|
|
expect(result[0].canApprove).toBe(true);
|
|
expect(result[1].id).toBe('request-2');
|
|
expect(result[1].canApprove).toBe(true);
|
|
});
|
|
|
|
it('should pass correct parameters to view model constructor', async () => {
|
|
const mockDto = {
|
|
requests: [
|
|
{
|
|
id: 'request-1',
|
|
teamId: 'team-1',
|
|
driverId: 'driver-1',
|
|
requestedAt: '2023-01-01T00:00:00Z',
|
|
},
|
|
],
|
|
};
|
|
|
|
mockApiClient.getJoinRequests = vi.fn().mockResolvedValue(mockDto);
|
|
|
|
const result = await service.getJoinRequests('team-1', 'user-1', false);
|
|
|
|
expect(result[0].canApprove).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('approveJoinRequest', () => {
|
|
it('should throw not implemented error', async () => {
|
|
await expect(service.approveJoinRequest()).rejects.toThrow('Not implemented: API endpoint for approving join requests');
|
|
});
|
|
});
|
|
|
|
describe('rejectJoinRequest', () => {
|
|
it('should throw not implemented error', async () => {
|
|
await expect(service.rejectJoinRequest()).rejects.toThrow('Not implemented: API endpoint for rejecting join requests');
|
|
});
|
|
});
|
|
}); |