Files
gridpilot.gg/apps/website/lib/services/payments/MembershipFeeService.test.ts
2026-01-17 22:55:03 +01:00

44 lines
1.7 KiB
TypeScript

import { describe, it, expect, vi, Mocked } from 'vitest';
import { MembershipFeeService } from './MembershipFeeService';
import { PaymentsApiClient } from '@/lib/api/payments/PaymentsApiClient';
import { MembershipFeeViewModel } from '../../view-models';
import type { MembershipFeeDto } from '@/lib/types/generated';
describe('MembershipFeeService', () => {
let mockApiClient: Mocked<PaymentsApiClient>;
let service: MembershipFeeService;
beforeEach(() => {
mockApiClient = {
getMembershipFees: vi.fn(),
} as Mocked<PaymentsApiClient>;
service = new MembershipFeeService(mockApiClient);
});
describe('getMembershipFee', () => {
it('should call apiClient.getMembershipFees with correct leagueId and return fee', async () => {
const leagueId = 'league-123';
const mockFee: any = { id: 'fee-1', leagueId: 'league-123', amount: 100 };
const mockOutput = { fee: mockFee, payments: [] };
mockApiClient.getMembershipFees.mockResolvedValue(mockOutput as any);
const result = await service.getMembershipFee(leagueId);
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith({ leagueId });
expect(result).toBeInstanceOf(MembershipFeeViewModel);
expect(result!.id).toEqual('fee-1');
});
it('should return null when no fee is returned', async () => {
const leagueId = 'league-456';
const mockOutput = { fee: null, payments: [] };
mockApiClient.getMembershipFees.mockResolvedValue(mockOutput as any);
const result = await service.getMembershipFee(leagueId);
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith({ leagueId });
expect(result).toBeNull();
});
});
});