plan-templates.test.js 2.12 KB
import { describe, expect, it } from 'vitest'
import { PLAN_TEMPLATES } from '../plan-templates'
import { PLAN_FIELD_DEFINITIONS } from '../plan-fields'

describe('plan template amount field mapping', () => {
  it('should map protection coverage to coverage api field', () => {
    expect(PLAN_TEMPLATES['life-insurance-wiop3e'].config.submit_mapping.coverage).toEqual({
      api_field: 'coverage',
      transform: 'fen_to_yuan'
    })
  })

  it('should use annual_premium field for savings schema and submit mapping', () => {
    const savingsConfig = PLAN_TEMPLATES['savings-gs'].config
    const annualPremiumField = savingsConfig.form_schema.base_fields.find(field => field.key === 'annual_premium')

    expect(annualPremiumField).toMatchObject({
      key: 'annual_premium',
      label: '年缴保费',
      type: 'amount'
    })

    expect(savingsConfig.submit_mapping.annual_premium).toEqual({
      api_field: 'annual_premium',
      transform: 'fen_to_yuan'
    })

    expect(savingsConfig.submit_mapping.coverage).toBeUndefined()
  })
})

describe('plan field definitions amount semantics', () => {
  it('should expose separate coverage and annual_premium definitions', () => {
    expect(PLAN_FIELD_DEFINITIONS.coverage).toMatchObject({
      label: '保额',
      api_field: 'coverage',
      transform: 'fen_to_yuan'
    })

    expect(PLAN_FIELD_DEFINITIONS.annual_premium).toMatchObject({
      label: '年缴保费',
      api_field: 'annual_premium',
      transform: 'fen_to_yuan'
    })
  })
})

describe('critical illness mpc special age options', () => {
  it('should expose pregnancy week option only for mpc', () => {
    expect(PLAN_TEMPLATES['critical-illness-mpc'].config.special_age_options).toEqual(['孕22周'])
    expect(PLAN_TEMPLATES['critical-illness-mbc-pro'].config.special_age_options).toBeUndefined()
    expect(PLAN_TEMPLATES['critical-illness-mbc2'].config.special_age_options).toBeUndefined()
  })
})

describe('savings gs multistage payment periods', () => {
  it('should include 2-year payment period option', () => {
    expect(PLAN_TEMPLATES['savings-gs-multistage'].config.payment_periods).toContain('2 年')
  })
})