import { DeckMapper } from '../../../../src/Application/DTOs/Mappers/DeckMapper'; import { Type, CType, State } from '../../../../src/Domain/Deck/DeckAggregate'; describe('DeckMapper', () => { const createMockDeck = (overrides: any = {}) => ({ id: 'deck-123', name: 'Test Deck', type: Type.LUCK, userid: 'user-123', creationdate: new Date('2024-01-01'), cards: [ { text: 'Test card 1', answer: 'Answer 1' }, { text: 'Test card 2' } ], playedNumber: 5, ctype: CType.PUBLIC, updatedate: new Date('2024-01-02'), state: State.ACTIVE, organization: null, ...overrides }); describe('toShortDto', () => { it('should map DeckAggregate to ShortDeckDto correctly', () => { // Arrange const deck = createMockDeck(); // Act const result = DeckMapper.toShortDto(deck); // Assert expect(result).toEqual({ id: 'deck-123', name: 'Test Deck', type: Type.LUCK, playedNumber: 5, ctype: CType.PUBLIC }); }); it('should handle different deck types', () => { // Arrange const jokeDeck = createMockDeck({ id: 'joker-deck', name: 'Joker Deck', type: Type.JOKER, playedNumber: 10 }); // Act const result = DeckMapper.toShortDto(jokeDeck); // Assert expect(result.type).toBe(Type.JOKER); expect(result.playedNumber).toBe(10); }); it('should handle private decks', () => { // Arrange const privateDeck = createMockDeck({ ctype: CType.PRIVATE, playedNumber: 0 }); // Act const result = DeckMapper.toShortDto(privateDeck); // Assert expect(result.ctype).toBe(CType.PRIVATE); expect(result.playedNumber).toBe(0); }); }); describe('toDetailDto', () => { it('should map DeckAggregate to DetailDeckDto correctly', () => { // Arrange const deck = createMockDeck(); // Act const result = DeckMapper.toDetailDto(deck); // Assert expect(result).toEqual({ id: 'deck-123', name: 'Test Deck', type: Type.LUCK, userid: 'user-123', creationdate: new Date('2024-01-01'), cards: [ { text: 'Test card 1', answer: 'Answer 1' }, { text: 'Test card 2' } ], playedNumber: 5, ctype: CType.PUBLIC }); }); it('should handle empty cards array', () => { // Arrange const deckWithNoCards = createMockDeck({ cards: [] }); // Act const result = DeckMapper.toDetailDto(deckWithNoCards); // Assert expect(result.cards).toEqual([]); }); it('should handle question type deck', () => { // Arrange const questionDeck = createMockDeck({ type: Type.QUESTION, cards: [ { text: 'Question 1?', answer: 'Answer 1' }, { text: 'Question 2?', answer: null } ] }); // Act const result = DeckMapper.toDetailDto(questionDeck); // Assert expect(result.type).toBe(Type.QUESTION); expect(result.cards).toHaveLength(2); expect(result.cards[1].answer).toBeNull(); }); }); describe('toShortDtoList', () => { it('should map array of DeckAggregate to array of ShortDeckDto', () => { // Arrange const decks = [ createMockDeck({ id: 'deck-1', name: 'First Deck' }), createMockDeck({ id: 'deck-2', name: 'Second Deck', type: Type.JOKER }), createMockDeck({ id: 'deck-3', name: 'Third Deck', ctype: CType.PRIVATE }) ]; // Act const result = DeckMapper.toShortDtoList(decks); // Assert expect(result).toHaveLength(3); expect(result[0]).toEqual({ id: 'deck-1', name: 'First Deck', type: Type.LUCK, playedNumber: 5, ctype: CType.PUBLIC }); expect(result[1].type).toBe(Type.JOKER); expect(result[2].ctype).toBe(CType.PRIVATE); }); it('should handle empty array', () => { // Arrange const decks: any[] = []; // Act const result = DeckMapper.toShortDtoList(decks); // Assert expect(result).toEqual([]); expect(result).toHaveLength(0); }); it('should handle large arrays', () => { // Arrange const decks = Array.from({ length: 50 }, (_, i) => createMockDeck({ id: `deck-${i + 1}`, name: `Deck ${i + 1}`, playedNumber: i }) ); // Act const result = DeckMapper.toShortDtoList(decks); // Assert expect(result).toHaveLength(50); expect(result[0].playedNumber).toBe(0); expect(result[49].playedNumber).toBe(49); }); }); });