import { describe, expect, it } from 'vitest';
import {
  toPersonalityQuizResultMutationDto,
  toPersonalityQuizResultViewModel,
} from '@/business/personality/mappers';
import type { PersonalityQuizSubmission } from '@/business/personality/types';
import type { PersonalityQuizResultDto } from '@/shared/types/personality';

describe('personality mappers', () => {
  it('maps a null backend result to a null view model', () => {
    expect(toPersonalityQuizResultViewModel(null)).toBeNull();
  });

  it('maps backend quiz result DTO fields into the frontend view model shape', () => {
    const dto: PersonalityQuizResultDto = {
      id: 'personality-1',
      personality_type: 'INFJ',
      quiz_answers: {
        '1': 'I',
        '2': 'N',
        '3': 'F',
        '4': 'J',
      },
      completed_at: '2026-06-08T08:00:00.000Z',
      organizationId: 'org-1',
      campusId: 'campus-1',
      userId: 'user-1',
      createdById: 'user-1',
      updatedById: null,
      createdAt: '2026-06-08T08:00:00.000Z',
      updatedAt: '2026-06-08T09:00:00.000Z',
    };

    expect(toPersonalityQuizResultViewModel(dto)).toEqual({
      personalityType: 'INFJ',
      quizAnswers: {
        1: 'I',
        2: 'N',
        3: 'F',
        4: 'J',
      },
      updatedAt: '2026-06-08T09:00:00.000Z',
    });
  });

  it('maps quiz submission state back into the backend mutation DTO shape', () => {
    const submission: PersonalityQuizSubmission = {
      personalityType: 'ESTP',
      quizAnswers: {
        1: 'E',
        2: 'S',
        3: 'T',
        4: 'P',
      },
    };

    expect(toPersonalityQuizResultMutationDto(submission)).toEqual({
      personality_type: 'ESTP',
      quiz_answers: {
        '1': 'E',
        '2': 'S',
        '3': 'T',
        '4': 'P',
      },
    });
  });
});
