@jetthai/cuora 1.2.0 → 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 (166) hide show
  1. package/BREAKING_CHANGES.md +9 -0
  2. package/CHANGELOG.md +36 -0
  3. package/package.json +5 -2
  4. package/resetGitBranch.sh +16 -16
  5. package/src/api/account.js +8 -0
  6. package/src/api/auth.js +1 -1
  7. package/src/api/common.js +6 -1
  8. package/src/api/index.js +3 -1
  9. package/src/api/otp.js +5 -0
  10. package/src/api/user.js +1 -0
  11. package/src/machine/activity/activity.js +23 -19
  12. package/src/machine/activity/activity_cash.js +27 -22
  13. package/src/machine/activity/cash_rain_activity.js +1 -0
  14. package/src/machine/activity/continue_deposit_activity.js +1 -0
  15. package/src/machine/activity/deposit_activity.js +1 -0
  16. package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
  17. package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
  19. package/src/machine/activity/fafafa_activity.js +1 -0
  20. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  21. package/src/machine/activity/instant_rebate_activity.js +1 -0
  22. package/src/machine/activity/invite_friends_activity.js +1 -0
  23. package/src/machine/activity/jackpot.js +1 -0
  24. package/src/machine/activity/mini_game_activity.js +1 -0
  25. package/src/machine/activity/otp_verified_activity.js +1 -0
  26. package/src/machine/activity/ranking_activity.js +1 -0
  27. package/src/machine/activity/return_bonus_activity.js +3 -1
  28. package/src/machine/activity/roulette_activity_v2.js +6 -0
  29. package/src/machine/activity/sign_in_activity.js +1 -0
  30. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  31. package/src/machine/activity/specify_bets_activity.js +1 -0
  32. package/src/machine/activity/specify_turnover_activity.js +1 -0
  33. package/src/machine/activity/time_bomb_activity.js +1 -0
  34. package/src/machine/activity/vip_card_activity.js +1 -0
  35. package/src/machine/auth.js +18 -6
  36. package/src/machine/auth_otp_v2.js +1 -0
  37. package/src/machine/auth_otp_v3.js +48 -11
  38. package/src/machine/bank_binding.js +1 -0
  39. package/src/machine/bank_binding_amb.js +1 -0
  40. package/src/machine/bonus.js +1 -0
  41. package/src/machine/common.js +24 -4
  42. package/src/machine/deposit/amb.js +1 -0
  43. package/src/machine/deposit/crypto_bank.js +20 -5
  44. package/src/machine/deposit/crypto_bank_cash.js +35 -9
  45. package/src/machine/deposit/crypto_qrcode.js +11 -1
  46. package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
  47. package/src/machine/deposit/crypto_way.js +11 -5
  48. package/src/machine/deposit/crypto_way_cash.js +15 -6
  49. package/src/machine/deposit/deposit_fc.js +1 -0
  50. package/src/machine/deposit/direct.js +1 -0
  51. package/src/machine/deposit/direct_cash.js +1 -0
  52. package/src/machine/deposit/float.js +1 -0
  53. package/src/machine/deposit/krway.js +1 -0
  54. package/src/machine/deposit/loadcard_cash.js +2 -1
  55. package/src/machine/deposit/loadcard_vn.js +1 -0
  56. package/src/machine/deposit/manual_cash.js +1 -0
  57. package/src/machine/deposit/manual_vn.js +1 -0
  58. package/src/machine/deposit/qrcode_cash.js +6 -5
  59. package/src/machine/deposit/qrcode_v2.js +1 -0
  60. package/src/machine/deposit/usdt.js +23 -4
  61. package/src/machine/deposit/usdt_cash.js +15 -1
  62. package/src/machine/deposit/virtual_bank_cash.js +11 -9
  63. package/src/machine/deposit/virtual_bank_vn.js +1 -0
  64. package/src/machine/deposit/vpay.js +7 -0
  65. package/src/machine/error.js +1 -0
  66. package/src/machine/game_betslip.js +1 -0
  67. package/src/machine/game_favorite_v2.js +1 -0
  68. package/src/machine/game_hot_new.js +1 -0
  69. package/src/machine/game_info.js +5 -0
  70. package/src/machine/game_replay.js +1 -0
  71. package/src/machine/game_search_cash.js +1 -0
  72. package/src/machine/game_search_v2.js +1 -0
  73. package/src/machine/game_v2_1.js +88 -46
  74. package/src/machine/honor_board.js +1 -0
  75. package/src/machine/honor_board_cash.js +11 -8
  76. package/src/machine/inbox.js +93 -43
  77. package/src/machine/leaderboard.js +1 -0
  78. package/src/machine/merge.js +1 -0
  79. package/src/machine/navbar.js +3 -1
  80. package/src/machine/payment_data.js +1 -0
  81. package/src/machine/promotions.js +11 -18
  82. package/src/machine/ranking.js +5 -2
  83. package/src/machine/reward.js +1 -0
  84. package/src/machine/reward_cash.js +1 -0
  85. package/src/machine/reward_fc.js +1 -0
  86. package/src/machine/roulette_v2.js +18 -26
  87. package/src/machine/setting.js +1 -0
  88. package/src/machine/side.js +10 -4
  89. package/src/machine/side_cash.js +1 -0
  90. package/src/machine/side_v2.js +38 -24
  91. package/src/machine/user_info.js +1 -0
  92. package/src/machine/user_photo.js +1 -0
  93. package/src/machine/user_reset_password.js +5 -2
  94. package/src/machine/user_sign_up.js +1 -0
  95. package/src/machine/vip_table.js +1 -0
  96. package/src/machine/websocket.js +42 -14
  97. package/src/machine/welcome.js +1 -0
  98. package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
  99. package/src/machine/withdraw/withdraw_krway.js +1 -0
  100. package/src/machine/withdraw/withdraw_manual.js +16 -8
  101. package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
  102. package/src/request/request.js +34 -30
  103. package/src/util/deviceToken.js +7 -6
  104. package/src/util/storage.js +4 -3
  105. package/test/api.behavior.test.js +69 -0
  106. package/test/api.contract.test.js +18 -0
  107. package/test/config.test.js +27 -0
  108. package/test/deviceToken.test.js +139 -0
  109. package/test/helpers.coverage.test.js +11 -0
  110. package/test/helpers.js +91 -0
  111. package/test/index.exports.test.js +14 -0
  112. package/test/machine.activity.core.coverage.test.js +337 -0
  113. package/test/machine.activity.gap.coverage.test.js +252 -0
  114. package/test/machine.activity.more.coverage.test.js +180 -0
  115. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  116. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  117. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  118. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  119. package/test/machine.auth.coverage.test.js +215 -0
  120. package/test/machine.bank_binding.test.js +143 -0
  121. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  122. package/test/machine.contract.test.js +50 -0
  123. package/test/machine.crypto_bank.coverage.test.js +270 -0
  124. package/test/machine.crypto_way.coverage.test.js +108 -0
  125. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  126. package/test/machine.definition.test.js +137 -0
  127. package/test/machine.deposit.manual.coverage.test.js +365 -0
  128. package/test/machine.deposit_fc.coverage.test.js +126 -0
  129. package/test/machine.direct.coverage.test.js +96 -0
  130. package/test/machine.direct_cash.coverage.test.js +108 -0
  131. package/test/machine.error.coverage.test.js +37 -0
  132. package/test/machine.events.test.js +126 -0
  133. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  134. package/test/machine.float.coverage.test.js +136 -0
  135. package/test/machine.flow.test.js +226 -0
  136. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  137. package/test/machine.game_search_cash.coverage.test.js +155 -0
  138. package/test/machine.game_search_v2.test.js +199 -0
  139. package/test/machine.game_user_profile.coverage.test.js +100 -0
  140. package/test/machine.honor_board.test.js +133 -0
  141. package/test/machine.inbox.common.coverage.test.js +304 -0
  142. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  143. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  144. package/test/machine.misc.coverage.test.js +361 -0
  145. package/test/machine.more2.coverage.test.js +261 -0
  146. package/test/machine.options.execution.test.js +272 -0
  147. package/test/machine.priority.coverage.test.js +603 -0
  148. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  149. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  150. package/test/machine.regression.test.js +82 -0
  151. package/test/machine.roulette_v2.test.js +142 -0
  152. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  153. package/test/machine.targeted.coverage.test.js +313 -0
  154. package/test/machine.usdt.coverage.test.js +95 -0
  155. package/test/machine.usdt_cash.coverage.test.js +73 -0
  156. package/test/machine.vip_card_activity.test.js +114 -0
  157. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  158. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  159. package/test/machine.vpay.coverage.test.js +142 -0
  160. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  161. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  162. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  163. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  164. package/test/request.test.js +325 -0
  165. package/test/util.storage.errors.test.js +47 -0
  166. package/test/util.test.js +41 -0
