@jetthai/cuora 2.0.0-beta.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -113
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -112
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +18 -28
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +2 -13
  70. package/src/machine/game_v2_1.js +42 -166
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -463
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -91
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -144
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -195
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -148
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -629
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,105 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import virtualBankCashFactory from '../src/machine/deposit/virtual_bank_cash.js'
5
-
6
- test('virtual_bank_cash covers actions, guards, and services branches', async () => {
7
- const sent = []
8
- const request = {
9
- config: { appSecret: 'secret' },
10
- send: async (req) => {
11
- sent.push(req)
12
- if (req.url === 'payment/v2/vbank_cash/expected/result') {
13
- return { data: { expectedAmount: 1234 } }
14
- }
15
- if (req.url === 'payment/v2/vbank_cash/transaction') {
16
- return { applyId: 'A-1', status: 'processing' }
17
- }
18
- return {}
19
- },
20
- }
21
-
22
- const machine = virtualBankCashFactory(request, {
23
- selectedAmount: 40,
24
- promotion: { minimumAmount: 50, promotionsNo: 'P-1' },
25
- paymentDetail: [
26
- {
27
- category: 'virtualBank',
28
- transferType: 'deposit',
29
- method: 'vbank_cash',
30
- minimum: 100,
31
- maximum: 500,
32
- processing: [{ id: 'processing-1' }],
33
- virtualBanks: [{ bank: 'A' }],
34
- },
35
- {
36
- category: 'virtualBank',
37
- transferType: 'withdraw',
38
- method: 'ignored',
39
- },
40
- ],
41
- })
42
-
43
- const { actions, guards, services } = machine.options
44
- const initial = machine.initialState.context
45
-
46
- const initData = await services.fetchInitData(initial)
47
- assert.equal(initData.currentPayment.method, 'vbank_cash')
48
-
49
- const setInitData = actions.setInitData.assignment(initial, { data: initData })
50
- assert.equal(setInitData.method, 'vbank_cash')
51
- assert.equal(setInitData.processing.id, 'processing-1')
52
- assert.equal(setInitData.virtualBanks.bank, 'A')
53
- assert.equal(setInitData.selectedAmount, 100)
54
-
55
- const setInitDataWithoutOptional = actions.setInitData.assignment(
56
- { paymentDetail: [{ category: 'virtualBank', transferType: 'deposit', method: 'plain', minimum: 10, maximum: 20 }] },
57
- { data: { currentPayment: { method: 'plain', minimum: 10, maximum: 20 } } }
58
- )
59
- assert.equal(setInitDataWithoutOptional.processing, null)
60
- assert.equal(setInitDataWithoutOptional.virtualBanks, null)
61
-
62
- assert.equal(actions.inputAmount.assignment(initial, { data: 222 }).selectedAmount, 222)
63
-
64
- const fromV2 = actions.setCalculation.assignment(initial, { data: { data: { expectedAmount: 88 } } })
65
- assert.equal(fromV2.calculation.expectedAmount, 88)
66
-
67
- const legacy = actions.setCalculation.assignment(initial, { data: { expectedAmount: 77 } })
68
- assert.equal(legacy.calculation.expectedAmount, 77)
69
-
70
- assert.equal(actions.setProcessing.assignment(initial, { data: { applyId: 'A-2' } }).processing.applyId, 'A-2')
71
- assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
72
- assert.equal(actions.setDepositTime.assignment(initial, { data: '2026-01-01 00:00:00' }).depositTime, '2026-01-01 00:00:00')
73
- assert.equal(actions.setPromotion.assignment(initial, { data: { promotionsNo: 'P-2' } }).promotion.promotionsNo, 'P-2')
74
-
75
- assert.equal(guards.isCalculable({ selectedAmount: 100, currentPayment: null }), false)
76
- assert.equal(guards.isCalculable({ selectedAmount: 99, currentPayment: { minimum: 100, maximum: 500 } }), false)
77
- assert.equal(guards.isCalculable({ selectedAmount: 501, currentPayment: { minimum: 100, maximum: 500 } }), false)
78
- assert.equal(guards.isCalculable({ selectedAmount: '120', currentPayment: { minimum: 100, maximum: 500 } }), true)
79
-
80
- assert.equal(guards.isProcessing({ processing: null }), null)
81
- assert.equal(guards.isProcessing({ processing: { applyId: 'A-3' } }).applyId, 'A-3')
82
-
83
- const calcResult = await services.fetchCalculation({ method: 'vbank_cash', selectedAmount: '345', promotion: { promotionsNo: 'P-1' } }, {})
84
- assert.equal(calcResult.data.expectedAmount, 1234)
85
-
86
- const submitResult = await services.submitDeposit(
87
- {
88
- method: 'vbank_cash',
89
- selectedAmount: 456,
90
- depositTime: '2026-01-01 10:00:00',
91
- promotion: { promotionsNo: 'P-9' },
92
- },
93
- {}
94
- )
95
- assert.equal(submitResult.applyId, 'A-1')
96
-
97
- const calcReq = sent.find((entry) => entry.url === 'payment/v2/vbank_cash/expected/result')
98
- assert.equal(calcReq.params.amount, 345)
99
- assert.equal(calcReq.params.promotionsNo, 'P-1')
100
-
101
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/vbank_cash/transaction')
102
- assert.equal(submitReq.params.amount, 456)
103
- assert.equal(submitReq.params.depositTime, '2026-01-01 10:00:00')
104
- assert.equal(submitReq.params.promotionsNo, 'P-9')
105
- })
@@ -1,105 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import virtualBankVnFactory from '../src/machine/deposit/virtual_bank_vn.js'
5
-
6
- test('virtual_bank_vn covers actions, guards, inline checking cond and services', async () => {
7
- const sent = []
8
- const request = {
9
- config: { appSecret: 'secret' },
10
- send: async (req) => {
11
- sent.push(req)
12
- if (req.url === 'payment/v2/paymentDetail') {
13
- return [
14
- { category: 'other', method: 'ignored' },
15
- {
16
- category: 'virtualBank',
17
- method: 'virtual_bank_vn',
18
- minimum: 100,
19
- maximum: 500,
20
- processing: [{ applyId: 'P-1' }],
21
- virtualBanks: [{ bankCode: 'VCB' }],
22
- },
23
- ]
24
- }
25
- if (req.url === 'payment/v2/virtual_bank_vn/expected/result') {
26
- return { data: { expectedAmount: 888 } }
27
- }
28
- if (req.url === 'payment/v2/virtual_bank_vn/transaction') {
29
- return { applyId: 'TX-1', status: 'processing' }
30
- }
31
- return {}
32
- },
33
- }
34
-
35
- const machine = virtualBankVnFactory(request)
36
- const { actions, guards, services } = machine.options
37
- const initial = machine.initialState.context
38
-
39
- const paymentDetail = await services.fetchPaymentDetail(initial)
40
- assert.equal(paymentDetail.length, 2)
41
-
42
- const initData = actions.setInitData.assignment(initial, { data: paymentDetail })
43
- assert.equal(initData.paymentDetail.length, 2)
44
- assert.equal(initData.currentPayment.method, 'virtual_bank_vn')
45
- assert.equal(initData.method, 'virtual_bank_vn')
46
- assert.equal(initData.processing.applyId, 'P-1')
47
- assert.equal(initData.virtualBanks.bankCode, 'VCB')
48
-
49
- const initEmpty = actions.setInitData.assignment(initial, { data: [] })
50
- assert.equal(initEmpty.currentPayment, undefined)
51
- assert.equal(initEmpty.method, undefined)
52
- assert.equal(initEmpty.processing, undefined)
53
- assert.equal(initEmpty.virtualBanks, undefined)
54
-
55
- assert.equal(actions.setAmount.assignment(initial, { data: 222 }).amount, 222)
56
-
57
- const calculationV2 = actions.setCalculation.assignment(initial, { data: { data: { expectedAmount: 777 } } })
58
- assert.equal(calculationV2.calculation.expectedAmount, 777)
59
-
60
- const calculationLegacy = actions.setCalculation.assignment(initial, { data: { expectedAmount: 666 } })
61
- assert.equal(calculationLegacy.calculation.expectedAmount, 666)
62
-
63
- assert.equal(actions.setProcessing.assignment(initial, { data: { applyId: 'P-2' } }).processing.applyId, 'P-2')
64
- assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
65
- assert.equal(actions.setDepositTime.assignment(initial, { data: '2026-02-01 10:00:00' }).depositTime, '2026-02-01 10:00:00')
66
- assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'A-1' } }).promotion.activityNo, 'A-1')
67
-
68
- assert.equal(guards.isCalculable({ amount: 100, currentPayment: { minimum: 100, maximum: 500 } }), true)
69
- assert.equal(guards.isCalculable({ amount: 99, currentPayment: { minimum: 100, maximum: 500 } }), false)
70
- assert.equal(guards.isCalculable({ amount: 501, currentPayment: { minimum: 100, maximum: 500 } }), false)
71
-
72
- assert.equal(guards.isCalculated({ calculation: null }), null)
73
- assert.equal(guards.isCalculated({ calculation: { expectedAmount: 1 } }).expectedAmount, 1)
74
- assert.equal(guards.isProcessing({ processing: null }), null)
75
- assert.equal(guards.isProcessing({ processing: { applyId: 'P-3' } }).applyId, 'P-3')
76
-
77
- const checkingCond = machine.config.states.checking.always[0].cond
78
- assert.equal(checkingCond({ calculation: { expectedAmount: 1 }, promotion: { promotionsNo: 'x', activityNo: 'y' } }), true)
79
- assert.equal(checkingCond({ calculation: { expectedAmount: 1 }, promotion: { promotionsNo: 'none', activityNo: 'y' } }), false)
80
- assert.equal(checkingCond({ calculation: { expectedAmount: 1 }, promotion: { promotionsNo: 'x', activityNo: 'none' } }), false)
81
- assert.equal(checkingCond({ calculation: null, promotion: { promotionsNo: 'x', activityNo: 'y' } }), false)
82
-
83
- const calcResult = await services.fetchCalculation({ method: 'virtual_bank_vn', amount: '333', promotion: { activityNo: 'A-9' } })
84
- assert.equal(calcResult.data.expectedAmount, 888)
85
-
86
- const submitResult = await services.submitDeposit({
87
- method: 'virtual_bank_vn',
88
- amount: 444,
89
- depositTime: '2026-02-01 10:00:00',
90
- promotion: { activityNo: 'A-8' },
91
- })
92
- assert.equal(submitResult.applyId, 'TX-1')
93
-
94
- const fetchReq = sent.find((entry) => entry.url === 'payment/v2/paymentDetail')
95
- assert.equal(fetchReq.params.transferType, 'DEPOSIT')
96
-
97
- const calcReq = sent.find((entry) => entry.url === 'payment/v2/virtual_bank_vn/expected/result')
98
- assert.equal(calcReq.params.amount, 333)
99
- assert.equal(calcReq.params.promotionsNo, 'A-9')
100
-
101
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/virtual_bank_vn/transaction')
102
- assert.equal(submitReq.params.amount, 444)
103
- assert.equal(submitReq.params.depositTime, '2026-02-01 10:00:00')
104
- assert.equal(submitReq.params.promotionsNo, 'A-8')
105
- })
@@ -1,142 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import vpayFactory from '../src/machine/deposit/vpay.js'
5
-
6
- test('vpay covers actions, guards, inline cond and services', async () => {
7
- const sent = []
8
- const request = {
9
- config: { appSecret: 'app-secret' },
10
- send: async (req) => {
11
- sent.push(req)
12
- if (req.url === 'payment/v2/paymentInfo') {
13
- return {
14
- bankInfo: [
15
- { bindingType: 'CRYPTO', id: 1 },
16
- { bindingType: 'EWALLET', id: 2 },
17
- { bindingType: 'BANK', id: 3 },
18
- ],
19
- }
20
- }
21
- if (req.url === 'getConfig') {
22
- return { config: 'eyJib251c1ByZXZpZXdFbmFibGUiOnRydWV9' }
23
- }
24
- if (req.url === 'payment/v2/paymentDetail') {
25
- return [{ method: 'ignored' }, { method: 'vpay', optional: [100], minimum: 50, maximum: 500, grandTotalEnable: 1 }]
26
- }
27
- if (req.url === 'payment/v2/amb/getBankList') {
28
- return { data: [{ code: 'B1' }] }
29
- }
30
- if (req.url === 'payment/v2/vpay/checkTransaction') {
31
- return { qrcode: 'QR-OLD', amount: 321, vpayId: 'VP-OLD' }
32
- }
33
- if (req.url === 'payment/v2/vpay/bonus/preview') {
34
- return [{ bonus: 8 }]
35
- }
36
- if (req.url === 'payment/v2/vpay/transaction') {
37
- return { qrcode: 'QR-NEW', amount: 222, vpayId: 'VP-NEW' }
38
- }
39
- if (req.url === 'payment/v2/vpay/expected/result') {
40
- return { data: { expectedAmount: 111 } }
41
- }
42
- return {}
43
- },
44
- }
45
-
46
- global.window = { atob: (value) => Buffer.from(value, 'base64').toString('utf8') }
47
-
48
- const machine = vpayFactory(request)
49
- const { actions, guards, services } = machine.options
50
- const initial = machine.initialState.context
51
-
52
- const checkingCond = machine.config.states.checking.always[0].cond
53
- assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' } }), true)
54
- assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: false }, promotion: { activityNo: 'A1' } }), false)
55
- assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'none' } }), false)
56
-
57
- assert.equal(actions.setUserAccount.assignment(initial, { data: [{ account: 'u1' }] }).userAccount.account, 'u1')
58
- assert.equal(actions.setBonusPreview.assignment(initial, { data: [{ bonus: 7 }] }).bonusPreviewData[0].bonus, 7)
59
-
60
- const order = actions.setOrder.assignment(initial, { data: { amount: 99, qrcode: 'Q1', vpayId: 'V1' } })
61
- assert.equal(order.qrcode, 'Q1')
62
- assert.equal(order.vpayId, 'V1')
63
- assert.equal(order.calculatedAmount, 99)
64
-
65
- const previousOrder = actions.setPreviousOrder.assignment(initial, { data: { order: { amount: 88, qrcode: 'Q2', vpayId: 'V2' } } })
66
- assert.equal(previousOrder.qrcode, 'Q2')
67
- assert.equal(previousOrder.vpayId, 'V2')
68
- assert.equal(previousOrder.calculatedAmount, 88)
69
-
70
- const initFromData = actions.setInitialization.assignment(initial, {
71
- data: {
72
- siteConfig: { bonusPreviewEnable: true },
73
- housePayment: { optional: [100, 200], minimum: 50, maximum: 500, grandTotalEnable: 1 },
74
- bankList: { data: [{ code: 'B1' }] },
75
- },
76
- })
77
- assert.equal(initFromData.bankList[0].code, 'B1')
78
-
79
- const initFromArray = actions.setInitialization.assignment(initial, {
80
- data: {
81
- siteConfig: { bonusPreviewEnable: true },
82
- housePayment: { optional: [300], minimum: 10, maximum: 20, grandTotalEnable: 0 },
83
- bankList: [{ code: 'B2' }],
84
- },
85
- })
86
- assert.equal(initFromArray.bankList[0].code, 'B2')
87
-
88
- assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'P1' } }).promotion.activityNo, 'P1')
89
- assert.equal(actions.addAmount.assignment({ amount: 200, maximum: 250 }, { data: 80 }).amount, 250)
90
- assert.equal(actions.setAmount.assignment(initial, { data: 333 }).amount, 333)
91
-
92
- const calcFromV2 = actions.setCalculation.assignment(initial, { data: { data: { expectedAmount: 5 } } })
93
- assert.equal(calcFromV2.calculation.expectedAmount, 5)
94
-
95
- const calcLegacy = actions.setCalculation.assignment(initial, { data: { expectedAmount: 6 } })
96
- assert.equal(calcLegacy.calculation.expectedAmount, 6)
97
-
98
- assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
99
- const reset = actions.reset.assignment()
100
- assert.equal(reset.amount, 0)
101
- assert.equal(reset.calculation, null)
102
-
103
- assert.equal(guards.hasUserAccount(initial, { data: [] }), undefined)
104
- assert.equal(guards.hasUserAccount(initial, { data: [{ id: 9 }] }).id, 9)
105
- assert.equal(guards.hasPreviousOrder(initial, { data: { order: {} } }), undefined)
106
- assert.equal(guards.hasPreviousOrder(initial, { data: { order: { qrcode: 'X' } } }), 'X')
107
- assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 1 }), true)
108
- assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 0 }), false)
109
-
110
- const filtered = await services.fetchPaymentInfo(initial)
111
- assert.equal(filtered.length, 1)
112
- assert.equal(filtered[0].id, 3)
113
-
114
- const initialized = await services.initialize({ method: 'vpay' })
115
- assert.equal(initialized.siteConfig.bonusPreviewEnable, true)
116
- assert.equal(initialized.housePayment.method, 'vpay')
117
- assert.equal(initialized.bankList.data[0].code, 'B1')
118
- assert.equal(initialized.order.qrcode, 'QR-OLD')
119
-
120
- const bonusPreview = await services.fetchBonusPreview({ method: 'vpay', promotion: { activityNo: 'P100' } })
121
- assert.equal(bonusPreview[0].bonus, 8)
122
-
123
- const submitResult = await services.submitDeposit({ method: 'vpay', amount: 444, promotion: { activityNo: 'P9' } })
124
- assert.equal(submitResult.vpayId, 'VP-NEW')
125
-
126
- const calcResult = await services.fetchCalculation({ method: 'vpay', amount: '45', promotion: { activityNo: 'P8' } })
127
- assert.equal(calcResult.data.expectedAmount, 111)
128
-
129
- const bonusReq = sent.find((entry) => entry.url === 'payment/v2/vpay/bonus/preview')
130
- assert.equal(bonusReq.params.promotionsNo, 'P100')
131
-
132
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/vpay/transaction')
133
- assert.equal(submitReq.params.amount, 444)
134
- assert.equal(submitReq.params.promotionsNo, 'P9')
135
-
136
- const calcReq = sent.find((entry) => entry.url === 'payment/v2/vpay/expected/result')
137
- assert.equal(calcReq.params.amount, 45)
138
- assert.equal(calcReq.params.promotionsNo, 'P8')
139
-
140
- const paymentDetailReq = sent.find((entry) => entry.url === 'payment/v2/paymentDetail')
141
- assert.equal(paymentDetailReq.params.transferType, 'DEPOSIT')
142
- })
@@ -1,166 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import withdrawCryptoCashFactory from '../src/machine/withdraw/withdraw_crypto_cash.js'
5
-
6
- test('withdraw_crypto_cash covers actions, guards and services including otp flow', async () => {
7
- const sent = []
8
- const request = {
9
- send: async (req) => {
10
- sent.push(req)
11
- if (req.url === 'payment/v2/withdrawRule') {
12
- return { balance: 900 }
13
- }
14
- if (req.url === 'payment/v2/pendingOrder') {
15
- return [{ applyId: 'P-1' }]
16
- }
17
- if (req.url === 'payment/v2/withdraw_crypto_cash/expected/result') {
18
- return { data: { fee: 1 } }
19
- }
20
- if (req.url === 'payment/v2/withdraw_crypto_cash/transaction') {
21
- return { status: 'otp-verifying', requestId: 'RID-1', target: 'phone', ttl: 60 }
22
- }
23
- if (req.url === '/otpsso/reset') {
24
- return { requestId: 'RID-2', ttl: 30, target: 'phone' }
25
- }
26
- if (req.url === '/otpsso/acknowledge') {
27
- return { ok: true }
28
- }
29
- return {}
30
- },
31
- }
32
-
33
- const machine = withdrawCryptoCashFactory(request, {
34
- paymentDetail: [
35
- {
36
- transferType: 'withdraw',
37
- category: 'crypto',
38
- method: 'withdraw_crypto_cash',
39
- channel: 'USDT',
40
- minimum: 100,
41
- maximum: 1000,
42
- networkName: ['TRC20', 'ERC20'],
43
- networkOptional: ['TRON', 'ETH'],
44
- },
45
- ],
46
- })
47
-
48
- const { actions, guards, services } = machine.options
49
- const initial = machine.initialState.context
50
-
51
- const initData = actions.setInitData.assignment(initial, {
52
- data: {
53
- withdrawRule: { balance: 900 },
54
- processing: { applyId: 'P-1' },
55
- },
56
- })
57
- assert.equal(initData.withdrawRule.balance, 900)
58
- assert.equal(initData.selectedCrypto.method, 'withdraw_crypto_cash')
59
- assert.equal(initData.networks.length, 2)
60
- assert.equal(initData.selectedNetwork.value, 'TRC20')
61
- assert.equal(initData.processing.applyId, 'P-1')
62
-
63
- assert.equal(actions.setNetwork.assignment(initial, { data: { value: 'ERC20' } }).selectedNetwork.value, 'ERC20')
64
- assert.equal(actions.setAddress.assignment(initial, { data: 'ADDR' }).address, 'ADDR')
65
- assert.equal(actions.setAmount.assignment(initial, { data: 456 }).selectedAmount, 456)
66
-
67
- assert.equal(actions.setCalculation.assignment(initial, { data: { data: { fee: 2 } } }).calculation.fee, 2)
68
- assert.equal(actions.setCalculation.assignment(initial, { data: { fee: 3 } }).calculation.fee, 3)
69
-
70
- assert.equal(actions.resetCharge.assignment(initial, {}).charge, null)
71
- assert.equal(actions.setTransaction.assignment(initial, { data: { realAmount: 321 } }).realAmount, 321)
72
-
73
- const otpData = actions.setOtp.assignment(initial, {
74
- data: { requestId: 'RID-1', status: 'otp-verifying', target: 'phone', ttl: 60 },
75
- })
76
- assert.equal(otpData.requestId, 'RID-1')
77
- assert.equal(otpData.status, 'otp-verifying')
78
- assert.equal(otpData.target, 'phone')
79
- assert.equal(otpData.ttl, 60)
80
-
81
- assert.equal(actions.decreaseTtl.assignment({ ttl: 2 }, {}).ttl, 1)
82
- assert.equal(actions.decreaseTtl.assignment({ ttl: 0 }, {}).ttl, 0)
83
-
84
- const verification = actions.setVerificationData.assignment(initial, {
85
- data: { requestId: 'RID-2', ttl: 30, target: 'email' },
86
- })
87
- assert.equal(verification.requestId, 'RID-2')
88
- assert.equal(verification.ttl, 30)
89
- assert.equal(verification.target, 'email')
90
-
91
- assert.equal(actions.setAttachmentType.assignment(initial, { data: 'withdraw' }).attachmentType, 'withdraw')
92
- assert.equal(actions.setProcessing.assignment(initial, { data: { applyId: 'P-2' } }).processing.applyId, 'P-2')
93
-
94
- assert.equal(guards.isProcessing({ processing: null }), null)
95
- assert.equal(guards.isProcessing({ processing: { applyId: 'P-1' } }).applyId, 'P-1')
96
-
97
- assert.equal(
98
- guards.isCalculable({
99
- withdrawRule: { balance: 900 },
100
- selectedCrypto: { minimum: 100, maximum: 1000 },
101
- selectedNetwork: { value: 'TRC20' },
102
- selectedAmount: 800,
103
- }),
104
- true
105
- )
106
- assert.equal(
107
- guards.isCalculable({
108
- withdrawRule: { balance: 300 },
109
- selectedCrypto: { minimum: 100, maximum: 1000 },
110
- selectedNetwork: { value: 'TRC20' },
111
- selectedAmount: 350,
112
- }),
113
- false
114
- )
115
- assert.equal(guards.isOtpRequired({}, { data: { status: 'otp-verifying' } }), true)
116
- assert.equal(guards.isOtpRequired({}, { data: { status: 'done' } }), false)
117
-
118
- const fetchedInit = await services.fetchInitData(initial)
119
- assert.equal(fetchedInit.withdrawRule.balance, 900)
120
- assert.equal(fetchedInit.processing.applyId, 'P-1')
121
-
122
- const rule = await services.fetchWithdrawRule(initial)
123
- assert.equal(rule.balance, 900)
124
-
125
- const calc = await services.fetchCalculation({
126
- selectedCrypto: { method: 'withdraw_crypto_cash' },
127
- selectedNetwork: { value: 'TRC20' },
128
- selectedAmount: 222,
129
- })
130
- assert.equal(calc.data.fee, 1)
131
-
132
- const submit = await services.submitWithdraw({
133
- selectedCrypto: { method: 'withdraw_crypto_cash', channel: 'USDT' },
134
- selectedNetwork: { value: 'TRC20' },
135
- address: 'ADDR',
136
- selectedAmount: 333,
137
- })
138
- assert.equal(submit.status, 'otp-verifying')
139
-
140
- const reset = await services.resetOtp({ requestId: 'RID-1', target: 'phone' })
141
- assert.equal(reset.requestId, 'RID-2')
142
-
143
- const ack = await services.acknowledge({ requestId: 'RID-2', target: 'phone' }, { data: '123456' })
144
- assert.equal(ack.ok, true)
145
-
146
- const ruleReq = sent.find((entry) => entry.url === 'payment/v2/withdrawRule')
147
- assert.equal(ruleReq.params.walletType, 'CASH')
148
-
149
- const pendingReq = sent.find((entry) => entry.url === 'payment/v2/pendingOrder')
150
- assert.equal(pendingReq.params.transferType, 'WITHDRAW')
151
-
152
- const calcReq = sent.find((entry) => entry.url === 'payment/v2/withdraw_crypto_cash/expected/result')
153
- assert.equal(calcReq.params.amount, 222)
154
- assert.equal(calcReq.params.cryptoNetwork, 'TRC20')
155
-
156
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/withdraw_crypto_cash/transaction')
157
- assert.equal(submitReq.params.amount, 333)
158
- assert.equal(submitReq.params.cryptoCurrency, 'USDT')
159
- assert.equal(submitReq.params.targetAddress, 'ADDR')
160
-
161
- const resetReq = sent.find((entry) => entry.url === '/otpsso/reset')
162
- assert.equal(resetReq.params.requestId, 'RID-1')
163
-
164
- const ackReq = sent.find((entry) => entry.url === '/otpsso/acknowledge')
165
- assert.equal(ackReq.params.code, '123456')
166
- })
@@ -1,123 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import withdrawKrwayFactory from '../src/machine/withdraw/withdraw_krway.js'
5
-
6
- test('withdraw_krway covers actions, guards and services branches', async () => {
7
- const sent = []
8
- const request = {
9
- config: { appSecret: 'secret' },
10
- send: async (req) => {
11
- sent.push(req)
12
- if (req.url === 'payment/v2/paymentDetail') {
13
- return [
14
- {
15
- method: 'krway',
16
- minimum: 100,
17
- maximum: 5000,
18
- optional: [100, 200],
19
- processing: [{ applyId: 'P-1' }],
20
- },
21
- ]
22
- }
23
- if (req.url === 'payment/v2/paymentInfo') {
24
- return { bankInfo: [{ bankCode: 'KB', accountNumber: '123', branch: 'SE', holderName: 'Tony' }] }
25
- }
26
- if (req.url === 'payment/v2/withdrawRule') {
27
- return { enableWithdraw: true, balance: 900 }
28
- }
29
- if (req.url === 'payment/v2/krway/transaction') {
30
- return { applyId: 'A-1', balance: 800, realAmount: 100, charge: 1 }
31
- }
32
- if (req.url === 'payment/v2/withdrawCheck') {
33
- return { passDepositeLimit: true, passWithdrawCooldownTime: true, withdrawInServiceTime: true }
34
- }
35
- return {}
36
- },
37
- }
38
-
39
- const machine = withdrawKrwayFactory(request)
40
- const { actions, guards, services } = machine.options
41
- const setWithdrawCheck = machine.config.states.withdrawCheck.invoke.onDone[0].actions.assignment
42
- const initial = machine.initialState.context
43
-
44
- const paymentData = actions.setPaymentData.assignment(initial, {
45
- data: {
46
- paymentDetail: [{ minimum: 100, maximum: 5000, optional: [100], processing: [{ applyId: 'P-1' }] }],
47
- bankInfo: [{ bankCode: 'KB' }],
48
- },
49
- })
50
- assert.equal(paymentData.bank.bankCode, 'KB')
51
- assert.equal(paymentData.minimum, 100)
52
- assert.equal(paymentData.maximum, 5000)
53
- assert.equal(paymentData.options[0], 100)
54
- const paymentDataFallback = actions.setPaymentData.assignment(initial, {
55
- data: {
56
- paymentDetail: [],
57
- bankInfo: [],
58
- },
59
- })
60
- assert.equal(paymentDataFallback.bank, undefined)
61
- assert.equal(paymentDataFallback.minimum, undefined)
62
-
63
- const condition = actions.updateWithdrawCondition.assignment(initial, { data: { enableWithdraw: true, balance: 300 } })
64
- assert.equal(condition.enableWithdraw, true)
65
- assert.equal(condition.balance, 300)
66
-
67
- assert.equal(actions.addAmount.assignment({ amount: null }, { data: 5 }).amount, 5)
68
- assert.equal(actions.addAmount.assignment({ amount: '10.5' }, { data: '0.5' }).amount, 11)
69
- assert.equal(actions.setAmount.assignment(initial, { data: '123.45' }).amount, 123.45)
70
- assert.equal(actions.clearAmount.assignment(initial, {}).amount, null)
71
-
72
- const result = actions.setResult.assignment(initial, { data: { applyId: 'A-2', balance: 700, realAmount: 50, charge: 2 } })
73
- assert.equal(result.applyId, 'A-2')
74
- assert.equal(result.balance, 700)
75
- assert.equal(result.realAmount, 50)
76
- assert.equal(result.charge, 2)
77
-
78
- assert.equal(guards.haveProcessing({ paymentDetail: [{ processing: [{ id: 1 }] }] }), true)
79
- assert.equal(guards.haveProcessing({ paymentDetail: [{ processing: [] }] }), false)
80
-
81
- assert.equal(guards.isSubmittable({ amount: 1 }), true)
82
- assert.equal(guards.isSubmittable({ amount: 0 }), false)
83
-
84
- assert.equal(guards.isNotWithdrawable({ balance: 50, enableWithdraw: true, paymentDetail: [{ minimum: 100 }] }), true)
85
- assert.equal(guards.isNotWithdrawable({ balance: 150, enableWithdraw: false, paymentDetail: [{ minimum: 100 }] }), true)
86
- assert.equal(guards.isNotWithdrawable({ balance: 150, enableWithdraw: true, paymentDetail: [{ minimum: 100 }] }), false)
87
-
88
- assert.equal(guards.isNotWithdrawMinDepositAmount({ withdrawCheck: { passDepositeLimit: false } }), true)
89
- assert.equal(guards.isNotWithdrawMinDepositAmount({ withdrawCheck: { passDepositeLimit: true } }), false)
90
- assert.equal(guards.isNotWithdrawMinDepositAmount({ withdrawCheck: null }), true)
91
- assert.equal(guards.isPassWithdrawCooldownTime({ withdrawCheck: { passWithdrawCooldownTime: false } }), true)
92
- assert.equal(guards.isPassWithdrawCooldownTime({ withdrawCheck: { passWithdrawCooldownTime: true } }), false)
93
- assert.equal(guards.isPassWithdrawCooldownTime({ withdrawCheck: null }), true)
94
- assert.equal(guards.isNotWIthdrawServiceTime({ withdrawCheck: { withdrawInServiceTime: false } }), true)
95
- assert.equal(guards.isNotWIthdrawServiceTime({ withdrawCheck: { withdrawInServiceTime: true } }), false)
96
- assert.equal(guards.isNotWIthdrawServiceTime({ withdrawCheck: null }), true)
97
-
98
- const fetched = await services.fetchPaymentDetail(initial)
99
- assert.equal(fetched.paymentDetail[0].method, 'krway')
100
- assert.equal(fetched.bankInfo[0].bankCode, 'KB')
101
-
102
- const rules = await services.fetchWithdrawRules(initial)
103
- assert.equal(rules.enableWithdraw, true)
104
-
105
- const submit = await services.submitWithdraw({
106
- paymentDetail: [{ method: 'krway' }],
107
- amount: 100,
108
- bank: { bankCode: 'KB', accountNumber: '123', branch: 'SE', holderName: 'Tony' },
109
- })
110
- assert.equal(submit.applyId, 'A-1')
111
-
112
- const check = await services.withdrawCheck(initial)
113
- assert.equal(check.passDepositeLimit, true)
114
- assert.equal(setWithdrawCheck(initial, { data: { passDepositeLimit: true } }).withdrawCheck.passDepositeLimit, true)
115
-
116
- const ruleReq = sent.find((entry) => entry.url === 'payment/v2/withdrawRule')
117
- assert.equal(ruleReq.params.walletType, 'CASH')
118
-
119
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/krway/transaction')
120
- assert.equal(submitReq.params.amount, 100)
121
- assert.equal(submitReq.params.applyerBankCode, 'KB')
122
- assert.equal(submitReq.params.applyerAccountNumber, '123')
123
- })