@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,629 @@
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 gameV21Factory from '../src/machine/game_v2_1.js'
6
+ import withdrawManualFactory from '../src/machine/withdraw/withdraw_manual.js'
7
+ import storage from '../src/util/storage.js'
8
+ import { GAME_SEARCH } from '../src/util/constant.js'
9
+ import { createLocalStorageMock } from './helpers.js'
10
+
11
+ test('user_sign_up actions: phone/email payload mapping and device token toggle', () => {
12
+ const request = {
13
+ config: {
14
+ fpToken: 'fp',
15
+ sentry: { captureMessage: () => {}, captureException: () => {}, setTag: () => {} },
16
+ defaultChannel: 'default-channel',
17
+ defaultSubchannel: 'default-sub',
18
+ },
19
+ send: async () => ({ data: {} }),
20
+ }
21
+ const machine = userSignUpFactory(request)
22
+
23
+ const setSignUpPhone = machine.options.actions.setSignUpPhone.assignment
24
+ const setSignUpEmail = machine.options.actions.setSignUpEmail.assignment
25
+ const setDeviceTokenEnable = machine.options.actions.setDeviceTokenEnable.assignment
26
+
27
+ const phoneResult = setSignUpPhone(machine.initialState.context, {
28
+ data: {
29
+ email: 'p@example.com',
30
+ countryCode: '66',
31
+ phone: '0800000000',
32
+ nick_name: 'P',
33
+ password: 'pw',
34
+ channel: 'ch',
35
+ subchannel: 'sub',
36
+ affiliateCode: 'AFF',
37
+ },
38
+ })
39
+ assert.equal(phoneResult.signUpData.provider, 'phone')
40
+ assert.equal(phoneResult.signUpData.phone, '0800000000')
41
+ assert.equal(phoneResult.channel, 'ch')
42
+
43
+ const emailResult = setSignUpEmail(machine.initialState.context, {
44
+ data: {
45
+ email: 'e@example.com',
46
+ nick_name: 'E',
47
+ password: 'pw',
48
+ channel: 'ch2',
49
+ subchannel: 'sub2',
50
+ countryCode: '66',
51
+ phone: '0811111111',
52
+ },
53
+ })
54
+ assert.equal(emailResult.signUpData.provider, 'email')
55
+ assert.equal(emailResult.signUpData.countryCode, '66')
56
+ assert.equal(emailResult.subchannel, 'sub2')
57
+
58
+ const toggle = setDeviceTokenEnable(machine.initialState.context, { data: false })
59
+ assert.equal(toggle.deviceTokenEnable, false)
60
+ })
61
+
62
+ test('user_sign_up authenticate fallback: no ac and no storage channel uses default config', async () => {
63
+ global.localStorage = createLocalStorageMock()
64
+ global.window = { location: { href: 'https://example.com/reg' } }
65
+
66
+ const sentryMessages = []
67
+ let lastReq = null
68
+ const request = {
69
+ config: {
70
+ fpToken: 'fp',
71
+ sentry: {
72
+ captureMessage: (msg) => sentryMessages.push(msg),
73
+ captureException: () => {},
74
+ setTag: () => {},
75
+ },
76
+ defaultChannel: 'default-channel',
77
+ defaultSubchannel: 'default-sub',
78
+ },
79
+ hosts: [],
80
+ send: async (req) => {
81
+ lastReq = req
82
+ return { data: {} }
83
+ },
84
+ }
85
+ const machine = userSignUpFactory(request)
86
+ const authenticate = machine.options.services.authenticate
87
+
88
+ await authenticate(
89
+ {
90
+ ...machine.initialState.context,
91
+ signUpData: {
92
+ provider: 'local',
93
+ username: 'a',
94
+ password: 'b',
95
+ affiliateCode: null,
96
+ },
97
+ channel: null,
98
+ subchannel: null,
99
+ fc: null,
100
+ reCaptchaToken: 'captcha',
101
+ deviceTokenEnable: false,
102
+ },
103
+ {}
104
+ )
105
+
106
+ assert.equal(lastReq.url.includes('channel=default-channel'), true)
107
+ assert.equal(lastReq.url.includes('subchannel=default-sub'), true)
108
+ assert.equal(lastReq.url.includes('ac='), false)
109
+ assert.equal(sentryMessages.length > 0, true)
110
+ })
111
+
112
+ test('user_sign_up authenticate uses context channel/subchannel when defaults are absent', async () => {
113
+ global.localStorage = createLocalStorageMock()
114
+ global.window = { location: { href: 'https://example.com/reg2' } }
115
+
116
+ let lastReq = null
117
+ const request = {
118
+ config: {
119
+ fpToken: 'fp',
120
+ sentry: {
121
+ captureMessage: () => {},
122
+ captureException: () => {},
123
+ setTag: () => {},
124
+ },
125
+ defaultChannel: null,
126
+ defaultSubchannel: null,
127
+ },
128
+ hosts: [],
129
+ send: async (req) => {
130
+ lastReq = req
131
+ return { data: {} }
132
+ },
133
+ }
134
+ const machine = userSignUpFactory(request)
135
+ const authenticate = machine.options.services.authenticate
136
+
137
+ await authenticate(
138
+ {
139
+ ...machine.initialState.context,
140
+ signUpData: { provider: 'local', username: 'a', password: 'b', affiliateCode: 'undefined' },
141
+ channel: 'ctx-channel',
142
+ subchannel: 'ctx-sub',
143
+ reCaptchaToken: 'captcha',
144
+ deviceTokenEnable: false,
145
+ },
146
+ {}
147
+ )
148
+
149
+ assert.equal(lastReq.url.includes('channel=ctx-channel'), true)
150
+ assert.equal(lastReq.url.includes('subchannel=ctx-sub'), true)
151
+ assert.equal(lastReq.url.includes('ac='), false)
152
+ })
153
+
154
+ test('game_v2_1 actions: append/swap/url/info/flags branches', () => {
155
+ const request = {
156
+ config: { appSecret: 'secret' },
157
+ send: async () => ({}),
158
+ getToken: () => null,
159
+ }
160
+ const machine = gameV21Factory(request)
161
+ const actions = machine.options.actions
162
+ const guards = machine.options.guards
163
+
164
+ const baseContext = {
165
+ ...machine.initialState.context,
166
+ content: { data: [{ id: 1 }], timestamp: 1, totalPage: 5 },
167
+ addition: { data: [{ id: 'a' }], timestamp: 1, totalPage: 5 },
168
+ }
169
+
170
+ const reset = actions.resetContent.assignment(baseContext, {})
171
+ assert.equal(reset.index, -1)
172
+ assert.deepEqual(reset.content.data, [])
173
+ assert.deepEqual(actions.setStaticData.assignment(baseContext, { data: [{ id: 's1', category: 3 }] }), {
174
+ staticData: [{ id: 's1', category: 3 }],
175
+ staticInfoByCategory: { 3: [] },
176
+ })
177
+ assert.deepEqual(actions.setAdditionEnable.assignment(baseContext, { data: true }), { additionEnable: true })
178
+ assert.deepEqual(actions.setLoadable.assignment(baseContext, { data: true }), { loadable: true })
179
+ assert.equal(actions.increaseIndex.assignment({ ...baseContext, index: 3 }, {}).index, 4)
180
+ assert.deepEqual(actions.resetSHA.assignment(baseContext, {}), {})
181
+ assert.equal(actions.setLastPage.assignment({ ...baseContext, index: 4, content: { totalPage: 5 } }, {}).isLastPage, true)
182
+ assert.deepEqual(actions.setRoom.assignment(baseContext, { data: { categoryId: 7 } }), { room: { categoryId: 7 } })
183
+ assert.deepEqual(actions.setBatch.assignment(baseContext, { data: [{ id: 1 }] }), { batch: [{ id: 1 }] })
184
+
185
+ const searchAppend = actions.appendContent.assignment(
186
+ { ...baseContext, room: { categoryId: GAME_SEARCH }, additionEnable: false },
187
+ { data: [{ data: [{ id: 2 }] }] }
188
+ )
189
+ assert.equal(searchAppend, undefined)
190
+
191
+ const appendWithAddition = actions.appendContent.assignment(
192
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: true },
193
+ { data: [{ data: [{ id: 2 }] }, { data: [{ id: 'b' }] }] }
194
+ )
195
+ assert.equal(appendWithAddition.content.data.length, 2)
196
+ assert.equal(appendWithAddition.addition.data.length, 2)
197
+ const appendWithAdditionFallback = actions.appendContent.assignment(
198
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: true },
199
+ { data: [{ data: [{ id: 3 }] }, {}] }
200
+ )
201
+ assert.equal(appendWithAdditionFallback.addition.data.length, 1)
202
+
203
+ const appendNormal = actions.appendContent.assignment(
204
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: false },
205
+ { data: [{ data: [{ id: 2 }] }] }
206
+ )
207
+ assert.equal(appendNormal.content.data.length, 2)
208
+ const appendNormalFallback = actions.appendContent.assignment({ ...baseContext, room: { categoryId: 1 }, additionEnable: false }, { data: [{}] })
209
+ assert.equal(appendNormalFallback.content.data.length, 1)
210
+ const appendWithoutRoom = actions.appendContent.assignment({ ...baseContext, room: null, additionEnable: false }, { data: [{ data: [{ id: 2 }] }] })
211
+ assert.equal(appendWithoutRoom.content.data.length, 2)
212
+
213
+ const swapped = actions.swapContent.assignment(baseContext, {
214
+ data: [{ data: [{ id: 10 }] }, { data: [{ id: 11 }] }],
215
+ })
216
+ assert.equal(swapped.content.data.length, 1)
217
+ assert.equal(swapped.addition.data.length, 1)
218
+
219
+ const gameInfo = actions.setGameInfo.assignment(baseContext, {
220
+ data: {
221
+ game: {
222
+ providerId: 'P1',
223
+ gameId: 'G1',
224
+ gameTypeId: 'GT1',
225
+ mappingId: 'M1',
226
+ portrait: true,
227
+ gameCode: 'CODE',
228
+ name: 'Name',
229
+ gameName: 'Game Name',
230
+ },
231
+ },
232
+ })
233
+ assert.equal(gameInfo.game.portrait, 1)
234
+ const gameInfoLandscape = actions.setGameInfo.assignment(baseContext, {
235
+ data: {
236
+ game: {
237
+ providerId: 'P1',
238
+ gameId: 'G1',
239
+ gameTypeId: 'GT1',
240
+ mappingId: 'M1',
241
+ portrait: false,
242
+ gameCode: 'CODE',
243
+ name: 'Name',
244
+ gameName: 'Game Name',
245
+ },
246
+ },
247
+ })
248
+ assert.equal(gameInfoLandscape.game.portrait, 0)
249
+
250
+ const urlState = actions.setGameURL.assignment.type(baseContext, { data: { type: 'redirect' } })
251
+ assert.equal(urlState, 'redirect')
252
+ assert.equal(actions.setGameURL.assignment.gameToken(baseContext, { data: { gameToken: 'GT' } }), 'GT')
253
+ assert.equal(actions.setGameURL.assignment.gameHtml(baseContext, { data: { gameHtml: '<html/>' } }), '<html/>')
254
+ assert.equal(actions.setGameURL.assignment.gameURL(baseContext, { data: { gameURL: 'https://game.url' } }), 'https://game.url')
255
+ assert.equal(actions.setGameURL.assignment.gameWalletType(baseContext, { data: { gameWalletType: 'main' } }), 'main')
256
+ assert.deepEqual(actions.setSwitch.assignment(baseContext, { data: { game: { providerId: 'P2' } } }), { switchGame: { providerId: 'P2' } })
257
+ assert.equal(actions.setSwitchGameInfo.assignment({ ...baseContext, switchGame: { providerId: 'P3', gameId: 'G3' } }, {}).game.providerId, 'P3')
258
+ assert.equal(
259
+ actions.setSwitchGameInfo.assignment({ ...baseContext, switchGame: { providerId: 'P4', gameId: 'G4', portrait: true } }, {}).game.portrait,
260
+ 1
261
+ )
262
+ assert.equal(actions.setWalletType.assignment(baseContext, { data: { walletType: 'main' } }).walletType, 'main')
263
+ assert.equal(actions.setPageLoadingDone.assignment(baseContext, {}).pageLoading, true)
264
+ assert.equal(actions.setPageLoading.assignment(baseContext, {}).pageLoading, false)
265
+ assert.equal(actions.setLang.assignment(baseContext, { data: { locale: 'th-TH' } }).lang, 'th_TH')
266
+ assert.equal(actions.setLang.assignment(baseContext, { data: {} }).lang, 'en_US')
267
+ assert.equal(actions.setSite.assignment(baseContext, { data: { site: 'MY' } }).site, 'MY')
268
+ assert.equal(actions.setSite.assignment(baseContext, { data: {} }).site, undefined)
269
+ assert.equal(actions.setGameURL.assignment.type(baseContext, { data: undefined }), undefined)
270
+ assert.equal(actions.setGameDemoStatus.assignment(baseContext, { data: { isDemo: true } }).game.isDemo, true)
271
+ assert.equal(guards.isDifferentRoom({ ...baseContext, room: { categoryId: 1 } }, { data: { categoryId: 2 } }), true)
272
+ assert.equal(guards.isDifferentRoom({ ...baseContext, room: { categoryId: 1 } }, { data: { categoryId: 1 } }), false)
273
+ assert.equal(guards.hasNext({ ...baseContext, loadable: true, isLastPage: false }, {}), true)
274
+ assert.equal(guards.hasNext({ ...baseContext, loadable: false, isLastPage: false }, {}), false)
275
+ assert.equal(guards.hasRoomAndIsNotInGame({ ...baseContext, room: { categoryId: 1 }, isPlaying: false }, {}), true)
276
+ assert.equal(guards.hasRoomAndIsNotInGame({ ...baseContext, room: { categoryId: 1 }, isPlaying: true }, {}), false)
277
+ })
278
+
279
+ test('game_v2_1 services: batch/page/update/connect/demo/disconnect branches', async () => {
280
+ global.window = {
281
+ location: { href: 'https://example.com/path?x=1', origin: 'https://example.com' },
282
+ }
283
+
284
+ let hasToken = false
285
+ const sent = []
286
+ const request = {
287
+ config: { appSecret: 'secret' },
288
+ getToken: () => (hasToken ? 'token' : null),
289
+ send: async (req) => {
290
+ sent.push(req)
291
+ if (req.url?.includes('game/play')) {
292
+ return { type: 'redirect', redirect_url: 'https://game.url', gameToken: 'GT', gameHtml: '<html/>', wallet_type: 'main' }
293
+ }
294
+ if (req.url?.includes('game/demo')) {
295
+ return { type: 'html', redirect_url: '', gameToken: 'DG', gameHtml: '<demo/>', is_demo: true }
296
+ }
297
+ if (req.url?.includes('getListCategory') || req.url?.includes('getListCategoryByRange')) {
298
+ return { data: [{ isGame: true, id: 1 }] }
299
+ }
300
+ if (req.url?.includes('getListAddition') || req.url?.includes('getListAdditionByRange')) {
301
+ return { data: [{ id: 'addition' }] }
302
+ }
303
+ return { data: [] }
304
+ },
305
+ }
306
+
307
+ const machine = gameV21Factory(request)
308
+ const services = machine.options.services
309
+
310
+ const staticData = [
311
+ {
312
+ category: 1,
313
+ info: [
314
+ { isGame: true, id: 1 },
315
+ { isGame: false, id: 2 },
316
+ ],
317
+ },
318
+ ]
319
+ const batchNoToken = await services.batchFetch(
320
+ {
321
+ ...machine.initialState.context,
322
+ room: { categoryId: 1 },
323
+ index: 0,
324
+ additionEnable: false,
325
+ staticData,
326
+ },
327
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
328
+ )
329
+ assert.equal(batchNoToken.length, 1)
330
+ const batchNoTokenWithoutStaticData = await services.batchFetch(
331
+ {
332
+ ...machine.initialState.context,
333
+ room: { categoryId: 1 },
334
+ index: 0,
335
+ additionEnable: false,
336
+ staticData: undefined,
337
+ },
338
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
339
+ )
340
+ assert.equal(batchNoTokenWithoutStaticData.length, 0)
341
+ const batchNoTokenUnknownCategory = await services.batchFetch(
342
+ {
343
+ ...machine.initialState.context,
344
+ room: { categoryId: 999 },
345
+ index: 0,
346
+ additionEnable: false,
347
+ staticData,
348
+ },
349
+ { data: { list: [{ id: 999, i18n: 'unknown' }] } }
350
+ )
351
+ assert.equal(batchNoTokenUnknownCategory.length, 0)
352
+ const staticGamesOverLimit = Array.from({ length: 30 }, (_, idx) => ({ isGame: true, id: idx + 1 }))
353
+ const batchNoTokenStopsAtTwenty = await services.batchFetch(
354
+ {
355
+ ...machine.initialState.context,
356
+ room: { categoryId: 2 },
357
+ index: 0,
358
+ additionEnable: false,
359
+ staticData: [{ category: 2, info: staticGamesOverLimit }],
360
+ },
361
+ { data: { list: [{ id: 2, i18n: 'slot-over-limit' }] } }
362
+ )
363
+ assert.equal(batchNoTokenStopsAtTwenty[0].downLine.length, 20)
364
+
365
+ hasToken = true
366
+ const batchWithToken = await services.batchFetch(
367
+ {
368
+ ...machine.initialState.context,
369
+ room: { categoryId: 1 },
370
+ index: 0,
371
+ additionEnable: true,
372
+ staticData: [],
373
+ },
374
+ {
375
+ data: {
376
+ list: [
377
+ { id: 1, i18n: 'slot' },
378
+ { id: null, i18n: 'invalid' },
379
+ ],
380
+ },
381
+ }
382
+ )
383
+ assert.equal(Array.isArray(batchWithToken), true)
384
+ const batchWithTokenAdditionNoRoom = await services.batchFetch(
385
+ {
386
+ ...machine.initialState.context,
387
+ room: null,
388
+ index: 0,
389
+ additionEnable: true,
390
+ staticData: [],
391
+ },
392
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
393
+ )
394
+ assert.equal(Array.isArray(batchWithTokenAdditionNoRoom), true)
395
+ const batchWithTokenNoAddition = await services.batchFetch(
396
+ {
397
+ ...machine.initialState.context,
398
+ room: { categoryId: 1 },
399
+ index: 0,
400
+ additionEnable: false,
401
+ staticData: [],
402
+ },
403
+ {
404
+ data: {
405
+ list: [
406
+ { id: 1, i18n: 'slot' },
407
+ { id: null, i18n: 'invalid' },
408
+ ],
409
+ },
410
+ }
411
+ )
412
+ assert.equal(Array.isArray(batchWithTokenNoAddition), true)
413
+
414
+ const noRoomPage = await services.getPageContent({ ...machine.initialState.context, room: null }, {})
415
+ assert.equal(noRoomPage[0].totalPage, 0)
416
+
417
+ const searchPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: GAME_SEARCH }, index: 0 }, {})
418
+ assert.equal(searchPage, undefined)
419
+
420
+ hasToken = false
421
+ const staticPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: 1 }, index: 0, staticData }, {})
422
+ assert.equal(staticPage[0].data.length, 2)
423
+ const staticPageByCachedMap = await services.getPageContent(
424
+ {
425
+ ...machine.initialState.context,
426
+ room: { categoryId: 1 },
427
+ index: 0,
428
+ staticInfoByCategory: { 1: [{ isGame: true, id: 777 }] },
429
+ staticData: [],
430
+ },
431
+ {}
432
+ )
433
+ assert.equal(staticPageByCachedMap[0].data[0].id, 777)
434
+
435
+ hasToken = true
436
+ const dynamicPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: 1 }, index: 0, additionEnable: true }, {})
437
+ assert.equal(dynamicPage.length, 2)
438
+ const dynamicPageNoAddition = await services.getPageContent(
439
+ { ...machine.initialState.context, room: { categoryId: 1 }, index: 0, additionEnable: false },
440
+ {}
441
+ )
442
+ assert.equal(dynamicPageNoAddition.length, 1)
443
+
444
+ const noRoomUpdate = await services.updatePageContent({ ...machine.initialState.context, room: null }, {})
445
+ assert.deepEqual(noRoomUpdate, [])
446
+
447
+ const searchUpdate = await services.updatePageContent({ ...machine.initialState.context, room: { categoryId: GAME_SEARCH } }, {})
448
+ assert.deepEqual(searchUpdate, [])
449
+
450
+ hasToken = false
451
+ const noTokenUpdate = await services.updatePageContent({ ...machine.initialState.context, room: { categoryId: 1 } }, {})
452
+ assert.deepEqual(noTokenUpdate, [])
453
+
454
+ hasToken = true
455
+ const tokenUpdate = await services.updatePageContent(
456
+ { ...machine.initialState.context, room: { categoryId: 1 }, content: { timestamp: 1 }, index: 1, additionEnable: true },
457
+ {}
458
+ )
459
+ assert.equal(tokenUpdate.length, 2)
460
+ const tokenUpdateNoAddition = await services.updatePageContent(
461
+ { ...machine.initialState.context, room: { categoryId: 1 }, content: { timestamp: 1 }, index: 1, additionEnable: false },
462
+ {}
463
+ )
464
+ assert.equal(tokenUpdateNoAddition.length, 1)
465
+
466
+ const noGameConnect = await services.connectGame({ ...machine.initialState.context, game: { providerId: null, gameId: null } }, {})
467
+ assert.equal(noGameConnect, undefined)
468
+
469
+ const connectResult = await services.connectGame(
470
+ {
471
+ ...machine.initialState.context,
472
+ base: '/',
473
+ lang: 'en_US',
474
+ isMobile: 'mobile',
475
+ walletType: 'main',
476
+ game: { providerId: 'PG', gameId: 'G1', gameTypeId: 'GT1', mappingId: 'M1' },
477
+ },
478
+ {}
479
+ )
480
+ assert.equal(connectResult.gameToken, 'GT')
481
+ const connectResultNonReturnProvider = await services.connectGame(
482
+ {
483
+ ...machine.initialState.context,
484
+ base: '/',
485
+ lang: 'en_US',
486
+ isMobile: 'desktop',
487
+ walletType: 'main',
488
+ game: { providerId: 'XYZ', gameId: 'G2', gameTypeId: 'GT2', mappingId: 'M2' },
489
+ },
490
+ {}
491
+ )
492
+ assert.equal(connectResultNonReturnProvider.gameURL, 'https://game.url')
493
+
494
+ const demoResult = await services.demoGame(
495
+ {
496
+ ...machine.initialState.context,
497
+ site: 'MY',
498
+ lang: 'th_TH',
499
+ isMobile: 'desktop',
500
+ game: { providerId: 'PG', gameId: 'G1', gameTypeId: 'GT1', mappingId: 'M1', isDemo: false },
501
+ },
502
+ {}
503
+ )
504
+ assert.equal(demoResult.isDemo, true)
505
+
506
+ await services.disconnectGame({ ...machine.initialState.context, game: { providerId: 'PG' } }, { data: 'uid-site' })
507
+ assert.equal(
508
+ sent.some((req) => req.url?.includes('game/logout')),
509
+ true
510
+ )
511
+ })
512
+
513
+ test('withdraw_manual actions/guards/services cover major branches', async () => {
514
+ const sent = []
515
+ const request = {
516
+ config: { appSecret: 'secret' },
517
+ send: async (req) => {
518
+ sent.push(req)
519
+ if (req.url?.includes('getBindingPaymentList')) return { bankList: [] }
520
+ if (req.url?.includes('getBindingPaymentInfo')) return { bankList: [] }
521
+ if (req.url?.includes('getPaymentDetail')) return [{ method: 'manual' }]
522
+ if (req.url?.includes('getDoubleWalletWithdrawRule')) {
523
+ return { balance: 100, enableWithdraw: true, enableWithdrawAmount: 50, rules: [{ greaterEqualThen: 0, maxWithdrawAmount: 20 }] }
524
+ }
525
+ return { data: {} }
526
+ },
527
+ }
528
+
529
+ const machine = withdrawManualFactory(request)
530
+ const actions = machine.options.actions
531
+ const guards = machine.options.guards
532
+ const services = machine.options.services
533
+
534
+ const initData = actions.setInitData.assignment(machine.initialState.context, {
535
+ data: {
536
+ bindingPaymentList: { bankList: [{ bankCode: 'B1' }] },
537
+ bindingPaymentInfo: { bankList: [{ bankCode: 'B1' }], cryptoList: [] },
538
+ },
539
+ })
540
+ assert.equal(initData.boundBanks.length, 1)
541
+ assert.equal(actions.preset.assignment(machine.initialState.context, {}).attachmentType, 'withdraw')
542
+ assert.equal(actions.setMode.assignment(machine.initialState.context, { data: 'main' }).mode, 'main')
543
+
544
+ const cond = actions.updateWithdrawCondition.assignment(machine.initialState.context, {
545
+ data: {
546
+ enableWithdraw: true,
547
+ enableWithdrawAmount: '10',
548
+ currentWithdrawLimit: 1,
549
+ targetWithdrawLimit: 2,
550
+ balance: 100,
551
+ freeGameDetail: [],
552
+ freeGameExpired: false,
553
+ rules: [
554
+ { greaterEqualThen: 0, maxWithdrawAmount: 50 },
555
+ { greaterEqualThen: 80, maxWithdrawAmount: 90 },
556
+ ],
557
+ },
558
+ })
559
+ assert.equal(cond.maxWithdrawAmount, 90)
560
+ assert.equal(cond.enableWithdrawAmount, 10)
561
+
562
+ assert.equal(
563
+ guards.isAvailableAmount({
564
+ paymentDetail: [{ minimum: 10, maximum: 100 }],
565
+ currentBank: { bankCode: 'B1' },
566
+ amount: 20,
567
+ userInfo: { balance: 30 },
568
+ }),
569
+ true
570
+ )
571
+ assert.equal(guards.hasAttachmentType({ attachmentType: 'pool' }), true)
572
+ assert.equal(guards.haveProcessing({ paymentDetail: [{ processing: [{ id: 1 }] }] }), true)
573
+ assert.equal(guards.isBankNotBound({ boundBanks: [] }), true)
574
+ assert.equal(guards.isConvertible({ enableWithdraw: false, freeGameDetail: [{ freeGameCount: 1, freeGameUsedCount: 1 }] }), true)
575
+ assert.equal(guards.isNotWithdrawable({ balance: 1, enableWithdraw: true, paymentDetail: [{ minimum: 10 }] }), true)
576
+ assert.equal(guards.isOtpRequired({}, { data: { status: 'otp-verifying' } }), true)
577
+ assert.equal(guards.isNotWithdrawMinDepositAmount({ withdrawCheck: { passDepositeLimit: false } }), true)
578
+ assert.equal(guards.isPassWithdrawCooldownTime({ withdrawCheck: { passWithdrawCooldownTime: false } }), true)
579
+ assert.equal(guards.isNotWIthdrawServiceTime({ withdrawCheck: { withdrawInServiceTime: false } }), true)
580
+
581
+ await services.fetchInitData({}, {})
582
+ await services.fetchPaymentData({}, {})
583
+ await services.fetchWithdrawRules({ mode: 'main' }, {})
584
+ await services.fetchWithdrawRulePreview({}, {})
585
+ await services.fetchCalculation({ paymentDetail: [{ method: 'manual' }], currentBank: { cryptoCurrency: 'USDT' }, amount: 10 }, {})
586
+ await services.submitWithdraw(
587
+ {
588
+ paymentDetail: [{ method: 'manual' }],
589
+ currentBank: {
590
+ bindingType: 'BANK',
591
+ bankCode: 'B1',
592
+ branch: 'BRANCH',
593
+ accountNumber: '123',
594
+ ifscCode: 'IFSC',
595
+ holderName: 'Holder',
596
+ },
597
+ amount: 20,
598
+ },
599
+ {}
600
+ )
601
+ await services.submitWithdraw(
602
+ {
603
+ paymentDetail: [{ method: 'manual' }],
604
+ currentBank: {
605
+ bindingType: 'BANK',
606
+ bankCode: 'GCASH',
607
+ branch: 'BRANCH',
608
+ accountNumber: '123',
609
+ },
610
+ amount: 20,
611
+ },
612
+ {}
613
+ )
614
+ await services.convertFreeCredit({}, {})
615
+ await services.resetOtp({ requestId: 'RID', target: 'phone' }, {})
616
+ await services.acknowledge({ requestId: 'RID', target: 'phone' }, { data: '123456' })
617
+ await services.pool({ amount: 99 }, {})
618
+ await services.giveUp({}, {})
619
+ await services.withdrawCheck({}, {})
620
+
621
+ assert.equal(
622
+ sent.some((req) => req.url?.includes('/transaction')),
623
+ true
624
+ )
625
+ assert.equal(
626
+ sent.some((req) => req.url?.includes('restore')),
627
+ true
628
+ )
629
+ })