import { describe, expect, it } from 'vitest'; import { Comment } from '../../domain/entities/comment.entity.js'; import { CommentApplicationMapper } from './comment-application.mapper.js'; import { UserDto } from '../../../user/application/dto/user.dto.js'; const author: UserDto = { id: 'user-1', name: 'User 1', email: 'user-1@example.com', emailVerified: true, image: null, createdAt: new Date('2026-01-01T00:00:00.000Z'), updatedAt: new Date('2026-01-01T00:00:00.000Z'), }; const buildComment = (deletedAt: Date | null = null, authorId: string | null = 'user-1') => Comment.reconstitute({ id: 'comment-1', content: 'Secret', issueId: 1, authorId, editedAt: null, deletedAt, createdAt: new Date('2026-01-01T00:00:00.000Z'), updatedAt: new Date('2026-01-01T00:00:00.000Z'), }); describe('CommentApplicationMapper', () => { it('expands the author', () => { const dto = CommentApplicationMapper.toDto(buildComment(), new Map([[author.id, author]])); expect(dto.author).toEqual(author); expect(dto.content).toBe('Secret'); }); it('hides content of a deleted comment', () => { const dto = CommentApplicationMapper.toDto(buildComment(new Date()), new Map([[author.id, author]])); expect(dto.content).toBeNull(); expect(dto.deletedAt).toBeInstanceOf(Date); }); it('returns null author when the author account is deleted', () => { const dto = CommentApplicationMapper.toDto(buildComment(null, null), new Map()); expect(dto.authorId).toBeNull(); expect(dto.author).toBeNull(); }); });