@jetthai/cuora 1.2.0 → 2.0.0-beta.1

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 +21 -8
  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 +41 -7
  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 +18 -10
  57. package/src/machine/deposit/manual_vn.js +10 -5
  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 +14 -2
  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 +13 -2
  72. package/src/machine/game_search_v2.js +1 -0
  73. package/src/machine/game_v2_1.js +129 -50
  74. package/src/machine/honor_board.js +19 -7
  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 +195 -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 +148 -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 +629 -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,199 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import gameSearchV2Factory from '../src/machine/game_search_v2.js'
5
+
6
+ test('game_search_v2 actions and guards cover keyword/tag/game routing branches', () => {
7
+ const machine = gameSearchV2Factory({
8
+ send: async () => ({}),
9
+ })
10
+
11
+ const actions = machine.options.actions
12
+ const guards = machine.options.guards
13
+ const base = machine.initialState.context
14
+
15
+ const mainTagList = [{ id: 'm1' }, { id: 'm2' }]
16
+ const tagList = [{ id: 't1' }, { id: 't2' }]
17
+ const recentlySearch = [{ id: 'r1' }, { id: 'r2' }]
18
+
19
+ assert.deepEqual(actions.setMainTagList.assignment(base, { data: mainTagList }), { mainTagList })
20
+
21
+ const initialByRecent = actions.setInitialData.assignment(base, {
22
+ data: {
23
+ recentlySearch: [
24
+ { id: 'a', i18n: 'A' },
25
+ { id: null, i18n: 'B' },
26
+ { id: 'c', i18n: null },
27
+ ],
28
+ recentlyGame: [{ gameCode: 'g1' }],
29
+ youMayLike: [{ gameCode: 'g2' }],
30
+ },
31
+ })
32
+ assert.deepEqual(initialByRecent.recentlySearch, [{ id: 'a', i18n: 'A' }])
33
+ assert.deepEqual(initialByRecent.gameList, [{ gameCode: 'g1' }])
34
+
35
+ const initialByLike = actions.setInitialData.assignment(base, {
36
+ data: {
37
+ recentlySearch: [],
38
+ recentlyGame: [],
39
+ youMayLike: [{ gameCode: 'g3' }],
40
+ },
41
+ })
42
+ assert.deepEqual(initialByLike.gameList, [{ gameCode: 'g3' }])
43
+
44
+ const setMainTagId = actions.setMainTagId.assignment({ ...base, mainTagList }, { data: { tagId: 'm2' } })
45
+ assert.equal(setMainTagId.tagIndex, 1)
46
+ assert.equal(setMainTagId.click, 1)
47
+
48
+ assert.deepEqual(actions.clearMainTag.assignment(base, {}), { tagId: null })
49
+
50
+ const setTagIdRecent = actions.setTagId.assignment(
51
+ { ...base, mainTagList, tagList, recentlySearch },
52
+ { data: { tagId: 'r2', clickTagType: 'RECENTLY SEARCH' } }
53
+ )
54
+ assert.equal(setTagIdRecent.tagIndex, 1)
55
+ assert.equal(setTagIdRecent.click, 1)
56
+
57
+ const setTagIdPopular = actions.setTagId.assignment(
58
+ { ...base, mainTagList, tagList, recentlySearch },
59
+ { data: { tagId: 'm1', clickTagType: 'POPULAR KEYWORDS' } }
60
+ )
61
+ assert.equal(setTagIdPopular.tagIndex, 0)
62
+ assert.equal(setTagIdPopular.clickDefault, 1)
63
+
64
+ const setTagIdPopularByEmptyTagList = actions.setTagId.assignment(
65
+ { ...base, mainTagList, tagList: [], recentlySearch },
66
+ { data: { tagId: 'm2', clickTagType: 'OTHER' } }
67
+ )
68
+ assert.equal(setTagIdPopularByEmptyTagList.tagIndex, 1)
69
+ assert.equal(setTagIdPopularByEmptyTagList.clickDefault, 1)
70
+
71
+ const setTagIdNormal = actions.setTagId.assignment(
72
+ { ...base, mainTagList, tagList, recentlySearch },
73
+ { data: { tagId: 't2', clickTagType: 'OTHER' } }
74
+ )
75
+ assert.equal(setTagIdNormal.tagIndex, 1)
76
+ assert.equal(setTagIdNormal.click, 1)
77
+
78
+ assert.deepEqual(actions.setGames.assignment(base, { data: { traceId: 'tr1', result: [{ id: 1 }] } }), {
79
+ traceId: 'tr1',
80
+ gameList: [{ id: 1 }],
81
+ })
82
+ assert.deepEqual(actions.setGames.assignment({ ...base, tagId: 'Recently', recentlyGame: [{ id: 'rg' }] }, {}), {
83
+ traceId: null,
84
+ gameList: [{ id: 'rg' }],
85
+ })
86
+ assert.deepEqual(actions.setGames.assignment({ ...base, tagId: 'You may like', youMayLike: [{ id: 'yl' }] }, {}), {
87
+ traceId: null,
88
+ gameList: [{ id: 'yl' }],
89
+ })
90
+
91
+ assert.deepEqual(
92
+ actions.setTraceData.assignment(base, {
93
+ data: { traceData: { isYouMayLike: true, isRecentlyGame: false, isRecentlySearch: true } },
94
+ }),
95
+ { isYouMayLike: true, isRecentlyGame: false, isRecentlySearch: true }
96
+ )
97
+ assert.deepEqual(actions.setKeyword.assignment(base, { data: { keyword: 'slot' } }), { keyword: 'slot' })
98
+ assert.deepEqual(actions.setLang.assignment(base, { data: { lang: 'th-TH' } }), { lang: 'th-TH' })
99
+ assert.deepEqual(actions.clearKeywords.assignment(base, {}), { keyword: '' })
100
+ assert.deepEqual(actions.setTagList.assignment(base, { data: tagList }), { tagList })
101
+
102
+ const setGameCode = actions.setGameCode.assignment({ ...base, gameList: [{ gameCode: 'G1' }, { gameCode: 'G2' }] }, { data: 'G2' })
103
+ assert.equal(setGameCode.gameCode, 'G2')
104
+ assert.equal(setGameCode.gameCodeIndex, 1)
105
+
106
+ const clearExceptKeyword = actions.clearExceptKeyword.assignment({ ...base, keyword: 'fish', gameList: [{ id: 1 }], traceId: 't' }, {})
107
+ assert.equal(clearExceptKeyword.query, 'fish')
108
+ assert.deepEqual(clearExceptKeyword.gameList, [])
109
+ assert.equal(clearExceptKeyword.tagId, null)
110
+
111
+ assert.equal(guards.isRecentlyYouMayLike({ tagId: 'Recently' }, {}), true)
112
+ assert.equal(guards.isRecentlyYouMayLike({ tagId: 'You may like' }, {}), true)
113
+ assert.equal(guards.isRecentlyYouMayLike({ tagId: 'Other' }, {}), false)
114
+ assert.equal(guards.hasTagList({ tagList: [{ id: 1 }] }, {}), true)
115
+ assert.equal(guards.hasTagList({ tagList: [] }, {}), false)
116
+
117
+ const pressEnterSend = machine.config.states.searching.states.searchIdle.on.PRESS_ENTER[0].actions
118
+ const sendEvent = pressEnterSend.event({ ...base, tagList: [{ id: 'top-tag' }] }, {})
119
+ assert.equal(sendEvent.type, 'SET_TAG_ID')
120
+ assert.equal(sendEvent.data.tagId, 'top-tag')
121
+ assert.deepEqual(sendEvent.data.traceData, {
122
+ isYouMayLike: false,
123
+ isRecentlyGame: false,
124
+ isRecentlySearch: false,
125
+ })
126
+ })
127
+
128
+ test('game_search_v2 services call expected endpoints and normalize sendTrace id', async () => {
129
+ const calls = []
130
+ const request = {
131
+ send: async (req) => {
132
+ calls.push(req)
133
+ if (req.url === 'game/search') {
134
+ return { result: [{ id: 'tag-1' }] }
135
+ }
136
+ if (req.url === 'game/search/home') {
137
+ return { recentlySearch: [], recentlyGame: [], youMayLike: [] }
138
+ }
139
+ if (req.url === 'game/search/list') {
140
+ return { traceId: 'TRACE-1', result: [{ gameCode: 'GG' }] }
141
+ }
142
+ if (req.url === 'game/search/trace') {
143
+ return { ok: true, params: req.params }
144
+ }
145
+ return {}
146
+ },
147
+ }
148
+ const machine = gameSearchV2Factory(request)
149
+ const services = machine.options.services
150
+
151
+ const tags = await services.fetchTags({ keyword: 'slot', lang: 'en-US' }, {})
152
+ assert.deepEqual(tags, [{ id: 'tag-1' }])
153
+
154
+ const home = await services.fetchInitialData({}, {})
155
+ assert.deepEqual(home, { recentlySearch: [], recentlyGame: [], youMayLike: [] })
156
+
157
+ const games = await services.fetchGames({ tagId: 'm1', tagIndex: 2, keyword: 'jackpot', click: 1, clickDefault: null }, {})
158
+ assert.deepEqual(games, { traceId: 'TRACE-1', result: [{ gameCode: 'GG' }] })
159
+
160
+ const traceNormal = await services.sendTrace(
161
+ {
162
+ traceId: 'T1',
163
+ tagId: 'm1',
164
+ tagIndex: 0,
165
+ gameCode: 'G1',
166
+ gameCodeIndex: 1,
167
+ keyword: 'aaa',
168
+ click: 1,
169
+ clickDefault: null,
170
+ isYouMayLike: false,
171
+ isRecentlyGame: false,
172
+ isRecentlySearch: false,
173
+ },
174
+ {}
175
+ )
176
+ assert.equal(traceNormal.ok, true)
177
+
178
+ const traceSpecial = await services.sendTrace(
179
+ {
180
+ traceId: 'T2',
181
+ tagId: 'Recently',
182
+ tagIndex: 0,
183
+ gameCode: 'G2',
184
+ gameCodeIndex: 2,
185
+ keyword: 'bbb',
186
+ click: 1,
187
+ clickDefault: null,
188
+ isYouMayLike: true,
189
+ isRecentlyGame: true,
190
+ isRecentlySearch: true,
191
+ },
192
+ {}
193
+ )
194
+ assert.equal(traceSpecial.params.tagId, null)
195
+ assert.equal(
196
+ calls.some((req) => req.url === 'game/search/trace'),
197
+ true
198
+ )
199
+ })
@@ -0,0 +1,100 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import gameInfoFactory from '../src/machine/game_info.js'
5
+ import gameBetslipFactory from '../src/machine/game_betslip.js'
6
+ import gameReplayFactory from '../src/machine/game_replay.js'
7
+ import userInfoFactory from '../src/machine/user_info.js'
8
+ import userPhotoFactory from '../src/machine/user_photo.js'
9
+
10
+ test('game_info/game_betslip/game_replay services and actions map responses', async () => {
11
+ const sent = []
12
+ const request = {
13
+ config: { appSecret: 'secret' },
14
+ send: async (req) => {
15
+ sent.push(req)
16
+ if (req.url === 'game/info') return { data: { gameCode: req.params.gameCode } }
17
+ if (req.url === 'game/betslip') return { ticket: 't1' }
18
+ if (req.url === 'game/gameReplay') return { data: { replay: true } }
19
+ return {}
20
+ },
21
+ }
22
+
23
+ const gameInfoWithCode = gameInfoFactory(request, { gameCode: 'G001' })
24
+ const infoActions = gameInfoWithCode.options.actions
25
+ const infoServices = gameInfoWithCode.options.services
26
+ const infoCtx = gameInfoWithCode.initialState.context
27
+ assert.equal(infoActions.setGameInfo.assignment(infoCtx, { data: { data: { name: 'A' } } }).gameInfo.name, 'A')
28
+ const info = await infoServices.fetchGameInfo(infoCtx, {})
29
+ assert.equal(info.data.gameCode, 'G001')
30
+
31
+ const gameInfoNoCode = gameInfoFactory(request, { gameCode: null })
32
+ const emptyInfo = await gameInfoNoCode.options.services.fetchGameInfo(gameInfoNoCode.initialState.context, {})
33
+ assert.deepEqual(emptyInfo, { data: {} })
34
+
35
+ const betslip = gameBetslipFactory(request, { providerId: 'P1', seqNo: 'S1', lang: 'en-US' })
36
+ const bActions = betslip.options.actions
37
+ const bServices = betslip.options.services
38
+ assert.equal(bActions.setBetslip.assignment(betslip.initialState.context, { data: { ticket: 't1' } }).gameBetSlip.ticket, 't1')
39
+ const bData = await bServices.fetchBetslip(betslip.initialState.context, {})
40
+ assert.equal(bData.ticket, 't1')
41
+
42
+ const replay = gameReplayFactory(request, { providerId: 'P1', seqNo: 'S2', lang: 'en-US' })
43
+ const rActions = replay.options.actions
44
+ const rServices = replay.options.services
45
+ assert.equal(rActions.setGameReplayInfo.assignment(replay.initialState.context, { data: { data: { replay: 1 } } }).gameReplayInfo.replay, 1)
46
+ const rData = await rServices.fetchGameReplayInfo(replay.initialState.context, {})
47
+ assert.equal(rData.data.replay, true)
48
+
49
+ assert.equal(
50
+ sent.some((req) => req.url === 'game/betslip'),
51
+ true
52
+ )
53
+ assert.equal(
54
+ sent.some((req) => req.url === 'game/gameReplay'),
55
+ true
56
+ )
57
+ })
58
+
59
+ test('user_info and user_photo services/actions cover fetch and update', async () => {
60
+ const sent = []
61
+ const request = {
62
+ send: async (req) => {
63
+ sent.push(req)
64
+ if (req.url === 'self' && req.method === 'get') return { uid: 'u1', nick: 'A' }
65
+ if (req.url === 'self' && req.method === 'post') return { ok: true, params: req.params }
66
+ if (req.url === 'getAllAvatar') return { data: [{ id: 1 }, { id: 2 }] }
67
+ if (req.url === 'updateUserAvatar') return { ok: true, params: req.params }
68
+ return {}
69
+ },
70
+ }
71
+
72
+ const userInfo = userInfoFactory(request)
73
+ const uiActions = userInfo.options.actions
74
+ const uiServices = userInfo.options.services
75
+ const uiCtx = userInfo.initialState.context
76
+ assert.equal(uiActions.setUserInfo.assignment(uiCtx, { data: { uid: 'u1' } }).userInfo.uid, 'u1')
77
+ const info = await uiServices.fetchUserInfo(uiCtx, {})
78
+ assert.equal(info.uid, 'u1')
79
+ const upd = await uiServices.updateUserInfo(uiCtx, { data: { nick_name: 'B' } })
80
+ assert.equal(upd.ok, true)
81
+
82
+ const userPhoto = userPhotoFactory(request)
83
+ const upActions = userPhoto.options.actions
84
+ const upServices = userPhoto.options.services
85
+ const upCtx = userPhoto.initialState.context
86
+ assert.equal(upActions.setUserPhotoList.assignment(upCtx, { data: { data: [{ id: 1 }] } }).userPhotoList[0].id, 1)
87
+ const list = await upServices.fetchUserPhotoList(upCtx, {})
88
+ assert.equal(list.data.length, 2)
89
+ const updPhoto = await upServices.updateUserPhoto(upCtx, { data: { avatar: 2 } })
90
+ assert.equal(updPhoto.ok, true)
91
+
92
+ assert.equal(
93
+ sent.some((req) => req.url === 'self' && req.method === 'post'),
94
+ true
95
+ )
96
+ assert.equal(
97
+ sent.some((req) => req.url === 'updateUserAvatar'),
98
+ true
99
+ )
100
+ })
@@ -0,0 +1,148 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import honorBoardFactory from '../src/machine/honor_board.js'
5
+ import honorBoardCashFactory from '../src/machine/honor_board_cash.js'
6
+
7
+ function createRequestStub() {
8
+ const calls = []
9
+ return {
10
+ calls,
11
+ request: {
12
+ config: { appSecret: 'secret' },
13
+ send: async (req) => {
14
+ calls.push(req)
15
+ return {
16
+ data: [
17
+ { type: 'DEPOSIT', data: [{ broadcastId: 2, time: 2 }] },
18
+ { type: 'JACKPOT', data: [{ broadcastId: 1, time: 1 }] },
19
+ ],
20
+ }
21
+ },
22
+ },
23
+ }
24
+ }
25
+
26
+ test('honor_board: actions/guard/delay/service branches are stable', async () => {
27
+ const { request, calls } = createRequestStub()
28
+ const machine = honorBoardFactory(request)
29
+
30
+ const setBroadcastList = machine.options.actions.setBroadcastList.assignment
31
+ const setBroadcast = machine.options.actions.setBroadcast.assignment
32
+ const resetBroadcast = machine.options.actions.resetBroadcast.assignment
33
+ const leaveGame = machine.options.actions.leaveGame.assignment
34
+ const isNotInGame = machine.options.guards.isNotInGame
35
+ const timeout = machine.options.delays.TIMEOUT
36
+ const fetchHonorBoardList = machine.options.services.fetchHonorBoardList
37
+
38
+ const sorted = setBroadcastList(machine.initialState.context, {
39
+ data: [{ data: [{ broadcastId: 'b2', time: 3 }] }, { data: [{ broadcastId: 'b1', time: 1 }, { broadcastId: 'b0' }] }],
40
+ })
41
+ assert.deepEqual(
42
+ sorted.broadcastList.map((item) => item.broadcastId),
43
+ ['b0', 'b1', 'b2']
44
+ )
45
+
46
+ const firstPick = setBroadcast(
47
+ {
48
+ ...machine.initialState.context,
49
+ broadcastList: [{ broadcastId: 'a' }, { broadcastId: 'b' }],
50
+ sentNormalBroadcastList: [],
51
+ normalBroadcast: null,
52
+ },
53
+ {}
54
+ )
55
+ assert.equal(firstPick.normalBroadcast.broadcastId, 'a')
56
+
57
+ const secondPick = setBroadcast(
58
+ {
59
+ ...machine.initialState.context,
60
+ broadcastList: [{ broadcastId: 'a' }, { broadcastId: 'b' }],
61
+ sentNormalBroadcastList: [{ broadcastId: 'a' }],
62
+ normalBroadcast: { broadcastId: 'a' },
63
+ },
64
+ {}
65
+ )
66
+ assert.equal(secondPick.normalBroadcast.broadcastId, 'b')
67
+
68
+ const dedupedAndPruned = setBroadcast(
69
+ {
70
+ ...machine.initialState.context,
71
+ broadcastList: [{ broadcastId: 'a' }, { broadcastId: 'b' }],
72
+ sentNormalBroadcastList: [{ broadcastId: 'a' }, { broadcastId: 'a' }, { broadcastId: 'stale' }],
73
+ normalBroadcast: { broadcastId: 'b' },
74
+ },
75
+ {}
76
+ )
77
+ assert.equal(dedupedAndPruned.normalBroadcast, undefined)
78
+ assert.deepEqual(
79
+ dedupedAndPruned.sentNormalBroadcastList.map((item) => item.broadcastId),
80
+ ['a', 'b']
81
+ )
82
+
83
+ assert.equal(resetBroadcast(machine.initialState.context, {}).isPlaying, true)
84
+ assert.equal(leaveGame({ ...machine.initialState.context, isPlaying: true }, {}).isPlaying, false)
85
+ assert.equal(isNotInGame({ isPlaying: false }, {}), true)
86
+ assert.equal(isNotInGame({ isPlaying: true }, {}), false)
87
+ assert.equal(timeout({ tick: 6 }, {}), 60)
88
+
89
+ const data = await fetchHonorBoardList(machine.initialState.context, {})
90
+ assert.equal(Array.isArray(data), true)
91
+ assert.equal(calls.length, 1)
92
+ })
93
+
94
+ test('honor_board_cash: action/delay/service map all tab branches', async () => {
95
+ const calls = []
96
+ const request = {
97
+ config: { appSecret: 'secret' },
98
+ send: async (req) => {
99
+ calls.push(req)
100
+ return {
101
+ data: [
102
+ { type: 'CASH_RAIN', id: 1 },
103
+ { type: 'DEPOSIT', id: 2 },
104
+ { type: 'FREE_ROULETTE_SPIN', id: 3 },
105
+ { type: 'JACKPOT', id: 4 },
106
+ { type: 'WIN_SCORE', id: 5 },
107
+ { type: 'WIN_MULTIPLIER', id: 6 },
108
+ { type: 'WITHDRAW', id: 7 },
109
+ { type: 'UNKNOWN', id: 8 },
110
+ ],
111
+ }
112
+ },
113
+ }
114
+
115
+ const machine = honorBoardCashFactory(request)
116
+ const setHonorBoardList = machine.options.actions.setHonorBoardList.assignment
117
+ const timeout = machine.options.delays.TIMEOUT
118
+ const fetchHonorBoardList = machine.options.services.fetchHonorBoardList
119
+
120
+ const mapped = setHonorBoardList(machine.initialState.context, {
121
+ data: [
122
+ { type: 'CASH_RAIN', value: 1 },
123
+ { type: 'DEPOSIT', value: 2 },
124
+ { type: 'FREE_ROULETTE_SPIN', value: 3 },
125
+ { type: 'JACKPOT', value: 4 },
126
+ { type: 'WIN_SCORE', value: 5 },
127
+ { type: 'WIN_MULTIPLIER', value: 6 },
128
+ { type: 'WITHDRAW', value: 7 },
129
+ { type: 'UNKNOWN', value: 8 },
130
+ ],
131
+ })
132
+ assert.deepEqual(mapped.tabs, ['cashRain', 'deposit', 'roulette', 'jackpot', 'bigWin', 'maxBet', 'withdraw', undefined])
133
+ assert.equal(mapped.cashRain.value, 1)
134
+ assert.equal(mapped.deposit.value, 2)
135
+ assert.equal(mapped.roulette.value, 3)
136
+ assert.equal(mapped.jackpot.value, 4)
137
+ assert.equal(mapped.bigWin.value, 5)
138
+ assert.equal(mapped.maxBet.value, 6)
139
+ assert.equal(mapped.withdraw.value, 7)
140
+ const emptyMapped = setHonorBoardList(machine.initialState.context, { data: null })
141
+ assert.deepEqual(emptyMapped.tabs, [])
142
+ assert.deepEqual(emptyMapped.cashRain, {})
143
+ assert.equal(timeout({ tick: 7 }, {}), 70)
144
+
145
+ const data = await fetchHonorBoardList(machine.initialState.context, {})
146
+ assert.equal(Array.isArray(data), true)
147
+ assert.equal(calls.length, 1)
148
+ })