planSubmitTransformers.test.js
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { describe, expect, it, vi } from 'vitest'
import {
transformSubmitValue,
transformWithdrawalStagesForSubmit
} from '../planSubmitTransformers'
describe('transformWithdrawalStagesForSubmit', () => {
it('should convert withdrawal stage amount from fen to yuan', () => {
const result = transformWithdrawalStagesForSubmit([
{
annual_withdrawal_amount: 12300,
withdrawal_start_age: 18,
withdrawal_period: '1年',
annual_increase_percentage: '12'
}
])
expect(result).toEqual([
{
annual_withdrawal_amount: '123.00',
withdrawal_start_age: 18,
withdrawal_period: '1年',
annual_increase_percentage: '12'
}
])
})
it('should keep empty stage amount unchanged', () => {
const result = transformWithdrawalStagesForSubmit([
{
annual_withdrawal_amount: null,
withdrawal_start_age: 18
}
])
expect(result[0].annual_withdrawal_amount).toBeNull()
})
})
describe('transformSubmitValue', () => {
it('should use fen_to_yuan mapping for simple amount fields', () => {
const toYuan = vi.fn().mockReturnValue('123.00')
const result = transformSubmitValue({
fieldKey: 'annual_withdrawal_amount',
value: 12300,
mapping: {
api_field: 'annual_withdrawal_amount',
transform: 'fen_to_yuan'
},
toYuan
})
expect(result).toBe('123.00')
expect(toYuan).toHaveBeenCalledWith('annual_withdrawal_amount', 12300)
})
it('should use custom mapping transform for withdrawal stages', () => {
const result = transformSubmitValue({
fieldKey: 'withdrawal_stages',
value: [
{
annual_withdrawal_amount: 12300,
withdrawal_start_age: 18
}
],
mapping: {
api_field: 'withdrawal_stages',
transform: transformWithdrawalStagesForSubmit
},
toYuan: vi.fn()
})
expect(result).toEqual([
{
annual_withdrawal_amount: '123.00',
withdrawal_start_age: 18
}
])
})
})