244 lines
7.4 KiB
TypeScript
244 lines
7.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ProfileLeaguesViewDataBuilder } from './ProfileLeaguesViewDataBuilder';
|
|
|
|
describe('ProfileLeaguesViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform ProfileLeaguesPageDto to ProfileLeaguesViewData correctly', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Owned League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Member League',
|
|
description: 'Test Description',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result).toEqual({
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Owned League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner',
|
|
},
|
|
],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Member League',
|
|
description: 'Test Description',
|
|
membershipRole: 'member',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('should handle empty owned leagues', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Member League',
|
|
description: 'Test Description',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues).toHaveLength(0);
|
|
expect(result.memberLeagues).toHaveLength(1);
|
|
});
|
|
|
|
it('should handle empty member leagues', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Owned League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
],
|
|
memberLeagues: [],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues).toHaveLength(1);
|
|
expect(result.memberLeagues).toHaveLength(0);
|
|
});
|
|
|
|
it('should handle multiple leagues in both arrays', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Owned League 1',
|
|
description: 'Description 1',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Owned League 2',
|
|
description: 'Description 2',
|
|
membershipRole: 'admin' as const,
|
|
},
|
|
],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-3',
|
|
name: 'Member League 1',
|
|
description: 'Description 3',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
{
|
|
leagueId: 'league-4',
|
|
name: 'Member League 2',
|
|
description: 'Description 4',
|
|
membershipRole: 'steward' as const,
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues).toHaveLength(2);
|
|
expect(result.memberLeagues).toHaveLength(2);
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Test League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Test League 2',
|
|
description: 'Test Description 2',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues[0].leagueId).toBe(profileLeaguesPageDto.ownedLeagues[0].leagueId);
|
|
expect(result.ownedLeagues[0].name).toBe(profileLeaguesPageDto.ownedLeagues[0].name);
|
|
expect(result.ownedLeagues[0].description).toBe(profileLeaguesPageDto.ownedLeagues[0].description);
|
|
expect(result.ownedLeagues[0].membershipRole).toBe(profileLeaguesPageDto.ownedLeagues[0].membershipRole);
|
|
expect(result.memberLeagues[0].leagueId).toBe(profileLeaguesPageDto.memberLeagues[0].leagueId);
|
|
expect(result.memberLeagues[0].name).toBe(profileLeaguesPageDto.memberLeagues[0].name);
|
|
expect(result.memberLeagues[0].description).toBe(profileLeaguesPageDto.memberLeagues[0].description);
|
|
expect(result.memberLeagues[0].membershipRole).toBe(profileLeaguesPageDto.memberLeagues[0].membershipRole);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Test League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
],
|
|
memberLeagues: [
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Test League 2',
|
|
description: 'Test Description 2',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
],
|
|
};
|
|
|
|
const originalDto = { ...profileLeaguesPageDto };
|
|
ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(profileLeaguesPageDto).toEqual(originalDto);
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle different membership roles', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Test League',
|
|
description: 'Test Description',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
{
|
|
leagueId: 'league-2',
|
|
name: 'Test League 2',
|
|
description: 'Test Description 2',
|
|
membershipRole: 'admin' as const,
|
|
},
|
|
{
|
|
leagueId: 'league-3',
|
|
name: 'Test League 3',
|
|
description: 'Test Description 3',
|
|
membershipRole: 'steward' as const,
|
|
},
|
|
{
|
|
leagueId: 'league-4',
|
|
name: 'Test League 4',
|
|
description: 'Test Description 4',
|
|
membershipRole: 'member' as const,
|
|
},
|
|
],
|
|
memberLeagues: [],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues[0].membershipRole).toBe('owner');
|
|
expect(result.ownedLeagues[1].membershipRole).toBe('admin');
|
|
expect(result.ownedLeagues[2].membershipRole).toBe('steward');
|
|
expect(result.ownedLeagues[3].membershipRole).toBe('member');
|
|
});
|
|
|
|
it('should handle empty description', () => {
|
|
const profileLeaguesPageDto = {
|
|
ownedLeagues: [
|
|
{
|
|
leagueId: 'league-1',
|
|
name: 'Test League',
|
|
description: '',
|
|
membershipRole: 'owner' as const,
|
|
},
|
|
],
|
|
memberLeagues: [],
|
|
};
|
|
|
|
const result = ProfileLeaguesViewDataBuilder.build(profileLeaguesPageDto);
|
|
|
|
expect(result.ownedLeagues[0].description).toBe('');
|
|
});
|
|
});
|
|
});
|