@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,211 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import fafafaActivityFactory from '../src/machine/activity/fafafa_activity.js'
5
+ import specifyBetsActivityFactory from '../src/machine/activity/specify_bets_activity.js'
6
+ import specifyTurnoverActivityFactory from '../src/machine/activity/specify_turnover_activity.js'
7
+ import depositActivityFactory from '../src/machine/activity/deposit_activity.js'
8
+ import returnBonusActivityFactory from '../src/machine/activity/return_bonus_activity.js'
9
+ import welcomeFactory from '../src/machine/welcome.js'
10
+ import { createLocalStorageMock } from './helpers.js'
11
+
12
+ test('fafafa_activity actions/guards/services cover reward and period branches', async () => {
13
+ const sent = []
14
+ const request = {
15
+ config: { appSecret: 'secret' },
16
+ send: async (req) => {
17
+ sent.push(req)
18
+ if (req.url === 'activities') return { data: { receiveStatus: 2, periodEndTime: Math.floor(Date.now() / 1000) + 30 } }
19
+ if (req.url === 'activities/sentAward') {
20
+ return { data: { awards: [{ id: 1 }], periodBeginTime: 1, periodEndTime: 2, receiveNo: req.params.activityNo, receiveReward: true } }
21
+ }
22
+ if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
23
+ return { data: {} }
24
+ },
25
+ }
26
+ const machine = fafafaActivityFactory(request, { activityNo: 88, isAutoReceiving: true })
27
+ const actions = machine.options.actions
28
+ const guards = machine.options.guards
29
+ const services = machine.options.services
30
+ const ctx = machine.initialState.context
31
+
32
+ assert.equal(actions.setActivityNo.assignment(ctx, { data: 99 }).activityNo, 99)
33
+ const detailSet = actions.setActivityDetail.assignment({ ...ctx, lastCheckedPeriodEndTime: 1 }, { data: { periodEndTime: 10, receiveStatus: 2 } })
34
+ assert.equal(detailSet.lastCheckedPeriodEndTime, null)
35
+ assert.equal(
36
+ actions.setAward.assignment(ctx, { data: { awards: [1], periodBeginTime: 1, periodEndTime: 2, receiveNo: '3', receiveReward: true } }).receiveNo,
37
+ '3'
38
+ )
39
+ assert.equal(typeof actions.setCallback.assignment(ctx, { data: {} }).callback, 'function')
40
+ let cb = 0
41
+ actions.doCallback({ ...ctx, callback: () => cb++ }, {})
42
+ assert.equal(cb, 1)
43
+ assert.ok(actions.setDuration.assignment({ ...ctx, activityDetail: { periodEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
44
+
45
+ assert.equal(guards.isAwardable({ ...ctx, activityDetail: { receiveStatus: 2 } }, {}), true)
46
+ assert.equal(guards.isAutoReceiving({ ...ctx, isAutoReceiving: true }, {}), true)
47
+ const periodCtx = { ...ctx, duration: 0, activityDetail: { periodEndTime: 123 }, lastCheckedPeriodEndTime: null }
48
+ assert.equal(guards.shouldCheckNewPeriod(periodCtx, {}), true)
49
+ assert.equal(guards.shouldCheckNewPeriod(periodCtx, {}), false)
50
+ assert.equal(guards.shouldCheckNewPeriod({ ...ctx, duration: 1, activityDetail: { periodEndTime: 123 } }, {}), false)
51
+
52
+ await services.fetchActivityDetail({ ...ctx, activityNo: 88 }, {})
53
+ await services.awardPrize({ ...ctx, activityNo: 88 }, {})
54
+ const r0 = await services.receiveReward({ ...ctx, activityNo: 88, receiveNo: '0' }, {})
55
+ assert.equal(r0.ok, true)
56
+ const r2 = await services.receiveReward({ ...ctx, activityNo: 88, receiveNo: '2' }, {})
57
+ assert.equal(r2.receiveNo, 2)
58
+ })
59
+
60
+ test('specify_bets_activity and specify_turnover_activity cover timer and receive branches', async () => {
61
+ const sent = []
62
+ const request = {
63
+ config: { appSecret: 'secret' },
64
+ send: async (req) => {
65
+ sent.push(req)
66
+ if (req.url === 'activities')
67
+ return { data: { activityNo: 7, receiveStatus: 2, receiveNo: '2', taskTimer: 1, registerTime: 0, activityEndTime: 1 } }
68
+ if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
69
+ return { data: [] }
70
+ },
71
+ }
72
+
73
+ const bets = specifyBetsActivityFactory(request, { activityNo: 7 })
74
+ const bActions = bets.options.actions
75
+ const bGuards = bets.options.guards
76
+ const bServices = bets.options.services
77
+ const bCtx = bets.initialState.context
78
+ let typeSeen = null
79
+ bActions.doCallback({ ...bCtx, callback: (type) => (typeSeen = type) }, { data: { type: 'bets' } })
80
+ assert.equal(typeSeen, 'bets')
81
+ assert.equal(bActions.setActivityNo.assignment(bCtx, { data: 8 }).activityNo, 8)
82
+ assert.equal(bActions.setActivityDetail.assignment(bCtx, { data: { receiveStatus: 0 } }).activityDetail.receiveStatus, 0)
83
+ assert.equal(typeof bActions.setCallback.assignment(bCtx, { data: {} }).callback, 'function')
84
+ assert.ok(bActions.setDuration.assignment({ ...bCtx, activityDetail: { taskTimer: 1, registerTime: 0 } }, {}).duration >= 0)
85
+ assert.ok(
86
+ bActions.setDuration.assignment({ ...bCtx, activityDetail: { taskTimer: 0, activityEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >=
87
+ 0
88
+ )
89
+ assert.equal(bGuards.isReceivable({ ...bCtx, activityDetail: { receiveStatus: 2 } }, {}), true)
90
+ assert.equal(bGuards.isReceived({ ...bCtx, activityDetail: { receiveStatus: 1 } }, {}), true)
91
+ assert.equal(bGuards.isOngoing({ ...bCtx, activityDetail: { receiveStatus: 0 } }, {}), true)
92
+ await bServices.fetchActivityDetail({ ...bCtx, activityNo: 7 }, {})
93
+ await bServices.receiveReward({ ...bCtx, activityDetail: { activityNo: 7, receiveNo: '0' } }, {})
94
+ const bReward = await bServices.receiveReward({ ...bCtx, activityDetail: { activityNo: 7, receiveNo: '2' } }, {})
95
+ assert.equal(bReward.receiveNo, 2)
96
+
97
+ const turnover = specifyTurnoverActivityFactory(request, { activityNo: 9 })
98
+ const tActions = turnover.options.actions
99
+ const tGuards = turnover.options.guards
100
+ const tServices = turnover.options.services
101
+ const tCtx = turnover.initialState.context
102
+ tActions.doCallback({ ...tCtx, callback: (type) => (typeSeen = type) }, { data: { type: 'turnover' } })
103
+ assert.equal(typeSeen, 'turnover')
104
+ assert.equal(tActions.setActivityNo.assignment(tCtx, { data: 10 }).activityNo, 10)
105
+ assert.equal(tActions.setActivityDetail.assignment(tCtx, { data: { receiveStatus: 1 } }).activityDetail.receiveStatus, 1)
106
+ assert.equal(typeof tActions.setCallback.assignment(tCtx, { data: {} }).callback, 'function')
107
+ assert.ok(tActions.setDuration.assignment({ ...tCtx, activityDetail: { activityEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
108
+ assert.equal(tGuards.isReceivable({ ...tCtx, activityDetail: { receiveStatus: 2 } }, {}), true)
109
+ assert.equal(tGuards.isReceived({ ...tCtx, activityDetail: { receiveStatus: 1 } }, {}), true)
110
+ assert.equal(tGuards.isOngoing({ ...tCtx, activityDetail: { receiveStatus: 0 } }, {}), true)
111
+ await tServices.fetchActivityDetail({ ...tCtx, activityNo: 9 }, {})
112
+ await tServices.receiveReward({ ...tCtx, activityDetail: { activityNo: 9, receiveNo: '0' } }, {})
113
+ const tReward = await tServices.receiveReward({ ...tCtx, activityDetail: { activityNo: 9, receiveNo: '2' } }, {})
114
+ assert.equal(tReward.receiveNo, 2)
115
+ })
116
+
117
+ test('deposit_activity and return_bonus_activity cover guards/filter/reward branches', async () => {
118
+ const request = {
119
+ config: { appSecret: 'secret' },
120
+ send: async (req) => {
121
+ if (req.url === 'activities') return { data: { achieveStatus: 1, deadline: Math.floor(Date.now() / 1000) + 100, rebateAmount: 0 } }
122
+ if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
123
+ if (req.url === 'activities/rewards' && req.method === 'get')
124
+ return { data: [{ activityType: 4, receiveStatus: 0, activityNo: 3, receiveNo: '2' }] }
125
+ return { data: [] }
126
+ },
127
+ }
128
+
129
+ const deposit = depositActivityFactory(request, { activityNo: 1 })
130
+ const dActions = deposit.options.actions
131
+ const dGuards = deposit.options.guards
132
+ const dServices = deposit.options.services
133
+ const dCtx = deposit.initialState.context
134
+ assert.equal(dActions.setActivityNo.assignment(dCtx, { data: 2 }).activityNo, 2)
135
+ assert.equal(dActions.setActivityDetail.assignment(dCtx, { data: { achieveStatus: 1 } }).activityDetail.achieveStatus, 1)
136
+ assert.ok(dActions.setDuration.assignment({ ...dCtx, activityDetail: { deadline: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
137
+ assert.equal(dGuards.isExpired({ ...dCtx, duration: 0 }, {}), true)
138
+ assert.equal(dGuards.isNotAvailable({ ...dCtx, activityDetail: { achieveStatus: 0 } }, {}), true)
139
+ await dServices.fetchActivityDetail({ ...dCtx, activityNo: 1 }, {})
140
+
141
+ const bonus = returnBonusActivityFactory(request)
142
+ const rActions = bonus.options.actions
143
+ const rGuards = bonus.options.guards
144
+ const rServices = bonus.options.services
145
+ const rCtx = bonus.initialState.context
146
+ assert.equal(rActions.setActivityNo.assignment(rCtx, { data: 10 }).activityNo, 10)
147
+ assert.equal(rActions.setActivityDetail.assignment(rCtx, { data: { rebateAmount: 10 } }).activityDetail.rebateAmount, 10)
148
+ const filtered = rActions.setRewardList.assignment(rCtx, {
149
+ data: [
150
+ { activityType: 4, receiveStatus: 0, receiveNo: '2', activityNo: 3 },
151
+ { activityType: 4, receiveStatus: 1, receiveNo: '3', activityNo: 4 },
152
+ ],
153
+ })
154
+ assert.equal(filtered.rewardList.length, 1)
155
+ assert.equal(rActions.setRewardList.assignment(rCtx, { data: null }).rewardList.length, 0)
156
+ assert.equal(typeof rActions.setCallback.assignment(rCtx, { data: {} }).callback, 'function')
157
+ rActions.doCallback({ ...rCtx, callback: () => {} }, {})
158
+ assert.equal(rGuards.isActivityChanged({ ...rCtx, activityNo: 1 }, { data: 2 }), true)
159
+ assert.equal(rGuards.hasActivityNo({ ...rCtx, activityNo: 1 }, {}), 1)
160
+ assert.equal(rGuards.isReceivable({ ...rCtx, rewardList: [{}] }, {}), true)
161
+ assert.equal(rGuards.isNotReceivableYet({ ...rCtx, rewardList: [], activityDetail: { rebateAmount: 10 } }, {}), true)
162
+ await rServices.fetchActivityDetail({ ...rCtx, activityNo: 3 }, {})
163
+ const rr = await rServices.receiveReward({ ...rCtx, rewardList: [{ activityNo: 3, receiveNo: '2' }] }, {})
164
+ assert.equal(rr.receiveNo, 2)
165
+ const list = await rServices.fetchRewardList(rCtx, {})
166
+ assert.equal(list.length, 1)
167
+ })
168
+
169
+ test('welcome machine guards/actions/services cover first-login flow branches', async () => {
170
+ global.localStorage = createLocalStorageMock()
171
+
172
+ const sent = []
173
+ const request = {
174
+ send: async (req) => {
175
+ sent.push(req)
176
+ if (req.url === 'self' && req.method === 'get') return { uid: 'u1', topup: 0, verification_status: 0 }
177
+ if (req.url === 'payment/v2/setting') return { ok: true }
178
+ if (req.url === 'self' && req.method === 'post') return { ok: true }
179
+ return { data: {} }
180
+ },
181
+ }
182
+ const machine = welcomeFactory(request)
183
+ const actions = machine.options.actions
184
+ const guards = machine.options.guards
185
+ const services = machine.options.services
186
+ const ctx = machine.initialState.context
187
+
188
+ assert.equal(actions.setUserInfo.assignment(ctx, { data: { uid: 'u1' } }).userInfo.uid, 'u1')
189
+ assert.equal(actions.setBonus.assignment(ctx, { data: 5 }).bonus, 5)
190
+ assert.equal(actions.setGender.assignment(ctx, { data: 'M' }).gender, 'M')
191
+ actions.setInfo({ ...ctx, userInfo: { uid: 'u1' } }, {})
192
+ assert.equal(global.localStorage.getItem('welcome_u1') !== null, true)
193
+
194
+ global.localStorage.clear()
195
+ assert.equal(guards.isFirstLogin({ ...ctx, userInfo: { uid: 'u2', topup: 0, verification_status: 0 } }, {}), true)
196
+ assert.equal(guards.isFirstLogin({ ...ctx, userInfo: { uid: 'u2', topup: 1, verification_status: 0 } }, {}), false)
197
+ assert.equal(guards.isFilled({ ...ctx, bonus: 1, gender: 'F' }, {}), true)
198
+ assert.equal(guards.isFilled({ ...ctx, bonus: null, gender: 'F' }, {}), false)
199
+
200
+ const info = await services.fetchUserInfo(ctx, {})
201
+ assert.equal(info.uid, 'u1')
202
+ await services.updatingInfo({ ...ctx, bonus: 1, gender: 'M' }, {})
203
+ assert.equal(
204
+ sent.some((req) => req.url === 'payment/v2/setting'),
205
+ true
206
+ )
207
+ assert.equal(
208
+ sent.some((req) => req.url === 'self' && req.method === 'post'),
209
+ true
210
+ )
211
+ })
@@ -0,0 +1,201 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import ambFactory from '../src/machine/deposit/amb.js'
5
+ import rewardFcFactory from '../src/machine/reward_fc.js'
6
+ import websocketFactory from '../src/machine/websocket.js'
7
+
8
+ test('deposit amb covers user account guard and initialization mapping', async () => {
9
+ const request = {
10
+ send: async (req) => {
11
+ if (req.url === 'payment/v2/paymentInfo') {
12
+ return {
13
+ bankInfo: [
14
+ { bindingType: 'BANK', id: 1 },
15
+ { bindingType: 'CRYPTO', id: 2 },
16
+ { bindingType: 'EWALLET', id: 3 },
17
+ ],
18
+ }
19
+ }
20
+ if (req.url === 'payment/v2/amb/transaction') {
21
+ return { accountName: 'House', accountNumber: '123', bankName: 'AMB Bank' }
22
+ }
23
+ if (req.url === 'payment/v2/amb/getBankList') {
24
+ return { data: [{ bankCode: 'AMB1' }] }
25
+ }
26
+ return {}
27
+ },
28
+ }
29
+
30
+ const machine = ambFactory(request)
31
+ const actions = machine.options.actions
32
+ const guards = machine.options.guards
33
+ const services = machine.options.services
34
+ const ctx = machine.initialState.context
35
+
36
+ assert.equal(actions.setUserAccount.assignment(ctx, { data: [{ id: 1 }] }).userAccount.id, 1)
37
+ const initA = actions.setInitialization.assignment(ctx, {
38
+ data: {
39
+ houseAccount: { accountName: 'A', accountNumber: 'B', bankName: 'C' },
40
+ bankList: { data: [{ bankCode: 'X' }] },
41
+ },
42
+ })
43
+ assert.equal(initA.houseAccountName, 'A')
44
+ assert.equal(initA.bankList[0].bankCode, 'X')
45
+ const initB = actions.setInitialization.assignment(ctx, {
46
+ data: {
47
+ houseAccount: { accountName: 'A', accountNumber: 'B', bankName: 'C' },
48
+ bankList: [{ bankCode: 'Y' }],
49
+ },
50
+ })
51
+ assert.equal(initB.bankList[0].bankCode, 'Y')
52
+
53
+ assert.equal(guards.hasUserAccount(ctx, { data: [{ id: 1 }] }).id, 1)
54
+ assert.equal(guards.hasUserAccount(ctx, { data: [] }), undefined)
55
+
56
+ const paymentInfo = await services.fetchPaymentInfo(ctx, {})
57
+ assert.equal(paymentInfo.length, 1)
58
+ const init = await services.initialize(ctx, {})
59
+ assert.equal(init.houseAccount.accountName, 'House')
60
+ assert.equal(init.bankList.data[0].bankCode, 'AMB1')
61
+ })
62
+
63
+ test('reward_fc covers setRewardList fallback and receive validation', async () => {
64
+ const request = {
65
+ config: { appSecret: 'secret' },
66
+ send: async (req) => {
67
+ if (req.url === 'activities/rewards' && req.method === 'get') return { data: [{ receiveNo: 1 }] }
68
+ if (req.url === 'activities/rewards' && req.method === 'post') return { ok: true, receiveNo: req.params.receiveNo }
69
+ return {}
70
+ },
71
+ }
72
+ const machine = rewardFcFactory(request)
73
+ const actions = machine.options.actions
74
+ const services = machine.options.services
75
+ const ctx = machine.initialState.context
76
+
77
+ assert.equal(actions.setRewardList.assignment(ctx, { data: null }).rewardList.length, 0)
78
+ assert.equal(actions.setRewardList.assignment(ctx, { data: [{ id: 1 }] }).rewardList.length, 1)
79
+ let called = 0
80
+ actions.doCallback({ ...ctx, callback: () => called++ }, {})
81
+ assert.equal(called, 1)
82
+ const fallbackCb = actions.setCallback.assignment(ctx, { data: {} }).callback
83
+ assert.equal(typeof fallbackCb, 'function')
84
+ assert.doesNotThrow(() => fallbackCb())
85
+ assert.equal(typeof actions.setCallback.assignment(ctx, { data: { callback: () => 1 } }).callback, 'function')
86
+
87
+ const list = await services.fetchRewardList(ctx, {})
88
+ assert.equal(list.length, 1)
89
+ const r0 = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '0', attended: false } })
90
+ assert.equal(r0.receiveNo, undefined)
91
+ const rBlank = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: ' ', attended: false } })
92
+ assert.equal(rBlank.receiveNo, undefined)
93
+ const r2 = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '2', attended: false } })
94
+ assert.equal(r2.receiveNo, 2)
95
+ })
96
+
97
+ test('websocket additional actions/listeners branches are covered', () => {
98
+ const request = {
99
+ config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', sentry: { captureException: () => {} } },
100
+ getToken: () => 't',
101
+ }
102
+ const machine = websocketFactory(request)
103
+ const actions = machine.options.actions
104
+ const ctx = machine.initialState.context
105
+
106
+ assert.equal(actions.saveSocketURL.assignment(ctx, { data: { socketURL: 'wss://new' } }).socketURL, 'wss://new')
107
+ assert.equal(actions.setConnecting.assignment(ctx, {}).connectStatus, 1)
108
+
109
+ let disconnected = false
110
+ const patched = actions.disconnectSocket.assignment({ ...ctx, clientSocket: { disconnect: () => (disconnected = true) } }, {})
111
+ assert.equal(disconnected, true)
112
+ assert.equal(patched.clientSocket, null)
113
+
114
+ const callbacks = []
115
+ const handlers = {}
116
+ const removed = []
117
+ const fakeSocket = {
118
+ id: 's1',
119
+ on: (event, fn) => (handlers[event] = fn),
120
+ off: (event) => removed.push(event),
121
+ }
122
+ const listen = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocket })
123
+ const cleanup = listen((event) => callbacks.push(event))
124
+ handlers['activity-reward-info']?.({ x: 1 })
125
+ handlers['message-notice-info']?.({ y: 1 })
126
+ handlers['payment-info']?.({ windowType: 'modal' })
127
+ assert.equal(
128
+ callbacks.some((e) => e.type === 'ACTIVITY_INFO'),
129
+ true
130
+ )
131
+ cleanup()
132
+ assert.equal(removed.includes('activity-info'), true)
133
+ assert.equal(removed.includes('disconnect'), true)
134
+
135
+ // null socket should safely no-op
136
+ assert.doesNotThrow(() => machine.options.services.listenToSocketEvents({ clientSocket: null })(() => {}))
137
+
138
+ // cleanup should no-op when socket.off is unavailable
139
+ const fakeSocketNoOff = { id: 's2', on: () => {} }
140
+ const cleanupNoOff = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocketNoOff })(() => {})
141
+ assert.doesNotThrow(() => cleanupNoOff())
142
+ })
143
+
144
+ test('websocket connectSocket and fetchSocket fallback branches are covered', async () => {
145
+ let offCalled = 0
146
+ const socketIoConnect = () => {
147
+ const handlers = {}
148
+ const sock = {
149
+ id: 'sid-1',
150
+ on: (event, fn) => {
151
+ handlers[event] = fn
152
+ if (event === 'connect') setTimeout(() => handlers.connect?.(), 0)
153
+ },
154
+ off: () => {
155
+ offCalled += 1
156
+ },
157
+ }
158
+ return sock
159
+ }
160
+ const socketIoError = () => {
161
+ const handlers = {}
162
+ const sock = {
163
+ id: 'sid-2',
164
+ on: (event, fn) => {
165
+ handlers[event] = fn
166
+ if (event === 'connect_error') setTimeout(() => handlers.connect_error?.({ message: 'nope' }), 0)
167
+ },
168
+ }
169
+ return sock
170
+ }
171
+
172
+ const requestConnect = {
173
+ config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', socketIo: socketIoConnect },
174
+ getToken: () => 'token',
175
+ }
176
+ const machineConnect = websocketFactory(requestConnect)
177
+ const connected = await machineConnect.options.services.connectSocket({ ...machineConnect.initialState.context, socketURL: 'wss://x' }, {})
178
+ assert.equal(connected.id, 'sid-1')
179
+ assert.equal(offCalled > 0, true)
180
+
181
+ const requestError = {
182
+ config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', socketIo: socketIoError },
183
+ getToken: () => 'token',
184
+ }
185
+ const machineError = websocketFactory(requestError)
186
+ await assert.rejects(
187
+ () => machineError.options.services.connectSocket({ ...machineError.initialState.context, socketURL: 'wss://x' }, {}),
188
+ (error) => error === 'nope'
189
+ )
190
+
191
+ const originalFetch = global.fetch
192
+ global.fetch = async (url) => {
193
+ if (String(url).endsWith('target.json')) {
194
+ return { json: async () => ({ socket: ['https://dead-1', 'https://dead-2'] }) }
195
+ }
196
+ throw new Error('ping fail')
197
+ }
198
+ const fallback = await machineConnect.options.services.fetchSocket({ url: 'https://storage.googleapis.com/x/target.json' }, {})
199
+ assert.equal(fallback.socketURL, 'https://dead-1')
200
+ global.fetch = originalFetch
201
+ })
@@ -0,0 +1,215 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import authFactory from '../src/machine/auth.js'
5
+ import { createLocalStorageMock } from './helpers.js'
6
+
7
+ function createRequestStub({ deviceTokenExists = true, getDeviceTokenWithRetry } = {}) {
8
+ const calls = []
9
+ return {
10
+ calls,
11
+ request: {
12
+ hosts: ['https://fnapi1.example.com'],
13
+ config: {
14
+ appSecret: 'secret',
15
+ clientId: 'client',
16
+ fpToken: 'fp-token',
17
+ defaultChannel: 'default-channel',
18
+ defaultSubchannel: 'default-sub',
19
+ fullURL: 'https://member.example.com',
20
+ sentry: {
21
+ captureMessage: () => {},
22
+ setUser: () => {},
23
+ captureException: () => {},
24
+ },
25
+ getDeviceTokenWithRetry,
26
+ },
27
+ send: async (req) => {
28
+ calls.push(req)
29
+ if (req.url === 'appLogin') return { token: 'app-token' }
30
+ if (req.url === 'login') return { token: 'login-token' }
31
+ if (req.url === 'guestLogin') return { token: 'guest-token' }
32
+ if (req.url === 'logout') return { ok: true }
33
+ if (req.url === 'self') return { uid_site: 'U100', rank: 1 }
34
+ if (req.url === 'checkDt') return { exist: deviceTokenExists }
35
+ if (req.url === 'updateDt') return { ok: true }
36
+ if (req.url === 'getConfig') {
37
+ const raw = JSON.stringify({
38
+ loginMethods: { local: true, phone: false },
39
+ registerMethods: { local: true, email: false },
40
+ dtVerify: true,
41
+ })
42
+ return { config: Buffer.from(raw, 'binary').toString('base64') }
43
+ }
44
+ return {}
45
+ },
46
+ },
47
+ }
48
+ }
49
+
50
+ test('auth actions: account/token/redirect/user/play paths are covered', async () => {
51
+ global.localStorage = createLocalStorageMock()
52
+ global.window = {
53
+ location: {
54
+ href: 'https://member.example.com/current',
55
+ protocol: 'https:',
56
+ host: 'member.example.com',
57
+ },
58
+ atob: (v) => Buffer.from(v, 'base64').toString('binary'),
59
+ }
60
+
61
+ const { request } = createRequestStub()
62
+ const machine = authFactory(request)
63
+ const actions = machine.options.actions
64
+ const delays = machine.options.delays
65
+ const guards = machine.options.guards
66
+
67
+ storageSet('cuora_client', 'token-from-storage')
68
+ assert.equal(actions.fetchToken.assignment(machine.initialState.context, {}).token, 'token-from-storage')
69
+
70
+ assert.equal(actions.setToken.assignment(machine.initialState.context, { data: 'token-1' }).token, 'token-1')
71
+ assert.equal(actions.extendToken.assignment(machine.initialState.context, {}).token, 'token-1')
72
+ assert.equal(actions.removeToken.assignment(machine.initialState.context, {}).token, null)
73
+
74
+ actions.setAccount.assignment(
75
+ {
76
+ ...machine.initialState.context,
77
+ loginData: { username: 'alice' },
78
+ },
79
+ {}
80
+ )
81
+ assert.equal(storageGet('account_username'), 'alice')
82
+
83
+ actions.setAccount.assignment(
84
+ {
85
+ ...machine.initialState.context,
86
+ loginData: { phone: '0800000000', countryCode: '66' },
87
+ countryAbbr: 'TH',
88
+ },
89
+ {}
90
+ )
91
+ assert.equal(storageGet('account_phone'), '0800000000')
92
+ assert.equal(storageGet('phone_countrycode'), 'TH_66')
93
+
94
+ actions.setAccount.assignment(
95
+ {
96
+ ...machine.initialState.context,
97
+ loginData: { email: 'a@example.com' },
98
+ },
99
+ {}
100
+ )
101
+ assert.equal(storageGet('account_email'), 'a@example.com')
102
+
103
+ storageSet('ac', 'AFF')
104
+ storageSet('nk', 'Nick')
105
+ storageSet('channel', 'stored-channel')
106
+ storageSet('subchannel', 'stored-sub')
107
+ await actions.redirectTo3Party(
108
+ {
109
+ ...machine.initialState.context,
110
+ base: '/entry',
111
+ siteConfig: { dtVerify: false },
112
+ },
113
+ { data: { provider: 'google', channel: 'ev-channel', subchannel: 'ev-sub', fc: 'FC1' } }
114
+ )
115
+ assert.equal(window.location.href.includes('/login?'), true)
116
+ assert.equal(window.location.href.includes('provider=google'), true)
117
+ assert.equal(window.location.href.includes('ac=AFF'), true)
118
+
119
+ const userInfoPatch = actions.setUserInfo.assignment(machine.initialState.context, { data: { uid_site: 'U100', rank: 1 } })
120
+ assert.equal(userInfoPatch.userInfo.uid_site, 'U100')
121
+ assert.equal(actions.setPlay.assignment(machine.initialState.context, { data: true }).isPlaying, true)
122
+
123
+ const setSiteConfig = actions.setSiteConfig.assignment(machine.initialState.context, {
124
+ data: {
125
+ loginMethods: { local: true, phone: false },
126
+ registerMethods: { local: true, email: false },
127
+ },
128
+ })
129
+ assert.deepEqual(setSiteConfig.siteConfig.loginMethods, { local: true })
130
+ assert.deepEqual(setSiteConfig.siteConfig.registerMethods, { local: true })
131
+
132
+ assert.equal(delays.TIMEOUT({ tick: 2, isPlaying: false }, {}), 2)
133
+ assert.equal(delays.TIMEOUT({ tick: 2, isPlaying: true }, {}), 10)
134
+ assert.equal(guards.hasToken({ token: 't' }, {}), 't')
135
+ assert.equal(guards.isInline({ userInfo: { rank: 0 } }, {}), true)
136
+ assert.equal(guards.isNotInline({ userInfo: { rank: -1 } }, {}), true)
137
+ })
138
+
139
+ test('auth services: login/guest/app/logout/self/checkDt/getConfig', async () => {
140
+ global.localStorage = createLocalStorageMock()
141
+ global.window = {
142
+ atob: (v) => Buffer.from(v, 'base64').toString('binary'),
143
+ location: { href: 'https://member.example.com' },
144
+ }
145
+
146
+ const { request, calls } = createRequestStub()
147
+ const machine = authFactory(request)
148
+ const services = machine.options.services
149
+
150
+ const appToken = await services.authenticateApp({}, { data: { provider: 'google', accessToken: 'at' } })
151
+ assert.equal(appToken, 'app-token')
152
+
153
+ const loginToken = await services.authenticate(
154
+ {
155
+ ...machine.initialState.context,
156
+ loginData: { provider: 'local', username: 'alice', password: 'pw' },
157
+ reCaptchaToken: 'captcha',
158
+ },
159
+ {}
160
+ )
161
+ assert.equal(loginToken, 'login-token')
162
+
163
+ const guestToken = await services.authenticateGuest({}, {})
164
+ assert.equal(guestToken, 'guest-token')
165
+
166
+ const logoutRes = await services.logout({}, {})
167
+ assert.equal(logoutRes.ok, true)
168
+
169
+ const self = await services.fetchUserInfo({}, {})
170
+ assert.equal(self.uid_site, 'U100')
171
+
172
+ await services.checkDeviceToken({ siteConfig: { dtVerify: true } }, {})
173
+ await services.checkDeviceToken({ siteConfig: { dtVerify: false } }, {})
174
+
175
+ const cfg = await services.fetchSiteConfig({}, {})
176
+ assert.equal(cfg.dtVerify, true)
177
+ assert.deepEqual(cfg.loginMethods, { local: true, phone: false })
178
+ assert.equal(
179
+ calls.some((req) => req.url === 'checkDt'),
180
+ true
181
+ )
182
+ assert.equal(
183
+ calls.some((req) => req.url === 'getConfig'),
184
+ true
185
+ )
186
+ })
187
+
188
+ test('auth checkDeviceToken updates dt when checkDt says not exist', async () => {
189
+ global.localStorage = createLocalStorageMock()
190
+ global.window = {
191
+ atob: (v) => Buffer.from(v, 'base64').toString('binary'),
192
+ location: { href: 'https://member.example.com' },
193
+ }
194
+
195
+ const { request, calls } = createRequestStub({
196
+ deviceTokenExists: false,
197
+ getDeviceTokenWithRetry: async () => 'dt-123',
198
+ })
199
+ const machine = authFactory(request)
200
+ const services = machine.options.services
201
+
202
+ await services.checkDeviceToken({ siteConfig: { dtVerify: true } }, {})
203
+ assert.equal(
204
+ calls.some((req) => req.url === 'updateDt' && req.params.dt === 'dt-123'),
205
+ true
206
+ )
207
+ })
208
+
209
+ function storageGet(key) {
210
+ return JSON.parse(localStorage.getItem(key)).value
211
+ }
212
+
213
+ function storageSet(key, value) {
214
+ localStorage.setItem(key, JSON.stringify({ value }))
215
+ }