import { describe, expect, it } from 'vitest';

import { buildUserProfileFromQuestionnaire } from '../index';
import { mapOnboardingSelectionsToQuestionnaireAnswers } from '../onboardingMapping';

describe('Onboarding → UserProfileScoring 集成', () => {
  it('完整作答：Onboarding 选择能正确映射并生成画像', () => {
    const selections = {
      status: ['pregnant'],
      emotion: ['calm'],
      influence: ['work'],
      support: ['balance'],
    };

    const answers = mapOnboardingSelectionsToQuestionnaireAnswers(selections);
    expect(answers).toEqual({
      mom_stage: 'expecting',
      emotion: 'calm',
      context: 'work',
      need: 'rest_balance',
    });

    const p = buildUserProfileFromQuestionnaire(answers, {
      generatedAt: '2026-01-30T00:00:00Z',
      now: '2026-01-30T00:00:00Z',
    });

    expect(p.stage).toEqual({ expecting: 1, parenting: 0, unknown: 0 });
    expect(p.emotion_score).toBe(0.8);
    expect(p.context).toEqual({ work: 1 });
    expect(p.need).toEqual({ rest_balance: 1 });
    expect(p.profile_answered).toEqual({ stage: true, emotion: true, context: true, need: true });
  });

  it('全部跳过：仍能生成最小可计算画像（unknown=1）', () => {
    const answers = mapOnboardingSelectionsToQuestionnaireAnswers({});
    expect(answers).toEqual({ mom_stage: null, emotion: null, context: null, need: null });

    const p = buildUserProfileFromQuestionnaire(answers, {
      generatedAt: '2026-01-30T00:00:00Z',
      now: '2026-01-30T00:00:00Z',
    });

    expect(p.stage).toEqual({ unknown: 1 });
    expect(p.emotion_score).toBeNull();
    expect(p.context).toEqual({});
    expect(p.need).toEqual({});
    expect(p.profile_answered).toEqual({ stage: false, emotion: false, context: false, need: false });
  });
});

