@jetthai/cuora 2.0.0-beta.0 → 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 -112
  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 -98
  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 +8 -11
  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 +0 -1
  70. package/src/machine/game_v2_1.js +39 -126
  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 -459
  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 -80
  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 -133
  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 -155
  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 -133
  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 -603
  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,313 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import userSignUpFactory from '../src/machine/user_sign_up.js'
5
- import websocketFactory from '../src/machine/websocket.js'
6
- import sideV2Factory from '../src/machine/side_v2.js'
7
- import storage from '../src/util/storage.js'
8
- import { createLocalStorageMock } from './helpers.js'
9
-
10
- test('user_sign_up: actions and authenticate service build registration payload', async () => {
11
- global.localStorage = createLocalStorageMock()
12
- global.window = { location: { href: 'https://example.com/register' } }
13
-
14
- storage.set('ac', 'AFF_FROM_STORAGE')
15
- storage.set('channel', 'channel_storage')
16
- storage.set('subchannel', 'sub_storage')
17
-
18
- const messages = []
19
- let sentReq = null
20
- const request = {
21
- config: {
22
- fpToken: 'fp-token',
23
- sentry: { captureMessage: (msg) => messages.push(msg), captureException: () => {}, setTag: () => {} },
24
- defaultChannel: 'default_channel',
25
- defaultSubchannel: 'default_subchannel',
26
- },
27
- hosts: [],
28
- send: async (req) => {
29
- sentReq = req
30
- return { data: { account: 'u1', currency: 'THB', site: 'S', strategy: 'normal', uid: 'uid' } }
31
- },
32
- }
33
-
34
- const machine = userSignUpFactory(request)
35
- const setSignUpId = machine.options.actions.setSignUpId.assignment
36
- const setRegistrationData = machine.options.actions.setRegistrationData.assignment
37
- const authenticate = machine.options.services.authenticate
38
-
39
- const signUpCtxPatch = setSignUpId(machine.initialState.context, {
40
- data: {
41
- email: 'a@example.com',
42
- username: 'alice',
43
- nick_name: 'Alice',
44
- password: 'pw',
45
- countryCode: '66',
46
- phone: '0800000000',
47
- channel: 'event_channel',
48
- subchannel: 'event_sub',
49
- affiliateCode: 'AFF_EVENT',
50
- },
51
- })
52
-
53
- assert.equal(signUpCtxPatch.signUpData.provider, 'local')
54
- assert.equal(signUpCtxPatch.channel, 'event_channel')
55
-
56
- const authResult = await authenticate(
57
- {
58
- ...machine.initialState.context,
59
- ...signUpCtxPatch,
60
- reCaptchaToken: 'captcha',
61
- fc: 'FC01',
62
- deviceTokenEnable: false,
63
- },
64
- {}
65
- )
66
-
67
- assert.ok(sentReq)
68
- assert.equal(authResult.data.account, 'u1')
69
- assert.equal(messages.length > 0, true)
70
- assert.equal(sentReq.url.includes('ac=AFF_FROM_STORAGE'), true)
71
- assert.equal(sentReq.url.includes('channel=channel_storage'), true)
72
- assert.equal(sentReq.url.includes('subchannel=sub_storage'), true)
73
- assert.equal(sentReq.url.includes('fc=FC01'), true)
74
-
75
- const registration = setRegistrationData(machine.initialState.context, {
76
- data: {
77
- account: 'u2',
78
- currency: 'USD',
79
- site: 'site',
80
- strategy: 'x',
81
- uid: 'uid2',
82
- channel: 'c',
83
- sub_channel: 'sc',
84
- },
85
- })
86
- assert.equal(registration.registrationData.account, 'u2')
87
- assert.equal(registration.registrationData.sub_channel, 'sc')
88
- })
89
-
90
- test('websocket: actions/guards/services work with mocked socket and fetch', async () => {
91
- const pushed = []
92
- const sentryErrors = []
93
- const request = {
94
- config: {
95
- socketURL: 'https://socket.example.com',
96
- bucketName: 'bucket',
97
- clientId: 'client',
98
- sentry: { captureException: (e) => sentryErrors.push(e) },
99
- },
100
- getToken: () => 'token',
101
- }
102
-
103
- const machine = websocketFactory(request)
104
-
105
- const setSocket = machine.options.actions.setSocket.assignment
106
- const setConnectError = machine.options.actions.setConnectError.assignment
107
- const setDisconnected = machine.options.actions.setDisconnected.assignment
108
- const pushEvent = machine.options.actions.pushEvent.assignment
109
- const setReconnectCount = machine.options.actions.setReconnectCount.assignment
110
- const isNeedConnect = machine.options.guards.isNeedConnect
111
- const isReconnect = machine.options.guards.isReconnect
112
-
113
- const connected = setSocket(machine.initialState.context, { data: { id: 'socket-1' } })
114
- assert.equal(connected.connectStatus, 2)
115
-
116
- const connectErr = setConnectError(
117
- { ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) }, connectError: null },
118
- { data: 'io server disconnect' }
119
- )
120
- assert.equal(connectErr.connectStatus, 0)
121
- assert.equal(sentryErrors.length > 0, true)
122
-
123
- setDisconnected({ ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) } }, { reason: 'transport error' })
124
-
125
- pushEvent(
126
- { ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) } },
127
- {
128
- data: {
129
- event: 'purchase',
130
- isTracking: true,
131
- data: { paymentMethod: 'bank', transactionId: 'tx1', currency: 'THB', value: 100, isFirst: true },
132
- },
133
- }
134
- )
135
-
136
- const recon = setReconnectCount({ ...machine.initialState.context, reconnectCount: 1 }, {})
137
- assert.equal(recon.reconnectCount, 2)
138
- assert.equal(isNeedConnect({ connectStatus: 1, clientSocket: null }, {}), false)
139
- assert.equal(isNeedConnect({ connectStatus: 0, clientSocket: { connected: true } }, {}), false)
140
- assert.equal(isNeedConnect({ connectStatus: 0, clientSocket: null }, {}), true)
141
- assert.equal(isReconnect({ reconnectCount: 1, connectError: 'io server disconnect' }, {}), true)
142
- assert.equal(isReconnect({ reconnectCount: 3, connectError: 'io server disconnect' }, {}), false)
143
-
144
- const originalFetch = global.fetch
145
- global.fetch = async (url) => {
146
- if (String(url).endsWith('target.json')) {
147
- return {
148
- ok: true,
149
- json: async () => ({ socket: ['https://a.example.com', 'https://b.example.com'] }),
150
- }
151
- }
152
- return {
153
- ok: true,
154
- json: async () => ({}),
155
- }
156
- }
157
- const fetchSocket = machine.options.services.fetchSocket
158
- const socketRes = await fetchSocket({ url: 'https://storage.googleapis.com/x/target.json' }, {})
159
- assert.ok(socketRes.socketURL)
160
-
161
- const callbacks = []
162
- const handlers = {}
163
- const fakeSocket = {
164
- on: (event, fn) => {
165
- handlers[event] = fn
166
- },
167
- }
168
- const listen = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocket })
169
- listen((event) => callbacks.push(event))
170
- handlers['activity-info']?.({ id: 1 })
171
- handlers['payment-info']?.({ windowType: 'toast', id: 2 })
172
- handlers['connect']?.()
173
- handlers['connect_error']?.({ message: 'x' })
174
- handlers['disconnect']?.('io server disconnect')
175
- assert.equal(callbacks.length > 0, true)
176
- global.fetch = originalFetch
177
- })
178
-
179
- test('side_v2: menu actions/guards/services handle nested menu flow', async () => {
180
- const menu = {
181
- timestamp: 1,
182
- data: [
183
- {
184
- categoryId: 1,
185
- isGame: false,
186
- sub: [{ categoryId: 11, isGame: false, sub: [{ categoryId: 111, isGame: true, sub: [] }] }],
187
- },
188
- ],
189
- }
190
-
191
- let lastReq = null
192
- const request = {
193
- config: { appSecret: 'secret' },
194
- send: async (req) => {
195
- lastReq = req
196
- return menu
197
- },
198
- }
199
-
200
- const machine = sideV2Factory(request)
201
- const setMenu = machine.options.actions.setMenu.assignment
202
- const setDefaultMenuItemStack = machine.options.actions.setDefaultMenuItemStack.assignment
203
- const setMenuItemStack = machine.options.actions.setMenuItemStack.assignment
204
- const restoreMenuItemStack = machine.options.actions.restoreMenuItemStack.assignment
205
- const pushHistoryStack = machine.options.actions.pushHistoryStack.assignment
206
- const popHistoryStack = machine.options.actions.popHistoryStack.assignment
207
- const resetMenuItemStack = machine.options.actions.resetMenuItemStack.assignment
208
- const resetHistoryStack = machine.options.actions.resetHistoryStack.assignment
209
- const updateMenu = machine.options.actions.updateMenu.assignment
210
- const isInMenu = machine.options.guards.isInMenu
211
-
212
- const patch1 = setMenu(machine.initialState.context, { data: menu })
213
- assert.equal(patch1.menu.data[0].level, 0)
214
- const patchNoArray = setMenu(machine.initialState.context, { data: { timestamp: 2, data: null } })
215
- assert.equal(patchNoArray.menu.timestamp, 2)
216
-
217
- const patch2 = setDefaultMenuItemStack(machine.initialState.context, { data: menu })
218
- assert.equal(Array.isArray(patch2.menuItemStack), true)
219
- assert.equal(patch2.menuItemStack.length > 0, true)
220
-
221
- const baseCtx = {
222
- ...machine.initialState.context,
223
- ...patch1,
224
- ...patch2,
225
- historyStack: [],
226
- }
227
-
228
- const selectedTop = setMenuItemStack(baseCtx, { data: menu.data[0] })
229
- assert.equal(selectedTop.menuItemStack.length > 0, true)
230
- const selectedTopNoSub = setMenuItemStack(baseCtx, { data: { categoryId: 2, level: 0, sub: [] } })
231
- assert.equal(selectedTopNoSub.historyStack.length, 0)
232
- const selectedNonTop = setMenuItemStack({ ...baseCtx, menuItemStack: [menu.data[0], menu.data[0].sub[0]] }, { data: { categoryId: 999, level: 1 } })
233
- assert.equal(selectedNonTop.menuItemStack.length, 2)
234
-
235
- const restored = restoreMenuItemStack({ ...baseCtx, previousMenuItemStack: [menu.data[0]] }, {})
236
- assert.equal(restored.menuItemStack.length, 1)
237
-
238
- const pushedStack = pushHistoryStack(baseCtx, { data: { name: 'x' } })
239
- assert.equal(pushedStack.historyStack.length, 1)
240
- const poppedStack = popHistoryStack({ ...baseCtx, historyStack: [{ name: 'x' }] }, {})
241
- assert.equal(poppedStack.historyStack.length, 0)
242
-
243
- const resetMenu = resetMenuItemStack({ ...baseCtx, defaultMenuItemStack: [menu.data[0]] }, {})
244
- assert.equal(resetMenu.menuItemStack.length, 1)
245
- const resetHistory = resetHistoryStack(baseCtx, {})
246
- assert.deepEqual(resetHistory.historyStack, [])
247
-
248
- const updated = updateMenu(baseCtx, { data: menu })
249
- assert.equal(updated.defaultMenuItemStack.length > 0, true)
250
- assert.equal(updateMenu(baseCtx, { data: { data: [] } }), undefined)
251
-
252
- assert.equal(isInMenu({ ...baseCtx, menuItemStack: [menu.data[0]] }, {}), true)
253
- assert.equal(
254
- isInMenu({
255
- ...baseCtx,
256
- menu: { ...menu, data: [menu.data[0], { categoryId: 2, isGame: true, sub: [] }] },
257
- menuItemStack: [menu.data[0]],
258
- }),
259
- true
260
- )
261
- assert.equal(
262
- isInMenu({
263
- ...baseCtx,
264
- menuItemStack: [{ categoryId: 99999 }],
265
- }),
266
- false
267
- )
268
-
269
- const getMenu = machine.options.services.getMenu
270
- const fetchUpdateMenu = machine.options.services.fetchUpdateMenu
271
- await getMenu(baseCtx, {})
272
- assert.ok(lastReq)
273
- await fetchUpdateMenu({ ...baseCtx, menu: { timestamp: 99 } }, {})
274
- assert.ok(lastReq)
275
- })
276
-
277
- test('side_v2: deep nested menu processing stays stable', () => {
278
- const depth = 12000
279
- const root = { categoryId: 1, isGame: false, sub: [] }
280
- let cursor = root
281
- for (let i = 2; i <= depth; i++) {
282
- const next = { categoryId: i, isGame: false, sub: [] }
283
- cursor.sub = [next]
284
- cursor = next
285
- }
286
- // terminal node is game-like leaf in real menu trees
287
- cursor.isGame = true
288
-
289
- const request = {
290
- config: { appSecret: 'secret' },
291
- send: async () => ({ data: [root] }),
292
- }
293
- const machine = sideV2Factory(request)
294
- const actions = machine.options.actions
295
- const isInMenu = machine.options.guards.isInMenu
296
- const ctx = machine.initialState.context
297
- const menu = { timestamp: 1, data: [root] }
298
-
299
- const patchedMenu = actions.setMenu.assignment(ctx, { data: menu })
300
- const patchedDefaultStack = actions.setDefaultMenuItemStack.assignment(ctx, { data: menu })
301
- assert.equal(patchedMenu.menu.data[0].level, 0)
302
- assert.equal(patchedDefaultStack.menuItemStack.length, depth)
303
-
304
- const inMenu = isInMenu(
305
- {
306
- ...ctx,
307
- menu: patchedMenu.menu,
308
- menuItemStack: [{ categoryId: depth }],
309
- },
310
- {}
311
- )
312
- assert.equal(inMenu, true)
313
- })
@@ -1,95 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import usdtFactory from '../src/machine/deposit/usdt.js'
5
-
6
- test('usdt actions/guards/services cover payment setup, cache and submit error path', async () => {
7
- const sent = []
8
- const request = {
9
- send: async (req) => {
10
- sent.push(req)
11
- if (req.url === 'payment/v2/paymentDetail') {
12
- return [
13
- {
14
- category: 'usdt',
15
- method: 'usdt',
16
- channel: 'USDT',
17
- networkName: ['TRC20', 'ERC20'],
18
- networkOptional: ['TRON', 'ETH'],
19
- },
20
- ]
21
- }
22
- if (req.url === 'payment/v2/usdt/transaction') {
23
- return {
24
- action: 'pay',
25
- cdtime: 60,
26
- accountNumber: 'ADDR',
27
- currency: 'USDT',
28
- network: 'TRC20',
29
- name: 'USDT',
30
- qrcode: 'QR',
31
- }
32
- }
33
- return {}
34
- },
35
- }
36
-
37
- const machine = usdtFactory(request)
38
- const { actions, guards, services } = machine.options
39
-
40
- const setPayment = actions.setPayment.assignment(machine.initialState.context, {
41
- data: [
42
- {
43
- category: 'usdt',
44
- method: 'usdt',
45
- channel: 'USDT',
46
- networkName: ['TRC20', 'ERC20'],
47
- networkOptional: ['TRON', 'ETH'],
48
- },
49
- ],
50
- })
51
- assert.equal(setPayment.currentPayment.method, 'usdt')
52
- assert.equal(setPayment.networks.length, 2)
53
- assert.equal(setPayment.selectedNetwork.value, 'TRC20')
54
-
55
- const setPaymentNoMatch = actions.setPayment.assignment(machine.initialState.context, { data: [{ category: 'other' }] })
56
- assert.equal(setPaymentNoMatch.currentPayment, null)
57
- assert.deepEqual(setPaymentNoMatch.networks, [])
58
-
59
- const setPaymentInvalidNetwork = actions.setPayment.assignment(machine.initialState.context, {
60
- data: [{ category: 'usdt', method: 'usdt', channel: 'USDT', networkName: null }],
61
- })
62
- assert.deepEqual(setPaymentInvalidNetwork.networks, [])
63
- assert.equal(setPaymentInvalidNetwork.selectedNetwork, null)
64
-
65
- assert.equal(actions.setNetwork.assignment(machine.initialState.context, { data: { value: 'ERC20' } }).selectedNetwork.value, 'ERC20')
66
- assert.deepEqual(actions.setResultFromLocal.assignment({ resultMap: {}, selectedNetwork: null }, {}), {})
67
- assert.equal(actions.setResultFromLocal.assignment({ resultMap: { TRC20: { hit: 1 } }, selectedNetwork: { value: 'TRC20' } }, {}).result.hit, 1)
68
-
69
- const result = actions.setResult.assignment(
70
- { resultMap: {}, selectedNetwork: { value: 'TRC20' } },
71
- { data: { action: 'pay', cdtime: 60, accountNumber: 'A', currency: 'USDT', network: 'TRC20', name: 'N', qrcode: 'Q' } }
72
- )
73
- assert.equal(result.resultMap.TRC20.currency, 'USDT')
74
-
75
- assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: null }), false)
76
- assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: { value: 'TRC20' } }), undefined)
77
- assert.deepEqual(guards.isFound({ resultMap: { TRC20: { ok: 1 } }, selectedNetwork: { value: 'TRC20' } }), { ok: 1 })
78
-
79
- const payments = await services.fetchPayments({}, {})
80
- assert.equal(Array.isArray(payments), true)
81
-
82
- await assert.rejects(
83
- async () => {
84
- await services.submitDeposit({ currentPayment: null, selectedNetwork: null }, {})
85
- },
86
- (error) => error && error.code === 'ERR_INVALID_USDT_NETWORK'
87
- )
88
-
89
- const submitted = await services.submitDeposit({ currentPayment: { method: 'usdt', channel: 'USDT' }, selectedNetwork: { value: 'TRC20' } }, {})
90
- assert.equal(submitted.currency, 'USDT')
91
-
92
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/usdt/transaction')
93
- assert.equal(submitReq.params.cryptoCurrency, 'USDT')
94
- assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
95
- })
@@ -1,73 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import usdtCashFactory from '../src/machine/deposit/usdt_cash.js'
5
-
6
- test('usdt_cash actions/guards/services cover network cache and submit mapping', async () => {
7
- const sent = []
8
- const request = {
9
- send: async (req) => {
10
- sent.push(req)
11
- if (req.url === 'payment/v2/usdt_cash/transaction') {
12
- return {
13
- action: 'pay',
14
- cdtime: 60,
15
- accountNumber: 'ADDR',
16
- currency: 'USDT',
17
- network: 'TRC20',
18
- name: 'USDT',
19
- qrcode: 'QR',
20
- }
21
- }
22
- return {}
23
- },
24
- }
25
-
26
- const machine = usdtCashFactory(request, {
27
- paymentDetail: [
28
- {
29
- transferType: 'deposit',
30
- category: 'usdt',
31
- method: 'usdt_cash',
32
- channel: 'USDT',
33
- networkName: ['TRC20', 'ERC20'],
34
- networkOptional: ['TRON', 'ETH'],
35
- },
36
- ],
37
- })
38
-
39
- const { actions, guards, services } = machine.options
40
-
41
- const setPayment = actions.setPayment.assignment(machine.initialState.context, {})
42
- assert.equal(setPayment.currentPayment.method, 'usdt_cash')
43
- assert.equal(setPayment.networks.length, 2)
44
- assert.equal(setPayment.selectedNetwork.value, 'TRC20')
45
-
46
- assert.equal(actions.setNetwork.assignment(machine.initialState.context, { data: { value: 'ERC20' } }).selectedNetwork.value, 'ERC20')
47
-
48
- assert.deepEqual(actions.setResultFromLocal.assignment({ resultMap: {}, selectedNetwork: null }, {}), {})
49
- assert.equal(actions.setResultFromLocal.assignment({ resultMap: { TRC20: { hit: 1 } }, selectedNetwork: { value: 'TRC20' } }, {}).result.hit, 1)
50
-
51
- const setResult = actions.setResult.assignment(
52
- { resultMap: {}, selectedNetwork: { value: 'TRC20' } },
53
- { data: { action: 'pay', cdtime: 60, accountNumber: 'ADDR', currency: 'USDT', network: 'TRC20', name: 'USDT', qrcode: 'QR' } }
54
- )
55
- assert.equal(setResult.resultMap.TRC20.currency, 'USDT')
56
-
57
- assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: null }), false)
58
- assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: { value: 'TRC20' } }), undefined)
59
- assert.deepEqual(guards.isFound({ resultMap: { TRC20: { ok: 1 } }, selectedNetwork: { value: 'TRC20' } }), { ok: 1 })
60
-
61
- const submit = await services.submitDeposit(
62
- {
63
- currentPayment: { method: 'usdt_cash', channel: 'USDT' },
64
- selectedNetwork: { value: 'TRC20' },
65
- },
66
- {}
67
- )
68
- assert.equal(submit.currency, 'USDT')
69
-
70
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/usdt_cash/transaction')
71
- assert.equal(submitReq.params.cryptoCurrency, 'USDT')
72
- assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
73
- })
@@ -1,114 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import vipCardActivityFactory from '../src/machine/activity/vip_card_activity.js'
5
-
6
- test('vip_card_activity actions/services cover level, period and award branches', async () => {
7
- const calls = []
8
- const request = {
9
- config: { appSecret: 'secret' },
10
- send: async (req) => {
11
- calls.push(req)
12
- return {
13
- data: {
14
- activityNo: 'A1',
15
- status: 'ok',
16
- },
17
- }
18
- },
19
- }
20
- const machine = vipCardActivityFactory(request)
21
- const actions = machine.options.actions
22
- const services = machine.options.services
23
-
24
- assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A1' }).activityNo, 'A1')
25
-
26
- const detailPatch = actions.setActivityDetail.assignment({ ...machine.initialState.context, activityDetail: { keep: true } }, { data: {} })
27
- assert.deepEqual(detailPatch.activityDetail, { keep: true })
28
-
29
- const setActivity = actions.setActivity.assignment(machine.initialState.context, {
30
- data: { activityNo: 'A2', activityDetail: { x: 1 } },
31
- })
32
- assert.equal(setActivity.activityNo, 'A2')
33
- assert.deepEqual(setActivity.activityDetail, { x: 1 })
34
-
35
- const now = Math.floor(Date.now() / 1000)
36
- const initAtMax = actions.setInitData.assignment(
37
- {
38
- ...machine.initialState.context,
39
- activityDetail: {
40
- rebateType: 'R',
41
- conditions: [
42
- { title: 'L1', depositLimit: '10', turnoverLimit: '20' },
43
- { title: 'L2', depositLimit: '30', turnoverLimit: '40' },
44
- ],
45
- nextCycleCardCurrentReachLevel: { title: 'L2' },
46
- nextCycleCardNextReachLevel: { title: 'L3', depositLimit: '50', turnoverLimit: '60' },
47
- lastCycleCard: { title: 'L1' },
48
- accumulateStartTime: now - 10,
49
- accumulateEndTime: now + 10,
50
- lastCycleCardStartTime: now - 5,
51
- lastCycleCardEndTime: now + 5,
52
- },
53
- },
54
- {}
55
- )
56
- assert.equal(initAtMax.nextDepositLimit, '30')
57
- assert.equal(initAtMax.nextTurnoverLimit, '40')
58
- assert.equal(initAtMax.isAccumulationPeriod, true)
59
- assert.equal(initAtMax.isAwardPeriod, true)
60
-
61
- const initAtNext = actions.setInitData.assignment(
62
- {
63
- ...machine.initialState.context,
64
- activityDetail: {
65
- conditions: [{ title: 'L1', depositLimit: '10', turnoverLimit: '20' }],
66
- nextCycleCardCurrentReachLevel: { title: 'L0' },
67
- nextCycleCardNextReachLevel: { title: 'L1', depositLimit: '10', turnoverLimit: '20' },
68
- accumulateStartTime: now + 100,
69
- accumulateEndTime: now + 200,
70
- lastCycleCardStartTime: now + 300,
71
- lastCycleCardEndTime: now + 400,
72
- },
73
- },
74
- {}
75
- )
76
- assert.equal(initAtNext.nextDepositLimit, '10')
77
- assert.equal(initAtNext.nextTurnoverLimit, '20')
78
- assert.equal(initAtNext.isAccumulationPeriod, false)
79
- assert.equal(initAtNext.isAwardPeriod, false)
80
-
81
- const durationAccumulation = actions.setDuration.assignment(
82
- {
83
- ...machine.initialState.context,
84
- isAwardPeriod: true,
85
- activityDetail: {
86
- rewardPeriodSameAsAccumulationPeriod: true,
87
- accumulateEndTime: `${now + 50}`,
88
- lastCycleCardEndTime: `${now + 99}`,
89
- },
90
- },
91
- {}
92
- )
93
- assert.equal(durationAccumulation.duration > 0, true)
94
-
95
- const durationAward = actions.setDuration.assignment(
96
- {
97
- ...machine.initialState.context,
98
- isAwardPeriod: true,
99
- activityDetail: {
100
- rewardPeriodSameAsAccumulationPeriod: false,
101
- accumulateEndTime: `${now + 1}`,
102
- lastCycleCardEndTime: `${now + 50}`,
103
- },
104
- },
105
- {}
106
- )
107
- assert.equal(durationAward.duration >= 49, true)
108
-
109
- const loadedDetail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
110
- const awardResult = await services.sentAward({ activityNo: 'A1' }, {})
111
- assert.equal(loadedDetail.activityNo, 'A1')
112
- assert.equal(awardResult.status, 'ok')
113
- assert.equal(calls.length, 2)
114
- })