@@ -0,0 +1,143 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import bankBindingFactory from '../src/machine/bank_binding.js'
5
+
6
+ function createRequestStub() {
7
+ const calls = []
8
+ return {
9
+ calls,
10
+ request: {
11
+ config: { appSecret: 'secret' },
12
+ send: async (req) => {
13
+ calls.push(req)
14
+ return { data: {} }
15
+ },
16
+ },
17
+ }
18
+ }
19
+
20
+ test('bank_binding action: setBanks maps initial binding data', () => {
21
+ const { request } = createRequestStub()
22
+ const machine = bankBindingFactory(request)
23
+ const setBanks = machine.options.actions.setBanks.assignment
24
+
25
+ const context = { ...machine.initialState.context, currency: 'PKR' }
26
+ const next = setBanks(context, {
27
+ data: {
28
+ paymentList: { bankList: [{ bankCode: 'B1' }] },
29
+ paymentInfo: {
30
+ bankInfo: [
31
+ { bindingType: 'BANK', holderName: 'A', ifscCode: 'IFSC001', firstNameLocale: 'F', lastNameLocale: 'L' },
32
+ { bindingType: 'CRYPTO', holderName: 'B' },
33
+ ],
34
+ },
35
+ },
36
+ })
37
+
38
+ assert.equal(next.hasAnyAccount, true)
39
+ assert.equal(next.hasAnyBankAccount, true)
40
+ assert.equal(next.holderName, 'A')
41
+ assert.equal(next.ifscCode, 'IFSC001')
42
+ assert.equal(next.bank, null)
43
+ })
44
+
45
+ test('bank_binding guard: isBindable covers CRYPTO/EWALLET/BANK branches', () => {
46
+ const { request } = createRequestStub()
47
+ const machine = bankBindingFactory(request)
48
+ const isBindable = machine.options.guards.isBindable
49
+
50
+ assert.ok(
51
+ isBindable(
52
+ {
53
+ bindingType: 'CRYPTO',
54
+ crypto: { symbol: 'USDT' },
55
+ network: { label: 'TRC20' },
56
+ cryptoAddress: 'addr',
57
+ holderName: 'A',
58
+ },
59
+ {}
60
+ )
61
+ )
62
+ assert.ok(
63
+ isBindable(
64
+ {
65
+ bindingType: 'EWALLET',
66
+ walletCode: { bankCode: 'W1' },
67
+ accountNumber: '123',
68
+ firstNameLocale: 'F',
69
+ lastNameLocale: 'L',
70
+ },
71
+ {}
72
+ )
73
+ )
74
+ assert.ok(
75
+ isBindable(
76
+ {
77
+ bindingType: 'BANK',
78
+ currency: 'INR',
79
+ bank: { bankCode: 'B1' },
80
+ ifscCode: 'IFSC',
81
+ accountNumber: '123',
82
+ branch: 'BR',
83
+ holderName: 'A',
84
+ },
85
+ {}
86
+ )
87
+ )
88
+ assert.ok(
89
+ isBindable(
90
+ {
91
+ bindingType: 'BANK',
92
+ currency: 'THB',
93
+ bank: { bankCode: 'B1' },
94
+ accountNumber: '123',
95
+ branch: 'BR',
96
+ firstNameLocale: 'F',
97
+ lastNameLocale: 'L',
98
+ },
99
+ {}
100
+ )
101
+ )
102
+ })
103
+
104
+ test('bank_binding services: fetchInitData and updatePaymentInfo build requests', async () => {
105
+ const { request, calls } = createRequestStub()
106
+ const machine = bankBindingFactory(request)
107
+
108
+ const fetchInitData = machine.options.services.fetchInitData
109
+ const updatePaymentInfo = machine.options.services.updatePaymentInfo
110
+
111
+ await fetchInitData({}, {})
112
+ assert.equal(calls.length, 2)
113
+ assert.equal(calls[0].url.endsWith('getBindingPaymentList'), true)
114
+ assert.equal(calls[1].url.endsWith('paymentInfo'), true)
115
+
116
+ calls.length = 0
117
+ await updatePaymentInfo(
118
+ {
119
+ bindingType: 'BANK',
120
+ bank: { bankCode: 'B001' },
121
+ ifscCode: 'IFSC',
122
+ crypto: { symbol: 'USDT' },
123
+ network: { label: 'TRC20' },
124
+ cryptoAddress: 'ADDR',
125
+ walletCode: { bankCode: 'W01' },
126
+ branch: 'BLANK',
127
+ branchCode: '001',
128
+ accountNumber: '123456',
129
+ holderName: 'Holder',
130
+ firstNameLocale: 'First',
131
+ lastNameLocale: 'Last',
132
+ pixType: 'CPF',
133
+ },
134
+ {}
135
+ )
136
+
137
+ assert.equal(calls.length, 1)
138
+ assert.equal(calls[0].url.endsWith('updatePaymentInfo'), true)
139
+ assert.equal(calls[0].params.bankCode, 'B001')
140
+ assert.equal(calls[0].params.branch, '')
141
+ assert.equal(calls[0].params.cryptoCurrency, 'USDT')
142
+ assert.equal(calls[0].params.walletCode, 'W01')
143
+ })
@@ -0,0 +1,223 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { interpret, State } from 'xstate'
4
+
5
+ import bankBindingFactory from '../src/machine/bank_binding.js'
6
+ import authOtpV2Factory from '../src/machine/auth_otp_v2.js'
7
+ import krwayFactory from '../src/machine/deposit/krway.js'
8
+
9
+ function waitForMatch(service, matcher, timeout = 1200) {
10
+ return new Promise((resolve, reject) => {
11
+ if (matcher(service.state)) {
12
+ resolve(service.state)
13
+ return
14
+ }
15
+
16
+ const timer = setTimeout(() => {
17
+ sub.unsubscribe()
18
+ reject(new Error('timeout waiting for state match'))
19
+ }, timeout)
20
+
21
+ const sub = service.subscribe((state) => {
22
+ if (matcher(state)) {
23
+ clearTimeout(timer)
24
+ sub.unsubscribe()
25
+ resolve(state)
26
+ }
27
+ })
28
+ })
29
+ }
30
+
31
+ test('bank_binding idle event assignments and bind transition guards are covered', async () => {
32
+ const sent = []
33
+ const request = {
34
+ config: { appSecret: 'secret' },
35
+ send: async (req) => {
36
+ sent.push(req)
37
+ if (req.url?.includes('getBindingPaymentList')) return { bankList: [{ bankCode: 'B1' }] }
38
+ if (req.url?.includes('paymentInfo')) return { bankInfo: [{ bindingType: 'BANK', holderName: 'H' }] }
39
+ return { ok: true }
40
+ },
41
+ }
42
+
43
+ const machine = bankBindingFactory(request)
44
+
45
+ let state = State.from('idle', { ...machine.initialState.context, currency: 'INR' })
46
+ state = machine.transition(state, { type: 'SET_BIND_TYPE', data: 'BANK' })
47
+ state = machine.transition(state, { type: 'SET_BANK_CODE', data: { bankCode: 'B1' } })
48
+ state = machine.transition(state, { type: 'SET_IFSC_CODE', data: 'IFSC' })
49
+ state = machine.transition(state, { type: 'SET_BRANCH', data: 'BR' })
50
+ state = machine.transition(state, { type: 'SET_ACCOUNT_NUMBER', data: '123' })
51
+ state = machine.transition(state, { type: 'SET_HOLDER_NAME', data: 'Name' })
52
+ state = machine.transition(state, { type: 'SET_FIRST_NAME', data: 'First' })
53
+ state = machine.transition(state, { type: 'SET_LAST_NAME', data: 'Last' })
54
+ state = machine.transition(state, { type: 'SET_PIX_TYPE', data: 'CPF' })
55
+ state = machine.transition(state, { type: 'SET_CRYPTO_CODE', data: { symbol: 'USDT' } })
56
+ state = machine.transition(state, { type: 'SET_NETWORK_CODE', data: { label: 'TRC20' } })
57
+ state = machine.transition(state, { type: 'SET_CRYPTO_ADDRESS', data: 'addr' })
58
+ state = machine.transition(state, { type: 'SET_WALLET_CODE', data: { bankCode: 'W1' } })
59
+ state = machine.transition(state, { type: 'SET_BRANCH_CODE', data: '001' })
60
+ assert.equal(state.context.bank.bankCode, 'B1')
61
+ assert.equal(state.context.walletCode.bankCode, 'W1')
62
+ assert.equal(state.context.branchCode, '001')
63
+
64
+ const resetState = machine.transition(state, { type: 'RESET_FORM' })
65
+ assert.equal(resetState.context.bank, null)
66
+ assert.equal(resetState.context.lastNameLocale, null)
67
+
68
+ const bindableState = State.from('idle', {
69
+ ...machine.initialState.context,
70
+ bindingType: 'BANK',
71
+ currency: 'THB',
72
+ bank: { bankCode: 'B1' },
73
+ accountNumber: '123',
74
+ branch: 'BR',
75
+ holderName: 'Name',
76
+ })
77
+ const toBinding = machine.transition(bindableState, { type: 'BIND_BANK' })
78
+ assert.equal(toBinding.value, 'binding')
79
+
80
+ const notBindableState = State.from('idle', {
81
+ ...machine.initialState.context,
82
+ bindingType: 'BANK',
83
+ currency: 'THB',
84
+ bank: { bankCode: '' },
85
+ })
86
+ const stayIdle = machine.transition(notBindableState, { type: 'BIND_BANK' })
87
+ assert.equal(stayIdle.value, 'idle')
88
+
89
+ await machine.options.services.updatePaymentInfo(bindableState.context, {})
90
+ assert.equal(
91
+ sent.some((req) => req.url?.includes('updatePaymentInfo')),
92
+ true
93
+ )
94
+ })
95
+
96
+ test('auth_otp_v2 actions/services and conditional transitions are covered', async () => {
97
+ const sent = []
98
+ const request = {
99
+ send: async (req) => {
100
+ sent.push(req)
101
+ if (req.url === '/verify/v2/initiate') {
102
+ if (req.params.strategy === 'phone') return { status: 'success-verified', requestId: 'R1', ttl: 2, target: { phone: true } }
103
+ return { status: 'otp-sent', requestId: 'R2', ttl: 2, target: { email: true } }
104
+ }
105
+ if (req.url === '/otpsso/reset') return { requestId: 'R3', ttl: 1, target: { email: true } }
106
+ if (req.url === '/otpsso/acknowledge') {
107
+ if (req.params.code === 'BAD') {
108
+ const err = new Error('bad code')
109
+ err.code = 'ERR_A108'
110
+ throw err
111
+ }
112
+ if (req.params.code === 'WRONG') {
113
+ const err = new Error('wrong code')
114
+ err.code = 'ERR_X'
115
+ throw err
116
+ }
117
+ return { requestId: 'R4', ttl: 9, target: { email: true } }
118
+ }
119
+ return {}
120
+ },
121
+ }
122
+
123
+ const machine = authOtpV2Factory(request)
124
+ const actions = machine.options.actions
125
+ const services = machine.options.services
126
+
127
+ assert.equal(actions.setStrategyPhone.assignment(machine.initialState.context, {}).strategy, 'phone')
128
+ assert.equal(actions.setStrategyEmail.assignment(machine.initialState.context, {}).strategy, 'email')
129
+ assert.equal(actions.setOtpResult.assignment(machine.initialState.context, { data: { requestId: 'A', ttl: 3, target: {} } }).ttl, 3)
130
+ assert.equal(actions.decreaseTtl.assignment({ ttl: 1 }, {}).ttl, 0)
131
+ assert.equal(actions.setAcknowledgeResult.assignment(machine.initialState.context, { data: { ttl: 7 } }).acknowledgeTtl, 7)
132
+ assert.equal(actions.decreaseAcknowledgeTtl.assignment({ acknowledgeTtl: 1 }, {}).acknowledgeTtl, 0)
133
+
134
+ const sentOtp = await services.sendOtp({ strategy: 'email' }, {})
135
+ assert.equal(sentOtp.status, 'otp-sent')
136
+ const resetOtp = await services.resetOtp({ requestId: 'R2', target: { email: true } }, {})
137
+ assert.equal(resetOtp.requestId, 'R3')
138
+ const ackOtp = await services.acknowledge({ requestId: 'R2', target: { email: true } }, { data: '123456' })
139
+ assert.equal(ackOtp.requestId, 'R4')
140
+
141
+ const s1 = interpret(machine).start()
142
+ s1.send({ type: 'SEND_OTP_PHONE' })
143
+ await waitForMatch(s1, (s) => s.matches('acknowledged'))
144
+ s1.stop()
145
+
146
+ const s2 = interpret(machine).start()
147
+ s2.send({ type: 'SEND_OTP_EMAIL' })
148
+ await waitForMatch(s2, (s) => s.matches('otp'))
149
+ s2.send({ type: 'ACKNOWLEDGE', data: 'BAD' })
150
+ await waitForMatch(s2, (s) => s.matches('idle'))
151
+ s2.stop()
152
+
153
+ const s3 = interpret(machine).start()
154
+ s3.send({ type: 'SEND_OTP_EMAIL' })
155
+ await waitForMatch(s3, (s) => s.matches('otp'))
156
+ s3.send({ type: 'ACKNOWLEDGE', data: 'WRONG' })
157
+ await waitForMatch(s3, (s) => s.matches('otp'))
158
+ s3.stop()
159
+
160
+ assert.equal(
161
+ sent.some((req) => req.url === '/verify/v2/initiate'),
162
+ true
163
+ )
164
+ })
165
+
166
+ test('deposit krway actions/guards/services and checking transitions are covered', async () => {
167
+ const sent = []
168
+ const request = {
169
+ send: async (req) => {
170
+ sent.push(req)
171
+ if (req.url === 'payment/v2/paymentDetail') {
172
+ return [
173
+ { category: 'other', optional: [], processing: [] },
174
+ { category: 'krway', method: 'krway', optional: [{ id: 'opt' }], processing: [{ applyId: 8 }] },
175
+ ]
176
+ }
177
+ if (req.url === 'mailbox/sendMessage') return { ok: true }
178
+ if (req.url === 'payment/v2/krway/transaction') return { applyId: 9, amount: 30 }
179
+ return {}
180
+ },
181
+ }
182
+
183
+ const machine = krwayFactory(request)
184
+ const { actions, guards, services } = machine.options
185
+
186
+ const pd = actions.setPaymentDetail.assignment(machine.initialState.context, {
187
+ data: [
188
+ { category: 'other', optional: [], processing: [] },
189
+ { category: 'krway', method: 'krway', optional: [{ id: 'opt' }], processing: [{ applyId: 1 }] },
190
+ ],
191
+ })
192
+ assert.equal(pd.currentPayment.method, 'krway')
193
+ assert.equal(pd.options.length, 1)
194
+ assert.equal(pd.processing.applyId, 1)
195
+
196
+ assert.equal(actions.addAmount.assignment({ ...machine.initialState.context, amount: 10 }, { data: 5 }).amount, 15)
197
+ assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: '20' }).amount, 20)
198
+ assert.equal(actions.clearAmount.assignment(machine.initialState.context, {}).amount, null)
199
+ assert.equal(actions.setProcessing.assignment(machine.initialState.context, { data: { applyId: 7 } }).processing.applyId, 7)
200
+ assert.equal(guards.isProcessing({ processing: null }), null)
201
+
202
+ const toProcessing = machine.transition(State.from('checking', { ...machine.initialState.context, processing: { applyId: 1 } }), {
203
+ type: 'xstate.init',
204
+ })
205
+ assert.equal(toProcessing.value, 'processing')
206
+ const toIdle = machine.transition(State.from('checking', { ...machine.initialState.context, processing: null }), { type: 'xstate.init' })
207
+ assert.equal(toIdle.value, 'idle')
208
+
209
+ const details = await services.fetchPaymentDetail({}, {})
210
+ assert.equal(details.length, 2)
211
+ await services.accountInquiry({}, { data: { from: 'u1', title: 't', content: 'c' } })
212
+ const submit = await services.submitDeposit({ currentPayment: { method: 'krway' }, amount: 30 }, {})
213
+ assert.equal(submit.applyId, 9)
214
+
215
+ assert.equal(
216
+ sent.some((req) => req.url === 'mailbox/sendMessage'),
217
+ true
218
+ )
219
+ assert.equal(
220
+ sent.some((req) => req.url === 'payment/v2/krway/transaction'),
221
+ true
222
+ )
223
+ })
@@ -0,0 +1,50 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import machine from '../src/machine/index.js'
5
+ import { createLocalStorageMock } from './helpers.js'
6
+
7
+ const requestStub = {
8
+ config: {
9
+ apiURL: 'https://api.example.com',
10
+ apiVersion: 'v1',
11
+ clientId: 'client',
12
+ appSecret: 'secret',
13
+ platform: 'web',
14
+ version: '1.0.0',
15
+ fpToken: 'fp-token',
16
+ sentry: {
17
+ captureException: () => {},
18
+ setTag: () => {},
19
+ },
20
+ defaultChannel: 'web',
21
+ defaultSubchannel: 'home',
22
+ socketURL: 'wss://socket.example.com',
23
+ bucketName: 'bucket',
24
+ },
25
+ send: async () => ({}),
26
+ }
27
+
28
+ global.localStorage = createLocalStorageMock()
29
+ global.window = {
30
+ location: {
31
+ search: '',
32
+ href: 'https://example.com/path',
33
+ origin: 'https://example.com',
34
+ protocol: 'https:',
35
+ host: 'example.com',
36
+ },
37
+ atob: (value) => Buffer.from(value, 'base64').toString('binary'),
38
+ CC_JSB: false,
39
+ }
40
+ global.document = { cookie: '' }
41
+
42
+ for (const [machineName, machineFactory] of Object.entries(machine)) {
43
+ test(`machine contract: ${machineName} can be created`, () => {
44
+ assert.equal(typeof machineFactory, 'function', `${machineName} should be a function`)
45
+ const machineInstance = machineFactory(requestStub, {})
46
+ assert.equal(typeof machineInstance.transition, 'function', `${machineName} should expose transition`)
47
+ assert.ok(machineInstance.id, `${machineName} should have machine id`)
48
+ assert.equal(typeof machineInstance.states, 'object', `${machineName} should expose states map`)
49
+ })
50
+ }
@@ -0,0 +1,270 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import cryptoBankFactory from '../src/machine/deposit/crypto_bank.js'
5
+ import cryptoBankCashFactory from '../src/machine/deposit/crypto_bank_cash.js'
6
+
7
+ test('crypto_bank actions/guards/services cover payment setup and submit payload', async () => {
8
+ const sent = []
9
+ const request = {
10
+ config: { appSecret: 'secret' },
11
+ send: async (req) => {
12
+ sent.push(req)
13
+ if (req.url === 'payment/v2/paymentDetail') {
14
+ return [
15
+ {
16
+ category: 'cryptoBank',
17
+ method: 'crypto_bank',
18
+ minimum: 10,
19
+ maximum: 1000,
20
+ processing: [{ id: 1 }],
21
+ optional: [100, 200],
22
+ banks: [
23
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'A1' },
24
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'A2' },
25
+ { cryptoName: 'ETH', symbol: 'ETH', network: 'ERC20', address: 'E1' },
26
+ ],
27
+ },
28
+ ]
29
+ }
30
+ if (req.url === 'payment/v2/crypto_bank/crypto/expected/result') return { data: { rate: 1.2 } }
31
+ if (req.url === 'payment/v2/crypto_bank/transaction') return { applyId: 88 }
32
+ return {}
33
+ },
34
+ }
35
+
36
+ const machine = cryptoBankFactory(request)
37
+ const { actions, guards, services } = machine.options
38
+
39
+ const setPayment = actions.setPayment.assignment(machine.initialState.context, {
40
+ data: [
41
+ {
42
+ category: 'cryptoBank',
43
+ method: 'crypto_bank',
44
+ minimum: 10,
45
+ maximum: 1000,
46
+ processing: [{ id: 1 }],
47
+ optional: [100, 200],
48
+ banks: [
49
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'A1' },
50
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'A2' },
51
+ { cryptoName: 'ETH', symbol: 'ETH', network: 'ERC20', address: 'E1' },
52
+ ],
53
+ },
54
+ ],
55
+ })
56
+ assert.equal(setPayment.cryptos.length, 2)
57
+ assert.equal(setPayment.selectedCrypto.label, 'USDT')
58
+ assert.equal(setPayment.selectedAddress.value, 'A1')
59
+ assert.equal(setPayment.processing.id, 1)
60
+
61
+ assert.deepEqual(actions.setCrypto.assignment({ cryptoBank: { banks: [] } }, { data: { label: 'USDT' } }), {})
62
+ assert.deepEqual(actions.setCrypto.assignment(setPayment, { data: { label: 'NOPE' } }), {})
63
+
64
+ const setCrypto = actions.setCrypto.assignment(setPayment, { data: { label: 'ETH' } })
65
+ assert.equal(setCrypto.selectedCrypto.label, 'ETH')
66
+ assert.equal(setCrypto.selectedAddress.value, 'E1')
67
+
68
+ assert.deepEqual(actions.setAddress.assignment({ cryptoBank: null, selectedCrypto: null }, { data: { value: 'A1' } }), {})
69
+ const setAddress = actions.setAddress.assignment(setPayment, { data: { value: 'A2' } })
70
+ assert.equal(setAddress.selectedCrypto.address, 'A2')
71
+
72
+ assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: '123' }).amount, '123')
73
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { bonus: 1 } } }).calculation, { bonus: 1 })
74
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { bonus: 2 } }).calculation, { bonus: 2 })
75
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
76
+ assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 7 } }).result.applyId, 7)
77
+ assert.equal(actions.setProofOptional.assignment(machine.initialState.context, { data: true }).proofOptional, true)
78
+ assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: '2026-01-01 10:00:00' }).depositTime, '2026-01-01 10:00:00')
79
+ assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'slip' }).receipt, 'slip')
80
+ assert.equal(actions.setPromotion.assignment(machine.initialState.context, { data: { activityNo: 'A1' } }).promotion.activityNo, 'A1')
81
+
82
+ assert.equal(
83
+ guards.isCalculable({
84
+ selectedCrypto: { value: 'crypto_bank' },
85
+ selectedAddress: { value: 'A1' },
86
+ cryptoBank: { minimum: 10, maximum: 100 },
87
+ amount: '20',
88
+ }),
89
+ true
90
+ )
91
+ assert.equal(
92
+ guards.isCalculable({ selectedCrypto: null, selectedAddress: { value: 'A1' }, cryptoBank: { minimum: 10, maximum: 100 }, amount: '20' }),
93
+ null
94
+ )
95
+ assert.equal(
96
+ guards.isSubmittable({
97
+ selectedCrypto: { value: 'crypto_bank' },
98
+ selectedAddress: { value: 'A1' },
99
+ amount: '20',
100
+ depositTime: 't',
101
+ receipt: 'r',
102
+ proofOptional: false,
103
+ }),
104
+ 'r'
105
+ )
106
+ assert.equal(
107
+ guards.isSubmittable({
108
+ selectedCrypto: { value: 'crypto_bank' },
109
+ selectedAddress: { value: 'A1' },
110
+ amount: '20',
111
+ depositTime: 't',
112
+ receipt: null,
113
+ proofOptional: true,
114
+ }),
115
+ true
116
+ )
117
+ assert.equal(guards.isProcessing({ processing: { id: 1 } }).id, 1)
118
+
119
+ const payments = await services.fetchPayments({}, {})
120
+ assert.equal(Array.isArray(payments), true)
121
+
122
+ const calculation = await services.fetchCalculation(
123
+ { selectedCrypto: { value: 'crypto_bank', symbol: 'USDT' }, amount: 99, promotion: { activityNo: 'ACT1' } },
124
+ {}
125
+ )
126
+ assert.equal(calculation.data.rate, 1.2)
127
+
128
+ const submitted = await services.submitDeposit(
129
+ {
130
+ selectedCrypto: { value: 'crypto_bank', symbol: 'USDT', network: 'TRC20', address: 'A1' },
131
+ amount: 77,
132
+ promotion: { activityNo: 'ACT2' },
133
+ depositTime: '2026-01-01 10:00:00',
134
+ receipt: 'slip',
135
+ },
136
+ {}
137
+ )
138
+ assert.equal(submitted.applyId, 88)
139
+
140
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_bank/transaction')
141
+ assert.equal(submitReq.params.promotionsNo, 'ACT2')
142
+ assert.equal(submitReq.params.sourceAddress, 'A1')
143
+ })
144
+
145
+ test('crypto_bank_cash actions/guards/services cover init branches and submit rules', async () => {
146
+ const sent = []
147
+ const request = {
148
+ send: async (req) => {
149
+ sent.push(req)
150
+ if (req.url === 'payment/v2/crypto_bank_cash/crypto/expected/result') return { data: { value: 22 } }
151
+ if (req.url === 'payment/v2/crypto_bank_cash/transaction') return { applyId: 99 }
152
+ return {}
153
+ },
154
+ }
155
+
156
+ const machine = cryptoBankCashFactory(request, {
157
+ paymentDetail: [
158
+ {
159
+ transferType: 'deposit',
160
+ category: 'cryptoBank',
161
+ method: 'crypto_bank_cash',
162
+ minimum: 50,
163
+ maximum: 5000,
164
+ grandTotalEnable: 0,
165
+ optional: [100, 200],
166
+ banks: [
167
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'CA1' },
168
+ { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'CA2' },
169
+ ],
170
+ },
171
+ ],
172
+ promotion: { promotionsNo: 'P1', minimumAmount: 120 },
173
+ selectedAmount: 10,
174
+ siteConfig: { bankDepositProofIsOptional: '1' },
175
+ })
176
+
177
+ const { actions, guards, services } = machine.options
178
+
179
+ const init = actions.setInitData.assignment(machine.initialState.context, {})
180
+ assert.equal(init.cryptos.length, 1)
181
+ assert.equal(init.selectedCrypto.label, 'USDT')
182
+ assert.equal(init.selectedAddress.value, 'CA1')
183
+
184
+ const initMissing = actions.setInitData.assignment({ ...machine.initialState.context, paymentDetail: [] }, {})
185
+ assert.equal(initMissing.cryptoBank, null)
186
+ assert.deepEqual(initMissing.options, [])
187
+
188
+ assert.deepEqual(actions.setCrypto.assignment({ cryptoBank: { banks: [] } }, { data: { label: 'USDT' } }), {})
189
+ assert.deepEqual(actions.setCrypto.assignment(init, { data: { label: 'NOPE' } }), {})
190
+ assert.equal(actions.setCrypto.assignment(init, { data: { label: 'USDT' } }).selectedAddress.value, 'CA1')
191
+
192
+ assert.deepEqual(actions.setAddress.assignment({ cryptoBank: null, selectedCrypto: null }, { data: { value: 'CA1' } }), {})
193
+ assert.equal(actions.setAddress.assignment(init, { data: { value: 'CA2' } }).selectedCrypto.address, 'CA2')
194
+
195
+ assert.equal(actions.setAmount.assignment({ ...init, cryptoBank: { grandTotalEnable: 1 }, selectedAmount: '10' }, { data: '5' }).selectedAmount, 15)
196
+ assert.equal(
197
+ actions.setAmount.assignment({ ...init, cryptoBank: { grandTotalEnable: 0 }, selectedAmount: '10' }, { data: '5' }).selectedAmount,
198
+ '5'
199
+ )
200
+ assert.equal(actions.inputAmount.assignment(machine.initialState.context, { data: 333 }).selectedAmount, 333)
201
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { bonus: 1 } } }).calculation, { bonus: 1 })
202
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { bonus: 2 } }).calculation, { bonus: 2 })
203
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
204
+ assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
205
+
206
+ const promo = actions.setPromotion.assignment({ ...init, selectedAmount: 10 }, { data: { promotionsNo: 'P2', minimumAmount: 200 } })
207
+ assert.equal(promo.selectedAmount, 200)
208
+ assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: 't' }).depositTime, 't')
209
+ assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'r' }).receipt, 'r')
210
+
211
+ assert.equal(
212
+ guards.isCalculable({
213
+ selectedCrypto: { value: 'crypto_bank_cash' },
214
+ selectedAddress: { value: 'CA1' },
215
+ cryptoBank: { minimum: 50, maximum: 500 },
216
+ selectedAmount: 100,
217
+ }),
218
+ true
219
+ )
220
+ assert.equal(
221
+ guards.isCalculable({ selectedCrypto: null, selectedAddress: { value: 'CA1' }, cryptoBank: { minimum: 50, maximum: 500 }, selectedAmount: 100 }),
222
+ null
223
+ )
224
+ assert.equal(
225
+ guards.isSubmittable({
226
+ selectedCrypto: { value: 'crypto_bank_cash' },
227
+ selectedAddress: { value: 'CA1' },
228
+ selectedAmount: 100,
229
+ depositTime: 't',
230
+ receipt: 'r',
231
+ calculation: { ok: 1 },
232
+ siteConfig: { bankDepositProofIsOptional: '1' },
233
+ }),
234
+ 'r'
235
+ )
236
+ assert.equal(
237
+ guards.isSubmittable({
238
+ selectedCrypto: { value: 'crypto_bank_cash' },
239
+ selectedAddress: { value: 'CA1' },
240
+ selectedAmount: 100,
241
+ depositTime: null,
242
+ receipt: null,
243
+ calculation: { ok: 1 },
244
+ siteConfig: { bankDepositProofIsOptional: '2' },
245
+ }),
246
+ true
247
+ )
248
+
249
+ const calc = await services.fetchCalculation(
250
+ { selectedCrypto: { value: 'crypto_bank_cash', symbol: 'USDT' }, selectedAmount: 300, promotion: { promotionsNo: 'P3' } },
251
+ {}
252
+ )
253
+ assert.equal(calc.data.value, 22)
254
+
255
+ const submitted = await services.submitDeposit(
256
+ {
257
+ selectedCrypto: { value: 'crypto_bank_cash', symbol: 'USDT', network: 'TRC20', address: 'CA1' },
258
+ selectedAmount: 500,
259
+ promotion: { promotionsNo: 'P4' },
260
+ depositTime: '2026-01-01 12:00:00',
261
+ receipt: 'slip',
262
+ },
263
+ {}
264
+ )
265
+ assert.equal(submitted.applyId, 99)
266
+
267
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_bank_cash/transaction')
268
+ assert.equal(submitReq.params.promotionsNo, 'P4')
269
+ assert.equal(submitReq.params.sourceAddress, 'CA1')
270
+ })