resolve manual DTOs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, Mocked } from 'vitest';
|
||||
import { MembershipFeeService, GetMembershipFeesOutputDto } from './MembershipFeeService';
|
||||
import { MembershipFeeService } from './MembershipFeeService';
|
||||
import { PaymentsApiClient } from '../../api/payments/PaymentsApiClient';
|
||||
import { MembershipFeeViewModel } from '../../view-models';
|
||||
import type { MembershipFeeDto } from '../../types/generated';
|
||||
@@ -17,36 +17,30 @@ describe('MembershipFeeService', () => {
|
||||
});
|
||||
|
||||
describe('getMembershipFees', () => {
|
||||
it('should call apiClient.getMembershipFees with correct leagueId and return mapped view models', async () => {
|
||||
it('should call apiClient.getMembershipFees with correct leagueId and return fee and payments', async () => {
|
||||
const leagueId = 'league-123';
|
||||
const mockFees: MembershipFeeDto[] = [
|
||||
{ id: 'fee-1', leagueId: 'league-123' },
|
||||
{ id: 'fee-2', leagueId: 'league-123' },
|
||||
];
|
||||
const mockOutput: GetMembershipFeesOutputDto = { fees: mockFees };
|
||||
const mockFee: MembershipFeeDto = { id: 'fee-1', leagueId: 'league-123', seasonId: undefined, type: 'season', amount: 100, enabled: true, createdAt: new Date(), updatedAt: new Date() };
|
||||
const mockPayments: any[] = [];
|
||||
const mockOutput = { fee: mockFee, payments: mockPayments };
|
||||
mockApiClient.getMembershipFees.mockResolvedValue(mockOutput);
|
||||
|
||||
const result = await service.getMembershipFees(leagueId);
|
||||
|
||||
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith(leagueId);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]).toBeInstanceOf(MembershipFeeViewModel);
|
||||
expect(result[0].id).toEqual('fee-1');
|
||||
expect(result[0].leagueId).toEqual('league-123');
|
||||
expect(result[1]).toBeInstanceOf(MembershipFeeViewModel);
|
||||
expect(result[1].id).toEqual('fee-2');
|
||||
expect(result[1].leagueId).toEqual('league-123');
|
||||
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith({ leagueId });
|
||||
expect(result.fee).toBeInstanceOf(MembershipFeeViewModel);
|
||||
expect(result.fee!.id).toEqual('fee-1');
|
||||
expect(result.payments).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return empty array when no fees are returned', async () => {
|
||||
it('should return null fee when no fee is returned', async () => {
|
||||
const leagueId = 'league-456';
|
||||
const mockOutput: GetMembershipFeesOutputDto = { fees: [] };
|
||||
const mockOutput = { fee: null, payments: [] };
|
||||
mockApiClient.getMembershipFees.mockResolvedValue(mockOutput);
|
||||
|
||||
const result = await service.getMembershipFees(leagueId);
|
||||
|
||||
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith(leagueId);
|
||||
expect(result).toEqual([]);
|
||||
expect(mockApiClient.getMembershipFees).toHaveBeenCalledWith({ leagueId });
|
||||
expect(result.fee).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user