@jetthai/cuora 1.1.488 → 2.0.0-beta.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 (212) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/BREAKING_CHANGES.md +9 -0
  3. package/CHANGELOG.md +3 -316
  4. package/README.md +15 -299
  5. package/package.json +5 -5
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/account.js +1 -0
  8. package/src/api/activity.js +39 -24
  9. package/src/api/auth.js +36 -5
  10. package/src/api/common.js +3 -5
  11. package/src/api/game.js +10 -0
  12. package/src/api/payment.js +55 -17
  13. package/src/api/user.js +16 -10
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +213 -0
  17. package/src/machine/activity/activity_cash.js +36 -84
  18. package/src/machine/activity/cash_rain_activity.js +1 -0
  19. package/src/machine/activity/continue_deposit_activity.js +1 -0
  20. package/src/machine/activity/deposit_activity.js +1 -0
  21. package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
  22. package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
  23. package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
  24. package/src/machine/activity/fafafa_activity.js +11 -0
  25. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  26. package/src/machine/activity/index.js +12 -0
  27. package/src/machine/activity/instant_rebate_activity.js +1 -0
  28. package/src/machine/activity/invite_friends_activity.js +115 -0
  29. package/src/machine/activity/jackpot.js +1 -0
  30. package/src/machine/activity/mini_game_activity.js +69 -0
  31. package/src/machine/activity/otp_verified_activity.js +1 -0
  32. package/src/machine/activity/ranking_activity.js +1 -0
  33. package/src/machine/activity/return_bonus_activity.js +155 -0
  34. package/src/machine/activity/roulette_activity_v2.js +1 -0
  35. package/src/machine/activity/sign_in_activity.js +1 -0
  36. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  37. package/src/machine/activity/specify_bets_activity.js +1 -0
  38. package/src/machine/activity/specify_turnover_activity.js +1 -0
  39. package/src/machine/activity/time_bomb_activity.js +1 -0
  40. package/src/machine/activity/vip_card_activity.js +1 -0
  41. package/src/machine/auth.js +112 -149
  42. package/src/machine/auth_otp_v2.js +178 -0
  43. package/src/machine/auth_otp_v3.js +22 -64
  44. package/src/machine/bank_binding.js +3 -2
  45. package/src/machine/bank_binding_amb.js +146 -0
  46. package/src/machine/bonus.js +76 -0
  47. package/src/machine/common.js +98 -14
  48. package/src/machine/deposit/amb.js +93 -0
  49. package/src/machine/deposit/crypto_bank.js +340 -0
  50. package/src/machine/deposit/crypto_bank_cash.js +35 -20
  51. package/src/machine/deposit/crypto_qrcode.js +158 -0
  52. package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
  53. package/src/machine/deposit/crypto_way.js +253 -0
  54. package/src/machine/deposit/crypto_way_cash.js +37 -48
  55. package/src/machine/deposit/deposit_fc.js +272 -0
  56. package/src/machine/deposit/direct.js +311 -0
  57. package/src/machine/deposit/direct_cash.js +10 -8
  58. package/src/machine/deposit/float.js +375 -0
  59. package/src/machine/deposit/index.js +28 -0
  60. package/src/machine/deposit/krway.js +152 -0
  61. package/src/machine/deposit/loadcard_cash.js +32 -14
  62. package/src/machine/deposit/loadcard_vn.js +352 -0
  63. package/src/machine/deposit/manual_cash.js +11 -8
  64. package/src/machine/deposit/manual_vn.js +459 -0
  65. package/src/machine/deposit/qrcode_cash.js +32 -15
  66. package/src/machine/deposit/qrcode_v2.js +339 -0
  67. package/src/machine/deposit/usdt.js +163 -0
  68. package/src/machine/deposit/usdt_cash.js +15 -1
  69. package/src/machine/deposit/virtual_bank_cash.js +12 -13
  70. package/src/machine/deposit/virtual_bank_vn.js +270 -0
  71. package/src/machine/deposit/vpay.js +374 -0
  72. package/src/machine/error.js +1 -7
  73. package/src/machine/game_betslip.js +1 -0
  74. package/src/machine/game_favorite_v2.js +1 -0
  75. package/src/machine/game_hot_new.js +80 -0
  76. package/src/machine/game_info.js +13 -1
  77. package/src/machine/game_replay.js +47 -0
  78. package/src/machine/game_search_cash.js +1 -0
  79. package/src/machine/game_search_v2.js +402 -0
  80. package/src/machine/game_v2_1.js +126 -39
  81. package/src/machine/honor_board.js +133 -0
  82. package/src/machine/honor_board_cash.js +28 -22
  83. package/src/machine/inbox.js +105 -43
  84. package/src/machine/index.js +32 -0
  85. package/src/machine/leaderboard.js +12 -8
  86. package/src/machine/merge.js +58 -0
  87. package/src/machine/navbar.js +3 -1
  88. package/src/machine/payment_data.js +87 -0
  89. package/src/machine/promotions.js +163 -0
  90. package/src/machine/ranking.js +30 -45
  91. package/src/machine/reward.js +256 -0
  92. package/src/machine/reward_cash.js +42 -2
  93. package/src/machine/reward_fc.js +99 -0
  94. package/src/machine/roulette_v2.js +11 -14
  95. package/src/machine/setting.js +1 -0
  96. package/src/machine/side.js +160 -0
  97. package/src/machine/side_cash.js +3 -3
  98. package/src/machine/side_v2.js +223 -0
  99. package/src/machine/user_info.js +1 -0
  100. package/src/machine/user_photo.js +1 -0
  101. package/src/machine/user_reset_password.js +14 -0
  102. package/src/machine/user_sign_up.js +61 -46
  103. package/src/machine/vip_table.js +58 -0
  104. package/src/machine/websocket.js +349 -374
  105. package/src/machine/welcome.js +111 -0
  106. package/src/machine/withdraw/index.js +6 -0
  107. package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
  108. package/src/machine/withdraw/withdraw_krway.js +223 -0
  109. package/src/machine/withdraw/withdraw_manual.js +541 -0
  110. package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
  111. package/src/request/config.js +0 -2
  112. package/src/request/request.js +60 -124
  113. package/src/util/constant.js +2 -6
  114. package/src/util/deviceToken.js +60 -0
  115. package/src/util/index.js +4 -2
  116. package/src/util/math.js +4 -0
  117. package/src/util/storage.js +4 -3
  118. package/test/api.behavior.test.js +69 -0
  119. package/test/api.contract.test.js +18 -0
  120. package/test/config.test.js +27 -0
  121. package/test/deviceToken.test.js +139 -0
  122. package/test/helpers.coverage.test.js +11 -0
  123. package/test/helpers.js +91 -0
  124. package/test/index.exports.test.js +14 -0
  125. package/test/machine.activity.core.coverage.test.js +337 -0
  126. package/test/machine.activity.gap.coverage.test.js +252 -0
  127. package/test/machine.activity.more.coverage.test.js +180 -0
  128. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  129. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  130. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  131. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  132. package/test/machine.auth.coverage.test.js +215 -0
  133. package/test/machine.bank_binding.test.js +143 -0
  134. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  135. package/test/machine.contract.test.js +50 -0
  136. package/test/machine.crypto_bank.coverage.test.js +270 -0
  137. package/test/machine.crypto_way.coverage.test.js +108 -0
  138. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  139. package/test/machine.definition.test.js +137 -0
  140. package/test/machine.deposit.manual.coverage.test.js +365 -0
  141. package/test/machine.deposit_fc.coverage.test.js +126 -0
  142. package/test/machine.direct.coverage.test.js +96 -0
  143. package/test/machine.direct_cash.coverage.test.js +108 -0
  144. package/test/machine.error.coverage.test.js +37 -0
  145. package/test/machine.events.test.js +126 -0
  146. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  147. package/test/machine.float.coverage.test.js +136 -0
  148. package/test/machine.flow.test.js +226 -0
  149. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  150. package/test/machine.game_search_cash.coverage.test.js +155 -0
  151. package/test/machine.game_search_v2.test.js +199 -0
  152. package/test/machine.game_user_profile.coverage.test.js +100 -0
  153. package/test/machine.honor_board.test.js +133 -0
  154. package/test/machine.inbox.common.coverage.test.js +304 -0
  155. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  156. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  157. package/test/machine.misc.coverage.test.js +361 -0
  158. package/test/machine.more2.coverage.test.js +261 -0
  159. package/test/machine.options.execution.test.js +272 -0
  160. package/test/machine.priority.coverage.test.js +603 -0
  161. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  162. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  163. package/test/machine.regression.test.js +82 -0
  164. package/test/machine.roulette_v2.test.js +142 -0
  165. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  166. package/test/machine.targeted.coverage.test.js +313 -0
  167. package/test/machine.usdt.coverage.test.js +95 -0
  168. package/test/machine.usdt_cash.coverage.test.js +73 -0
  169. package/test/machine.vip_card_activity.test.js +114 -0
  170. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  171. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  172. package/test/machine.vpay.coverage.test.js +142 -0
  173. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  174. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  175. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  176. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  177. package/test/request.test.js +325 -0
  178. package/test/util.storage.errors.test.js +47 -0
  179. package/test/util.test.js +41 -0
  180. package/.claude/commands/sync-ai-prompts.md +0 -93
  181. package/.claude/settings.local.json +0 -23
  182. package/.github/copilot-instructions.md +0 -448
  183. package/.husky/post-checkout +0 -32
  184. package/.husky/pre-push +0 -36
  185. package/AGENTS.md +0 -448
  186. package/AI_PROMPT_SOURCE.md +0 -446
  187. package/CLAUDE.md +0 -448
  188. package/GEMINI.md +0 -448
  189. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  190. package/docs/kibana/play-providerId-error.md +0 -202
  191. package/docs/kibana/play-selectedWalletType.md +0 -1
  192. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  193. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  194. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  195. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  196. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  197. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  198. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  199. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  200. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  201. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  202. package/scripts/auto-version.js +0 -68
  203. package/scripts/auto-version.sh +0 -33
  204. package/scripts/branch-auto-npm-publish.js +0 -29
  205. package/scripts/check-version.sh +0 -36
  206. package/scripts/clean-tags.sh +0 -84
  207. package/src/util/amount.js +0 -8
  208. package/src/util/err998SentryExtra.js +0 -26
  209. package/src/util/paramStore.js +0 -139
  210. package/src/util/socketPolicy.js +0 -57
  211. package/test/auth_otp_v3.test.js +0 -323
  212. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,365 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { State } from 'xstate'
