This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -2,29 +2,51 @@ import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
import { GetLeagueAdminPermissionsUseCase } from './GetLeagueAdminPermissionsUseCase';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import type { GetLeagueAdminPermissionsUseCaseParams } from './GetLeagueAdminPermissionsUseCaseParams';
describe('GetLeagueAdminPermissionsUseCase', () => {
let mockLeagueRepo: { findById: Mock };
let mockMembershipRepo: { getMembership: Mock };
let mockLeagueRepo: ILeagueRepository;
let mockMembershipRepo: ILeagueMembershipRepository;
let mockFindById: Mock;
let mockGetMembership: Mock;
beforeEach(() => {
mockLeagueRepo = { findById: vi.fn() };
mockMembershipRepo = { getMembership: vi.fn() };
mockFindById = vi.fn();
mockGetMembership = vi.fn();
mockLeagueRepo = {
findById: mockFindById,
findAll: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
exists: vi.fn(),
findByOwnerId: vi.fn(),
searchByName: vi.fn(),
} as ILeagueRepository;
mockMembershipRepo = {
getMembership: mockGetMembership,
getMembershipsForDriver: vi.fn(),
saveMembership: vi.fn(),
removeMembership: vi.fn(),
getJoinRequests: vi.fn(),
saveJoinRequest: vi.fn(),
removeJoinRequest: vi.fn(),
countByLeagueId: vi.fn(),
getLeagueMembers: vi.fn(),
} as ILeagueMembershipRepository;
});
const createUseCase = () => new GetLeagueAdminPermissionsUseCase(
mockLeagueRepo as unknown as ILeagueRepository,
mockMembershipRepo as unknown as ILeagueMembershipRepository,
mockLeagueRepo,
mockMembershipRepo,
);
const params: GetLeagueAdminPermissionsUseCaseParams = {
const params = {
leagueId: 'league1',
performerDriverId: 'driver1',
};
it('should return no permissions when league not found', async () => {
mockLeagueRepo.findById.mockResolvedValue(null);
mockFindById.mockResolvedValue(null);
const useCase = createUseCase();
const result = await useCase.execute(params);
@@ -34,8 +56,8 @@ describe('GetLeagueAdminPermissionsUseCase', () => {
});
it('should return no permissions when membership not found', async () => {
mockLeagueRepo.findById.mockResolvedValue({ id: 'league1' });
mockMembershipRepo.getMembership.mockResolvedValue(null);
mockFindById.mockResolvedValue({ id: 'league1' });
mockGetMembership.mockResolvedValue(null);
const useCase = createUseCase();
const result = await useCase.execute(params);
@@ -45,8 +67,8 @@ describe('GetLeagueAdminPermissionsUseCase', () => {
});
it('should return no permissions when membership not active', async () => {
mockLeagueRepo.findById.mockResolvedValue({ id: 'league1' });
mockMembershipRepo.getMembership.mockResolvedValue({ status: 'inactive', role: 'admin' });
mockFindById.mockResolvedValue({ id: 'league1' });
mockGetMembership.mockResolvedValue({ status: 'inactive', role: 'admin' });
const useCase = createUseCase();
const result = await useCase.execute(params);
@@ -56,8 +78,8 @@ describe('GetLeagueAdminPermissionsUseCase', () => {
});
it('should return no permissions when role is member', async () => {
mockLeagueRepo.findById.mockResolvedValue({ id: 'league1' });
mockMembershipRepo.getMembership.mockResolvedValue({ status: 'active', role: 'member' });
mockFindById.mockResolvedValue({ id: 'league1' });
mockGetMembership.mockResolvedValue({ status: 'active', role: 'member' });
const useCase = createUseCase();
const result = await useCase.execute(params);
@@ -67,8 +89,8 @@ describe('GetLeagueAdminPermissionsUseCase', () => {
});
it('should return permissions when role is admin', async () => {
mockLeagueRepo.findById.mockResolvedValue({ id: 'league1' });
mockMembershipRepo.getMembership.mockResolvedValue({ status: 'active', role: 'admin' });
mockFindById.mockResolvedValue({ id: 'league1' });
mockGetMembership.mockResolvedValue({ status: 'active', role: 'admin' });
const useCase = createUseCase();
const result = await useCase.execute(params);
@@ -78,8 +100,8 @@ describe('GetLeagueAdminPermissionsUseCase', () => {
});
it('should return permissions when role is owner', async () => {
mockLeagueRepo.findById.mockResolvedValue({ id: 'league1' });
mockMembershipRepo.getMembership.mockResolvedValue({ status: 'active', role: 'owner' });
mockFindById.mockResolvedValue({ id: 'league1' });
mockGetMembership.mockResolvedValue({ status: 'active', role: 'owner' });
const useCase = createUseCase();
const result = await useCase.execute(params);