simpleQuotationRoute.helpers.test.mjs 3.34 KB
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'

import {
  buildSimpleQuotationRouteState,
  getLatestAccountTimestamp
} from '../pages/carQuotation/services/simpleQuotationRoute.helpers.js'

describe('simpleQuotationRoute.helpers', () => {
  it('IT-EQ-SIMPLE-ROUTE-001: maps each supported payment entry without mixing route and order state', () => {
    assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 1 }), {
      pagePatch: { paymentMethod: 1 },
      orderPatch: { payType: 1, payee: 0 }
    })
    assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 3 }), {
      pagePatch: { paymentMethod: 3 },
      orderPatch: { payType: 2, payee: 1 }
    })
    assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 4 }), {
      pagePatch: { paymentMethod: 4 },
      orderPatch: { payType: 6, payee: 0 }
    })
    assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 6 }), {
      pagePatch: { paymentMethod: 6 },
      orderPatch: { payType: 7, payee: 0 }
    })
    assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 5 }), {
      pagePatch: { paymentMethod: 5 },
      orderPatch: {}
    })
  })

  it('IT-EQ-SIMPLE-ROUTE-002: maps one in-period trade to online pay and keeps zero-cent totals exact', () => {
    const trades = [
      {
        outTradeNo: 'out-1',
        tradeNo: 'trade-1',
        totalFee: 0,
        switchValue: 1,
        accountDateValue: 100
      }
    ]

    const result = buildSimpleQuotationRouteState(
      { selectOutTradeNoArr: trades },
      { formatAccountDate: value => `date:${value}` }
    )

    assert.deepEqual(result.pagePatch, {
      selectOutTradeNoArr: trades,
      switchValue: 1,
      outTradeNo: 'out-1',
      tradeNo: 'trade-1',
      totalFee: 0,
      accountDate: 'date:100',
      showTips: true,
      orderCreateType: 'additionRecordOrder'
    })
    assert.deepEqual(result.orderPatch, {
      payType: 1,
      payee: 0,
      outTradeNo: 'out-1',
      tradeNo: 'trade-1',
      transactionNo: 'trade-1',
      switchValue: 1,
      selectOutTradeNoArr: trades,
      successDateTime: '',
      pay2Time: ''
    })
  })

  it('IT-EQ-SIMPLE-ROUTE-003: mixed settlement periods use the latest date and combined recorded-payment fields', () => {
    const trades = [
      {
        outTradeNo: 'out-1',
        tradeNo: 'trade-1',
        totalFee: 101,
        switchValue: 1,
        accountDateValue: 100
      },
      {
        outTradeNo: 'out-2',
        tradeNo: 'trade-2',
        totalFee: 202,
        switchValue: 2,
        accountDateValue: 300
      }
    ]

    const result = buildSimpleQuotationRouteState(
      { selectOutTradeNoArr: trades, orderCreateType: 'custom-record' },
      { formatAccountDate: value => `date:${value}` }
    )

    assert.equal(getLatestAccountTimestamp(trades), 300)
    assert.equal(result.pagePatch.switchValue, null)
    assert.equal(result.pagePatch.totalFee, 303)
    assert.equal(result.pagePatch.accountDate, 'date:300')
    assert.equal(result.pagePatch.orderCreateType, 'custom-record')
    assert.equal(result.orderPatch.payType, 5)
    assert.equal(result.orderPatch.successDateTime, 'date:300')
    assert.equal(result.orderPatch.pay2Time, 'date:300')
    assert.equal(result.orderPatch.outTradeNo, 'out-1,out-2')
    assert.equal(result.orderPatch.transactionNo, 'trade-1,trade-2')
  })
})