4
+
5
+ import manualCashFactory from '../src/machine/deposit/manual_cash.js'
6
+ import manualVnFactory from '../src/machine/deposit/manual_vn.js'
7
+
8
+ test('manual_cash actions/guards/services map init, calculation and submit payloads', async () => {
9
+ const sent = []
10
+ const request = {
11
+ config: { appSecret: 'secret' },
12
+ send: async (req) => {
13
+ sent.push(req)
14
+ if (req.url === 'payment/v2/manual_cash/getBankList') {
15
+ return { data: [{ bankCode: 'H1', shortName: 'House 1', imageUrl: 'h1.png' }] }
16
+ }
17
+ if (req.url === 'payment/v2/getBindingPaymentInfo') {
18
+ return {
19
+ bankList: [
20
+ {
21
+ bankCode: 'U1',
22
+ accountNumber: '1234567890',
23
+ ifscCode: 'IFSC1',
24
+ holderName: 'Alice',
25
+ branch: 'Main',
26
+ branchCode: '001',
27
+ },
28
+ ],
29
+ }
30
+ }
31
+ if (req.url === 'payment/v2/pendingOrder') return [{ applyId: 99 }]
32
+ if (req.url === 'payment/v2/manual_cash/expected/result') return { bonus: 10 }
33
+ if (req.url === 'payment/v2/manual_cash/transaction') return { applyId: 1001 }
34
+ return {}
35
+ },
36
+ }
37
+
38
+ const machine = manualCashFactory(request, {
39
+ paymentDetail: [
40
+ {
41
+ category: 'manual',
42
+ transferType: 'deposit',
43
+ method: 'manual_cash',
44
+ minimum: 100,
45
+ maximum: 5000,
46
+ banks: [{ bankName: 'H1', accountNumber: '98765', ifscCode: 'HIFSC', upi: 'abc@upi' }],
47
+ },
48
+ ],
49
+ promotion: { promotionsNo: 'P01', minimumAmount: 200 },
50
+ selectedAmount: 50,
51
+ })
52
+
53
+ const { actions, guards, services } = machine.options
54
+
55
+ const init = actions.setInitData.assignment(machine.initialState.context, {
56
+ data: {
57
+ currentPayment: {
58
+ method: 'manual_cash',
59
+ minimum: 100,
60
+ maximum: 5000,
61
+ banks: [{ bankName: 'H1', accountNumber: '98765', ifscCode: 'HIFSC', upi: 'abc@upi' }],
62
+ },
63
+ bankList: {
64
+ data: [
65
+ { bankCode: 'H1', shortName: 'House 1', imageUrl: 'h1.png' },
66
+ { bankCode: 'U1', shortName: 'User 1', imageUrl: 'u1.png' },
67
+ ],
68
+ },
69
+ bindingPaymentInfo: {
70
+ bankList: [
71
+ {
72
+ bankCode: 'U1',
73
+ accountNumber: '1234567890',
74
+ ifscCode: 'IFSC1',
75
+ holderName: 'Alice',
76
+ branch: 'Main',
77
+ branchCode: '001',
78
+ },
79
+ ],
80
+ },
81
+ processing: { applyId: 8 },
82
+ },
83
+ })
84
+ assert.equal(init.method, 'manual_cash')
85
+ assert.equal(init.selectedAmount, 200)
86
+ assert.equal(init.houseBanks[0].displayText, 'House 1')
87
+ assert.equal(init.userBanks[0].displayText.includes('67890'), true)
88
+
89
+ const initWithArrayBanks = actions.setInitData.assignment(machine.initialState.context, {
90
+ data: {
91
+ currentPayment: {
92
+ method: 'manual_cash',
93
+ minimum: 10,
94
+ maximum: 50,
95
+ banks: [{ bankName: 'H1', accountNumber: '98765', ifscCode: 'HIFSC', upi: 'abc@upi' }],
96
+ },
97
+ bankList: [{ bankCode: 'H1', shortName: 'House 1', imageUrl: 'h1.png' }],
98
+ bindingPaymentInfo: { bankList: [] },
99
+ processing: null,
100
+ },
101
+ })
102
+ assert.equal(initWithArrayBanks.userBanks[0].displayText, 'House 1')
103
+
104
+ assert.equal(actions.setHouseBank.assignment(machine.initialState.context, { data: { bankName: 'HX' } }).selectedHouseBank.bankName, 'HX')
105
+ assert.equal(actions.inputAmount.assignment(machine.initialState.context, { data: 321 }).selectedAmount, 321)
106
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { a: 1 } } }).calculation, { a: 1 })
107
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { b: 2 } }).calculation, { b: 2 })
108
+ assert.equal(actions.setProcessing.assignment(machine.initialState.context, { data: { applyId: 1 } }).processing.applyId, 1)
109
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
110
+
111
+ const selectedUserBank = {
112
+ bankCode: 'U1',
113
+ accountNumber: '111',
114
+ ifscCode: 'I1',
115
+ holderName: 'N1',
116
+ branch: 'B1',
117
+ branchCode: 'BC1',
118
+ }
119
+ const userBankState = actions.setUserBank.assignment(machine.initialState.context, { data: selectedUserBank })
120
+ assert.equal(userBankState.userAccountNumber, '111')
121
+ assert.equal(actions.setUserAccountBranchName.assignment(machine.initialState.context, { data: 'Branch X' }).userAccountBranchName, 'Branch X')
122
+ assert.equal(actions.setUserAccountBranchCode.assignment(machine.initialState.context, { data: '007' }).userAccountBranchCode, '007')
123
+ assert.equal(actions.setUserAccountNumber.assignment(machine.initialState.context, { data: '222' }).userAccountNumber, '222')
124
+ assert.equal(actions.setUserIfscCode.assignment(machine.initialState.context, { data: 'IFSC2' }).userIfscCode, 'IFSC2')
125
+ assert.equal(actions.setUserAccountName.assignment(machine.initialState.context, { data: 'Bob' }).userAccountName, 'Bob')
126
+ assert.equal(actions.setTransactionId.assignment(machine.initialState.context, { data: 'TX1' }).transactionId, 'TX1')
127
+ assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: '2026-01-01 10:00:00' }).depositTime, '2026-01-01 10:00:00')
128
+ assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'img-base64' }).receipt, 'img-base64')
129
+ assert.equal(actions.setPromotion.assignment(machine.initialState.context, { data: { promotionsNo: 'P02' } }).promotion.promotionsNo, 'P02')
130
+
131
+ assert.equal(guards.isCalculable({ selectedAmount: '300', currentPayment: { minimum: 100, maximum: 500 } }), true)
132
+ assert.equal(guards.isCalculable({ selectedAmount: '99', currentPayment: { minimum: 100, maximum: 500 } }), false)
133
+ assert.deepEqual(guards.isProcessing({ processing: { applyId: 3 } }), { applyId: 3 })
134
+ assert.equal(guards.isProcessing({ processing: null }), null)
135
+
136
+ const initData = await services.fetchInitData(
137
+ {
138
+ ...machine.initialState.context,
139
+ paymentDetail: [
140
+ { category: 'manual', transferType: 'deposit', method: 'manual_cash' },
141
+ { category: 'manual', transferType: 'withdraw', method: 'other' },
142
+ ],
143
+ currentCategory: 'manual',
144
+ },
145
+ {}
146
+ )
147
+ assert.equal(initData.currentPayment.method, 'manual_cash')
148
+ assert.equal(initData.processing.applyId, 99)
149
+
150
+ const calc = await services.fetchCalculation({ method: 'manual_cash', selectedAmount: '555', promotion: { promotionsNo: 'P03' } }, {})
151
+ assert.equal(calc.bonus, 10)
152
+
153
+ const submitted = await services.submitDeposit(
154
+ {
155
+ method: 'manual_cash',
156
+ selectedAmount: 666,
157
+ selectedHouseBank: { bankName: 'H1', accountNumber: 'HACC', ifscCode: 'HIFSC', upi: 'h@upi' },
158
+ selectedUserBank: { bankCode: 'U1' },
159
+ userAccountNumber: 'UACC',
160
+ userIfscCode: 'UIFSC',
161
+ userAccountName: 'UName',
162
+ userAccountBranchName: 'UBranch',
163
+ userAccountBranchCode: 'UBC',
164
+ transactionId: 'TX999',
165
+ depositTime: '2026-01-01 12:30:00',
166
+ receipt: 'receipt-data',
167
+ promotion: { promotionsNo: 'P04' },
168
+ },
169
+ {}
170
+ )
171
+ assert.equal(submitted.applyId, 1001)
172
+
173
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/manual_cash/transaction')
174
+ assert.equal(submitReq.params.promotionsNo, 'P04')
175
+ assert.equal(submitReq.params.targetBankCode, 'H1')
176
+ assert.equal(submitReq.params.applyerAccountNumber, 'UACC')
177
+ })
178
+
179
+ test('manual_vn actions/guards/services cover branch mapping and promotions', async () => {
180
+ const sent = []
181
+ const request = {
182
+ config: { appSecret: 'secret' },
183
+ send: async (req) => {
184
+ sent.push(req)
185
+ if (req.url === 'payment/v2/paymentDetail') {
186
+ return [
187
+ {
188
+ category: 'manual',
189
+ method: 'manual_vn',
190
+ minimum: 100,
191
+ maximum: 5000,
192
+ processing: [{ applyId: 77 }],
193
+ banks: [{ bankName: 'H1', accountNumber: '98765', ifscCode: 'HIFSC', upi: 'abc@upi' }],
194
+ },
195
+ ]
196
+ }
197
+ if (req.url === 'payment/v2/getBindingPaymentInfo') {
198
+ return {
199
+ bankList: [
200
+ {
201
+ bankCode: 'U1',
202
+ accountNumber: '1234567890',
203
+ ifscCode: 'IFSC1',
204
+ holderName: 'Alice',
205
+ branch: 'Main',
206
+ branchCode: '001',
207
+ },
208
+ ],
209
+ }
210
+ }
211
+ if (req.url === 'payment/v2/getBindingPaymentList') {
212
+ return {
213
+ bankList: [
214
+ { bankCode: 'H1', shortName: 'House 1', imageUrl: 'h1.png' },
215
+ { bankCode: 'U1', shortName: 'User 1', imageUrl: 'u1.png' },
216
+ ],
217
+ }
218
+ }
219
+ if (req.url === 'payment/v2/manual_vn/expected/result') return { data: { bonus: 88 } }
220
+ if (req.url === 'payment/v2/manual_vn/transaction') return { applyId: 2026 }
221
+ return {}
222
+ },
223
+ }
224
+
225
+ const machine = manualVnFactory(request)
226
+ const { actions, guards, services } = machine.options
227
+
228
+ const toPending = machine.transition(
229
+ State.from('checking', {
230
+ ...machine.initialState.context,
231
+ calculation: { bonus: 10 },
232
+ promotion: { promotionsNo: 'P01', activityNo: 'A01' },
233
+ }),
234
+ { type: 'xstate.init' }
235
+ )
236
+ assert.equal(toPending.value, 'pending')
237
+
238
+ const toStep2 = machine.transition(
239
+ State.from('checking', {
240
+ ...machine.initialState.context,
241
+ calculation: { bonus: 10 },
242
+ promotion: { promotionsNo: 'none', activityNo: 'A01' },
243
+ }),
244
+ { type: 'xstate.init' }
245
+ )
246
+ assert.deepEqual(toStep2.value, { step2: 'idle' })
247
+
248
+ const init = actions.setInitData.assignment(machine.initialState.context, {
249
+ data: [
250
+ {
251
+ category: 'manual',
252
+ method: 'manual_vn',
253
+ processing: [{ applyId: 77 }],
254
+ banks: [{ bankName: 'H1', accountNumber: '98765', ifscCode: 'HIFSC', upi: 'abc@upi' }],
255
+ },
256
+ ],
257
+ })
258
+ assert.equal(init.method, 'manual_vn')
259
+ assert.equal(init.houseBanks[0].bankCode, 'H1')
260
+ assert.equal(init.processing.applyId, 77)
261
+
262
+ const banksState = actions.setBanks.assignment(
263
+ {
264
+ ...machine.initialState.context,
265
+ currentPayment: { banks: [{ bankName: 'H1' }] },
266
+ houseBanks: [{ bankName: 'H1' }],
267
+ selectedHouseBank: { bankName: 'H1' },
268
+ },
269
+ {
270
+ data: {
271
+ bindingPaymentInfo: {
272
+ bankList: [
273
+ {
274
+ bankCode: 'U1',
275
+ accountNumber: '1234567890',
276
+ ifscCode: 'IFSC1',
277
+ holderName: 'Alice',
278
+ branch: 'Main',
279
+ branchCode: '001',
280
+ },
281
+ ],
282
+ },
283
+ bindingPaymentList: {
284
+ bankList: [
285
+ { bankCode: 'H1', shortName: 'House 1', imageUrl: 'h1.png' },
286
+ { bankCode: 'U1', shortName: 'User 1', imageUrl: 'u1.png' },
287
+ ],
288
+ },
289
+ },
290
+ }
291
+ )
292
+ assert.equal(banksState.playerBanks[0].shortName.includes('67890'), true)
293
+ assert.equal(banksState.selectedHouseBank.shortName, 'House 1')
294
+ assert.equal(banksState.userAccountName, 'Alice')
295
+
296
+ assert.equal(actions.setHouseBank.assignment(machine.initialState.context, { data: { bankName: 'HX' } }).selectedHouseBank.bankName, 'HX')
297
+ assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: 345 }).amount, 345)
298
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { a: 1 } } }).calculation, { a: 1 })
299
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { b: 2 } }).calculation, { b: 2 })
300
+ assert.equal(actions.setProcessing.assignment(machine.initialState.context, { data: { applyId: 1 } }).processing.applyId, 1)
301
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
302
+
303
+ const selectedUserBank = {
304
+ bankCode: 'U1',
305
+ accountNumber: '111',
306
+ ifscCode: 'I1',
307
+ holderName: 'N1',
308
+ branch: 'B1',
309
+ branchCode: 'BC1',
310
+ }
311
+ const userBankState = actions.setUserBank.assignment(machine.initialState.context, { data: selectedUserBank })
312
+ assert.equal(userBankState.userAccountNumber, '111')
313
+ assert.equal(actions.setUserAccountBranchName.assignment(machine.initialState.context, { data: 'Branch X' }).userAccountBranchName, 'Branch X')
314
+ assert.equal(actions.setUserAccountBranchCode.assignment(machine.initialState.context, { data: '007' }).userAccountBranchCode, '007')
315
+ assert.equal(actions.setUserAccountNumber.assignment(machine.initialState.context, { data: '222' }).userAccountNumber, '222')
316
+ assert.equal(actions.setUserIfscCode.assignment(machine.initialState.context, { data: 'IFSC2' }).userIfscCode, 'IFSC2')
317
+ assert.equal(actions.setUserAccountName.assignment(machine.initialState.context, { data: 'Bob' }).userAccountName, 'Bob')
318
+ assert.equal(actions.setTransactionId.assignment(machine.initialState.context, { data: 'TX1' }).transactionId, 'TX1')
319
+ assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: '2026-01-01 10:00:00' }).depositTime, '2026-01-01 10:00:00')
320
+ assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'img-base64' }).receipt, 'img-base64')
321
+ assert.equal(actions.setPromotion.assignment(machine.initialState.context, { data: { activityNo: 'A01' } }).promotion.activityNo, 'A01')
322
+ assert.equal(actions.setPromotionDefaultAmount.assignment({ promotion: { minimumAmount: 777 } }, {}).amount, 777)
323
+
324
+ assert.equal(guards.isCalculable({ amount: '300', currentPayment: { minimum: 100, maximum: 500 } }), true)
325
+ assert.equal(guards.isCalculable({ amount: '99', currentPayment: { minimum: 100, maximum: 500 } }), false)
326
+ assert.deepEqual(guards.isCalculated({ calculation: { bonus: 1 } }), { bonus: 1 })
327
+ assert.equal(guards.isCalculated({ calculation: null }), null)
328
+ assert.deepEqual(guards.isProcessing({ processing: { applyId: 3 } }), { applyId: 3 })
329
+ assert.equal(guards.hasMinPromotionDeposit({ promotion: { minimumAmount: 123 } }), 123)
330
+ assert.equal(guards.hasMinPromotionDeposit({ promotion: null }), undefined)
331
+
332
+ const detail = await services.fetchPaymentDetail({}, {})
333
+ assert.equal(Array.isArray(detail), true)
334
+
335
+ const banks = await services.fetchBanks({}, {})
336
+ assert.equal(Array.isArray(banks.bindingPaymentList.bankList), true)
337
+
338
+ const calc = await services.fetchCalculation({ method: 'manual_vn', amount: '123', promotion: { activityNo: 'ACT1' } }, {})
339
+ assert.equal(calc.data.bonus, 88)
340
+
341
+ const submitted = await services.submitDeposit(
342
+ {
343
+ method: 'manual_vn',
344
+ amount: 456,
345
+ selectedHouseBank: { bankName: 'H1', accountNumber: 'HACC', ifscCode: 'HIFSC', upi: 'h@upi' },
346
+ selectedUserBank: { bankCode: 'U1' },
347
+ userAccountNumber: 'UACC',
348
+ userIfscCode: 'UIFSC',
349
+ userAccountName: 'UName',
350
+ userAccountBranchName: 'UBranch',
351
+ userAccountBranchCode: 'UBC',
352
+ transactionId: 'TX999',
353
+ depositTime: '2026-01-01 12:30:00',
354
+ receipt: 'receipt-data',
355
+ promotion: { activityNo: 'ACT2' },
356
+ },
357
+ {}
358
+ )
359
+ assert.equal(submitted.applyId, 2026)
360
+
361
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/manual_vn/transaction')
362
+ assert.equal(submitReq.params.promotionsNo, 'ACT2')
363
+ assert.equal(submitReq.params.targetBankCode, 'H1')
364
+ assert.equal(submitReq.params.applyerAccountNumber, 'UACC')
365
+ })
@@ -0,0 +1,126 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import depositFcFactory from '../src/machine/deposit/deposit_fc.js'
5
+
6
+ test('deposit_fc covers actions, guards and services request mapping', async () => {
7
+ const sent = []
8
+ const request = {
9
+ send: async (req) => {
10
+ sent.push(req)
11
+ if (req.url === 'payment/v2/paymentInfo') {
12
+ return { bonus: 1 }
13
+ }
14
+ if (req.url === 'payment/v2/paymentDetail') {
15
+ return [
16
+ {
17
+ method: 'crypto_deposit',
18
+ channel: 'USDT',
19
+ networkName: ['TRC20', 'ERC20'],
20
+ networkOptional: ['TRON', 'ETH'],
21
+ },
22
+ ]
23
+ }
24
+ if (req.url === 'payment/v2/crypto_deposit/expected/result') {
25
+ return { data: { actualAmount: 321 } }
26
+ }
27
+ if (req.url === 'payment/v2/crypto_deposit/transaction') {
28
+ return { applyId: 'AP-1' }
29
+ }
30
+ if (req.url === 'payment/v2/setting') {
31
+ return { ok: true }
32
+ }
33
+ return {}
34
+ },
35
+ }
36
+
37
+ const machine = depositFcFactory(request)
38
+ const { actions, guards, services } = machine.options
39
+ const initial = machine.initialState.context
40
+
41
+ const setCryptos = actions.setCryptos.assignment(initial, {
42
+ data: [{ method: 'crypto_deposit', channel: 'USDT', networkName: ['TRC20'], networkOptional: ['TRON'] }],
43
+ })
44
+ assert.equal(setCryptos.cryptos[0].label, 'USDT')
45
+ assert.equal(setCryptos.cryptos[0].value, 'crypto_deposit')
46
+ assert.equal(setCryptos.cryptos[0].icon, 'USDT')
47
+
48
+ const setCrypto = actions.setCrypto.assignment(
49
+ {
50
+ ...initial,
51
+ cryptos: [{ method: 'crypto_deposit', networkName: ['TRC20', 'ERC20'], networkOptional: ['TRON', 'ETH'] }],
52
+ currentNetwork: { value: 'OLD' },
53
+ currentAmount: 99,
54
+ calculatedResult: { actualAmount: 99 },
55
+ },
56
+ { data: { value: 'crypto_deposit' } }
57
+ )
58
+ assert.equal(setCrypto.currentCrypto.value, 'crypto_deposit')
59
+ assert.equal(setCrypto.networks.length, 2)
60
+ assert.equal(setCrypto.currentNetwork, null)
61
+ assert.equal(setCrypto.currentAmount, null)
62
+ assert.equal(setCrypto.calculatedResult, null)
63
+
64
+ const setCryptoNoNetwork = actions.setCrypto.assignment(
65
+ { ...initial, cryptos: [{ method: 'crypto_deposit', networkName: [], networkOptional: [] }], currentNetwork: null },
66
+ { data: { value: 'crypto_deposit' } }
67
+ )
68
+ assert.equal(setCryptoNoNetwork.networks.length, 0)
69
+
70
+ assert.equal(actions.setNetwork.assignment(initial, { data: { value: 'TRC20' } }).currentNetwork.value, 'TRC20')
71
+
72
+ assert.equal(actions.setAmount.assignment(initial, { data: 777 }).currentAmount, 777)
73
+ assert.equal(actions.setAmount.assignment({ calculatedResult: { actualAmount: 1 } }, { data: 0 }).calculatedResult, null)
74
+
75
+ assert.equal(actions.setCalculatedResult.assignment(initial, { data: { data: { actualAmount: 11 } } }).calculatedResult.actualAmount, 11)
76
+ assert.equal(actions.setCalculatedResult.assignment(initial, { data: { actualAmount: 12 } }).calculatedResult.actualAmount, 12)
77
+
78
+ assert.equal(actions.setSubmittedResult.assignment(initial, { data: { applyId: 'AP-2' } }).submittedResult.applyId, 'AP-2')
79
+ assert.equal(actions.clearCalculatedResult.assignment({ calculatedResult: { x: 1 } }, {}).calculatedResult, null)
80
+
81
+ assert.equal(actions.toggleBonus.assignment({ bonus: 1 }, {}).bonus, 0)
82
+ assert.equal(actions.toggleBonus.assignment({ bonus: 0 }, {}).bonus, 1)
83
+ assert.equal(actions.setBonus.assignment(initial, { data: 1 }).bonus, 1)
84
+
85
+ assert.equal(guards.hasCryptoOptions({ cryptos: [] }), false)
86
+ assert.equal(guards.hasCryptoOptions({ cryptos: [{}] }), true)
87
+ assert.equal(guards.hasNetworkOptions({ networks: [] }), false)
88
+ assert.equal(guards.hasNetworkOptions({ networks: [{}] }), true)
89
+ assert.equal(guards.isCalculable({ currentCrypto: {}, currentNetwork: {}, currentAmount: '0' }), 0)
90
+ assert.equal(guards.isCalculable({ currentCrypto: {}, currentNetwork: {}, currentAmount: '10' }), 10)
91
+ assert.equal(guards.isSubmittable({ calculatedResult: null }), null)
92
+ assert.equal(guards.isSubmittable({ calculatedResult: { actualAmount: 1 } }).actualAmount, 1)
93
+ assert.equal(guards.isBonusOff({ bonus: 1 }), false)
94
+ assert.equal(guards.isBonusOff({ bonus: 0 }), true)
95
+
96
+ const payments = await services.fetchPayments(initial)
97
+ assert.equal(payments[0].method, 'crypto_deposit')
98
+
99
+ const calc = await services.fetchCalculation({ currentCrypto: { method: 'crypto_deposit', channel: 'USDT' }, currentAmount: '123' })
100
+ assert.equal(calc.data.actualAmount, 321)
101
+
102
+ const submit = await services.submitDeposit({
103
+ currentCrypto: { method: 'crypto_deposit', channel: 'USDT' },
104
+ currentNetwork: { value: 'TRC20' },
105
+ calculatedResult: { actualAmount: 456 },
106
+ })
107
+ assert.equal(submit.applyId, 'AP-1')
108
+
109
+ await services.setBonusSetting({ bonus: 0 })
110
+ const bonusValue = await services.getPaymentInfo(initial)
111
+ assert.equal(bonusValue, 1)
112
+
113
+ const detailReq = sent.find((entry) => entry.url === 'payment/v2/paymentDetail')
114
+ assert.equal(detailReq.params.transferType, 'DEPOSIT')
115
+
116
+ const calcReq = sent.find((entry) => entry.url === 'payment/v2/crypto_deposit/expected/result')
117
+ assert.equal(calcReq.params.amount, 123)
118
+ assert.equal(calcReq.params.cryptoCurrency, 'USDT')
119
+
120
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_deposit/transaction')
121
+ assert.equal(submitReq.params.amount, 456)
122
+ assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
123
+
124
+ const settingReq = sent.find((entry) => entry.url === 'payment/v2/setting')
125
+ assert.equal(settingReq.params.bonus, 0)
126
+ })
@@ -0,0 +1,96 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import directFactory from '../src/machine/deposit/direct.js'
5
+
6
+ test('direct actions/guards/services cover init, promotion, calculation and submit mapping', async () => {
7
+ global.window = {
8
+ atob: (value) => Buffer.from(value, 'base64').toString('utf8'),
9
+ }
10
+
11
+ const sent = []
12
+ const request = {
13
+ config: { appSecret: 'secret' },
14
+ send: async (req) => {
15
+ sent.push(req)
16
+ if (req.url === 'getConfig') {
17
+ return { config: Buffer.from(JSON.stringify({ env: 'prod' })).toString('base64') }
18
+ }
19
+ if (req.url === 'payment/v2/paymentDetail') {
20
+ return [
21
+ { category: 'direct', method: 'direct_1', minimum: 50, maximum: 5000 },
22
+ { category: 'direct', method: 'direct_2', minimum: 100, maximum: 8000 },
23
+ ]
24
+ }
25
+ if (req.url === 'payment/v2/direct_1/getBankList') {
26
+ return { data: [{ bankCode: 'B1' }, { bankCode: 'B2' }] }
27
+ }
28
+ if (req.url === 'payment/v2/direct_1/expected/result') return { data: { bonus: 9 } }
29
+ if (req.url === 'payment/v2/direct_1/transaction') return { applyId: 777 }
30
+ return {}
31
+ },
32
+ }
33
+
34
+ const machine = directFactory(request)
35
+ const { actions, guards, services } = machine.options
36
+
37
+ const reset = actions.reset.assignment({ banks: [{ bankCode: 'B1' }] }, {})
38
+ assert.equal(reset.selectedBank.bankCode, 'B1')
39
+ assert.equal(reset.amount, null)
40
+
41
+ const init = actions.setInitData.assignment(machine.initialState.context, {
42
+ data: {
43
+ siteConfig: { env: 'prod' },
44
+ paymentDetail: [
45
+ { category: 'direct', method: 'direct_1', minimum: 50, maximum: 5000 },
46
+ { category: 'direct', method: 'direct_2', minimum: 100, maximum: 8000 },
47
+ ],
48
+ },
49
+ })
50
+ assert.equal(init.siteConfig.env, 'prod')
51
+ assert.equal(init.directs.length, 2)
52
+ assert.equal(init.currentMethod, 'direct_1')
53
+
54
+ const banksFromObject = actions.setBanks.assignment(machine.initialState.context, { data: { data: [{ bankCode: 'B1' }] } })
55
+ assert.equal(banksFromObject.selectedBank.bankCode, 'B1')
56
+ const banksFromArray = actions.setBanks.assignment(machine.initialState.context, { data: [{ bankCode: 'B2' }] })
57
+ assert.equal(banksFromArray.selectedBank.bankCode, 'B2')
58
+
59
+ const setDirect = actions.setDirect.assignment(machine.initialState.context, { data: { method: 'direct_2' } })
60
+ assert.equal(setDirect.currentMethod, 'direct_2')
61
+
62
+ assert.equal(actions.setSelectedBank.assignment(machine.initialState.context, { data: { bankCode: 'B9' } }).selectedBank.bankCode, 'B9')
63
+ assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: '321' }).amount, '321')
64
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { a: 1 } } }).calculation, { a: 1 })
65
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { b: 2 } }).calculation, { b: 2 })
66
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
67
+ assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
68
+ assert.equal(actions.setPromotion.assignment(machine.initialState.context, { data: { activityNo: 'A1' } }).promotion.activityNo, 'A1')
69
+ assert.equal(actions.setPromotionDefaultAmount.assignment({ promotion: { minimumAmount: 222 } }, {}).amount, 222)
70
+
71
+ assert.equal(guards.isCalculable({ amount: '100', currentDirect: { minimum: 50, maximum: 500 } }), true)
72
+ assert.equal(guards.isCalculable({ amount: '10', currentDirect: { minimum: 50, maximum: 500 } }), false)
73
+ assert.equal(guards.isSubmittable({ amount: '100', currentMethod: 'direct_1', selectedBank: { bankCode: 'B1' } }), 'B1')
74
+ assert.equal(guards.isSubmittable({ amount: '100', currentMethod: null, selectedBank: { bankCode: 'B1' } }), null)
75
+ assert.equal(guards.hasMinPromotionDeposit({ promotion: { minimumAmount: 333 } }), 333)
76
+
77
+ const initData = await services.fetchInitData({}, {})
78
+ assert.equal(initData.siteConfig.env, 'prod')
79
+ assert.equal(initData.paymentDetail.length, 2)
80
+
81
+ const bankList = await services.fetchBanksList({ currentDirect: { method: 'direct_1' } }, {})
82
+ assert.equal(bankList.data.length, 2)
83
+
84
+ const calc = await services.fetchCalculation({ currentMethod: 'direct_1', amount: '500', promotion: { activityNo: 'ACT1' } }, {})
85
+ assert.equal(calc.data.bonus, 9)
86
+
87
+ const submitted = await services.submitDeposit(
88
+ { currentMethod: 'direct_1', amount: 600, selectedBank: { bankCode: 'B1' }, promotion: { activityNo: 'ACT2' } },
89
+ {}
90
+ )
91
+ assert.equal(submitted.applyId, 777)
92
+
93
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/direct_1/transaction')
94
+ assert.equal(submitReq.params.applyerBankCode, 'B1')
95
+ assert.equal(submitReq.params.promotionsNo, 'ACT2')
96
+ })