@jetthai/cuora 1.2.0 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/BREAKING_CHANGES.md +9 -0
  2. package/CHANGELOG.md +36 -0
  3. package/package.json +5 -2
  4. package/resetGitBranch.sh +16 -16
  5. package/src/api/account.js +8 -0
  6. package/src/api/auth.js +1 -1
  7. package/src/api/common.js +6 -1
  8. package/src/api/index.js +3 -1
  9. package/src/api/otp.js +5 -0
  10. package/src/api/user.js +1 -0
  11. package/src/machine/activity/activity.js +23 -19
  12. package/src/machine/activity/activity_cash.js +27 -22
  13. package/src/machine/activity/cash_rain_activity.js +1 -0
  14. package/src/machine/activity/continue_deposit_activity.js +1 -0
  15. package/src/machine/activity/deposit_activity.js +1 -0
  16. package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
  17. package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
  19. package/src/machine/activity/fafafa_activity.js +1 -0
  20. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  21. package/src/machine/activity/instant_rebate_activity.js +1 -0
  22. package/src/machine/activity/invite_friends_activity.js +1 -0
  23. package/src/machine/activity/jackpot.js +1 -0
  24. package/src/machine/activity/mini_game_activity.js +1 -0
  25. package/src/machine/activity/otp_verified_activity.js +1 -0
  26. package/src/machine/activity/ranking_activity.js +1 -0
  27. package/src/machine/activity/return_bonus_activity.js +3 -1
  28. package/src/machine/activity/roulette_activity_v2.js +6 -0
  29. package/src/machine/activity/sign_in_activity.js +1 -0
  30. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  31. package/src/machine/activity/specify_bets_activity.js +1 -0
  32. package/src/machine/activity/specify_turnover_activity.js +1 -0
  33. package/src/machine/activity/time_bomb_activity.js +1 -0
  34. package/src/machine/activity/vip_card_activity.js +1 -0
  35. package/src/machine/auth.js +18 -6
  36. package/src/machine/auth_otp_v2.js +1 -0
  37. package/src/machine/auth_otp_v3.js +48 -11
  38. package/src/machine/bank_binding.js +1 -0
  39. package/src/machine/bank_binding_amb.js +1 -0
  40. package/src/machine/bonus.js +1 -0
  41. package/src/machine/common.js +24 -4
  42. package/src/machine/deposit/amb.js +1 -0
  43. package/src/machine/deposit/crypto_bank.js +20 -5
  44. package/src/machine/deposit/crypto_bank_cash.js +35 -9
  45. package/src/machine/deposit/crypto_qrcode.js +11 -1
  46. package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
  47. package/src/machine/deposit/crypto_way.js +11 -5
  48. package/src/machine/deposit/crypto_way_cash.js +15 -6
  49. package/src/machine/deposit/deposit_fc.js +1 -0
  50. package/src/machine/deposit/direct.js +1 -0
  51. package/src/machine/deposit/direct_cash.js +1 -0
  52. package/src/machine/deposit/float.js +1 -0
  53. package/src/machine/deposit/krway.js +1 -0
  54. package/src/machine/deposit/loadcard_cash.js +2 -1
  55. package/src/machine/deposit/loadcard_vn.js +1 -0
  56. package/src/machine/deposit/manual_cash.js +1 -0
  57. package/src/machine/deposit/manual_vn.js +1 -0
  58. package/src/machine/deposit/qrcode_cash.js +6 -5
  59. package/src/machine/deposit/qrcode_v2.js +1 -0
  60. package/src/machine/deposit/usdt.js +23 -4
  61. package/src/machine/deposit/usdt_cash.js +15 -1
  62. package/src/machine/deposit/virtual_bank_cash.js +11 -9
  63. package/src/machine/deposit/virtual_bank_vn.js +1 -0
  64. package/src/machine/deposit/vpay.js +7 -0
  65. package/src/machine/error.js +1 -0
  66. package/src/machine/game_betslip.js +1 -0
  67. package/src/machine/game_favorite_v2.js +1 -0
  68. package/src/machine/game_hot_new.js +1 -0
  69. package/src/machine/game_info.js +5 -0
  70. package/src/machine/game_replay.js +1 -0
  71. package/src/machine/game_search_cash.js +1 -0
  72. package/src/machine/game_search_v2.js +1 -0
  73. package/src/machine/game_v2_1.js +88 -46
  74. package/src/machine/honor_board.js +1 -0
  75. package/src/machine/honor_board_cash.js +11 -8
  76. package/src/machine/inbox.js +93 -43
  77. package/src/machine/leaderboard.js +1 -0
  78. package/src/machine/merge.js +1 -0
  79. package/src/machine/navbar.js +3 -1
  80. package/src/machine/payment_data.js +1 -0
  81. package/src/machine/promotions.js +11 -18
  82. package/src/machine/ranking.js +5 -2
  83. package/src/machine/reward.js +1 -0
  84. package/src/machine/reward_cash.js +1 -0
  85. package/src/machine/reward_fc.js +1 -0
  86. package/src/machine/roulette_v2.js +18 -26
  87. package/src/machine/setting.js +1 -0
  88. package/src/machine/side.js +10 -4
  89. package/src/machine/side_cash.js +1 -0
  90. package/src/machine/side_v2.js +38 -24
  91. package/src/machine/user_info.js +1 -0
  92. package/src/machine/user_photo.js +1 -0
  93. package/src/machine/user_reset_password.js +5 -2
  94. package/src/machine/user_sign_up.js +1 -0
  95. package/src/machine/vip_table.js +1 -0
  96. package/src/machine/websocket.js +42 -14
  97. package/src/machine/welcome.js +1 -0
  98. package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
  99. package/src/machine/withdraw/withdraw_krway.js +1 -0
  100. package/src/machine/withdraw/withdraw_manual.js +16 -8
  101. package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
  102. package/src/request/request.js +34 -30
  103. package/src/util/deviceToken.js +7 -6
  104. package/src/util/storage.js +4 -3
  105. package/test/api.behavior.test.js +69 -0
  106. package/test/api.contract.test.js +18 -0
  107. package/test/config.test.js +27 -0
  108. package/test/deviceToken.test.js +139 -0
  109. package/test/helpers.coverage.test.js +11 -0
  110. package/test/helpers.js +91 -0
  111. package/test/index.exports.test.js +14 -0
  112. package/test/machine.activity.core.coverage.test.js +337 -0
  113. package/test/machine.activity.gap.coverage.test.js +252 -0
  114. package/test/machine.activity.more.coverage.test.js +180 -0
  115. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  116. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  117. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  118. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  119. package/test/machine.auth.coverage.test.js +215 -0
  120. package/test/machine.bank_binding.test.js +143 -0
  121. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  122. package/test/machine.contract.test.js +50 -0
  123. package/test/machine.crypto_bank.coverage.test.js +270 -0
  124. package/test/machine.crypto_way.coverage.test.js +108 -0
  125. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  126. package/test/machine.definition.test.js +137 -0
  127. package/test/machine.deposit.manual.coverage.test.js +365 -0
  128. package/test/machine.deposit_fc.coverage.test.js +126 -0
  129. package/test/machine.direct.coverage.test.js +96 -0
  130. package/test/machine.direct_cash.coverage.test.js +108 -0
  131. package/test/machine.error.coverage.test.js +37 -0
  132. package/test/machine.events.test.js +126 -0
  133. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  134. package/test/machine.float.coverage.test.js +136 -0
  135. package/test/machine.flow.test.js +226 -0
  136. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  137. package/test/machine.game_search_cash.coverage.test.js +155 -0
  138. package/test/machine.game_search_v2.test.js +199 -0
  139. package/test/machine.game_user_profile.coverage.test.js +100 -0
  140. package/test/machine.honor_board.test.js +133 -0
  141. package/test/machine.inbox.common.coverage.test.js +304 -0
  142. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  143. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  144. package/test/machine.misc.coverage.test.js +361 -0
  145. package/test/machine.more2.coverage.test.js +261 -0
  146. package/test/machine.options.execution.test.js +272 -0
  147. package/test/machine.priority.coverage.test.js +603 -0
  148. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  149. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  150. package/test/machine.regression.test.js +82 -0
  151. package/test/machine.roulette_v2.test.js +142 -0
  152. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  153. package/test/machine.targeted.coverage.test.js +313 -0
  154. package/test/machine.usdt.coverage.test.js +95 -0
  155. package/test/machine.usdt_cash.coverage.test.js +73 -0
  156. package/test/machine.vip_card_activity.test.js +114 -0
  157. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  158. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  159. package/test/machine.vpay.coverage.test.js +142 -0
  160. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  161. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  162. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  163. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  164. package/test/request.test.js +325 -0
  165. package/test/util.storage.errors.test.js +47 -0
  166. package/test/util.test.js +41 -0
@@ -0,0 +1,603 @@
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' }] }), { staticData: [{ id: 's1' }] })
174
+ assert.deepEqual(actions.setAdditionEnable.assignment(baseContext, { data: true }), { additionEnable: true })
175
+ assert.deepEqual(actions.setLoadable.assignment(baseContext, { data: true }), { loadable: true })
176
+ assert.equal(actions.increaseIndex.assignment({ ...baseContext, index: 3 }, {}).index, 4)
177
+ assert.deepEqual(actions.resetSHA.assignment(baseContext, {}), {})
178
+ assert.equal(actions.setLastPage.assignment({ ...baseContext, index: 4, content: { totalPage: 5 } }, {}).isLastPage, true)
179
+ assert.deepEqual(actions.setRoom.assignment(baseContext, { data: { categoryId: 7 } }), { room: { categoryId: 7 } })
180
+ assert.deepEqual(actions.setBatch.assignment(baseContext, { data: [{ id: 1 }] }), { batch: [{ id: 1 }] })
181
+
182
+ const searchAppend = actions.appendContent.assignment(
183
+ { ...baseContext, room: { categoryId: GAME_SEARCH }, additionEnable: false },
184
+ { data: [{ data: [{ id: 2 }] }] }
185
+ )
186
+ assert.equal(searchAppend, undefined)
187
+
188
+ const appendWithAddition = actions.appendContent.assignment(
189
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: true },
190
+ { data: [{ data: [{ id: 2 }] }, { data: [{ id: 'b' }] }] }
191
+ )
192
+ assert.equal(appendWithAddition.content.data.length, 2)
193
+ assert.equal(appendWithAddition.addition.data.length, 2)
194
+ const appendWithAdditionFallback = actions.appendContent.assignment(
195
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: true },
196
+ { data: [{ data: [{ id: 3 }] }, {}] }
197
+ )
198
+ assert.equal(appendWithAdditionFallback.addition.data.length, 1)
199
+
200
+ const appendNormal = actions.appendContent.assignment(
201
+ { ...baseContext, room: { categoryId: 1 }, additionEnable: false },
202
+ { data: [{ data: [{ id: 2 }] }] }
203
+ )
204
+ assert.equal(appendNormal.content.data.length, 2)
205
+ const appendNormalFallback = actions.appendContent.assignment({ ...baseContext, room: { categoryId: 1 }, additionEnable: false }, { data: [{}] })
206
+ assert.equal(appendNormalFallback.content.data.length, 1)
207
+ const appendWithoutRoom = actions.appendContent.assignment({ ...baseContext, room: null, additionEnable: false }, { data: [{ data: [{ id: 2 }] }] })
208
+ assert.equal(appendWithoutRoom.content.data.length, 2)
209
+
210
+ const swapped = actions.swapContent.assignment(baseContext, {
211
+ data: [{ data: [{ id: 10 }] }, { data: [{ id: 11 }] }],
212
+ })
213
+ assert.equal(swapped.content.data.length, 1)
214
+ assert.equal(swapped.addition.data.length, 1)
215
+
216
+ const gameInfo = actions.setGameInfo.assignment(baseContext, {
217
+ data: {
218
+ game: {
219
+ providerId: 'P1',
220
+ gameId: 'G1',
221
+ gameTypeId: 'GT1',
222
+ mappingId: 'M1',
223
+ portrait: true,
224
+ gameCode: 'CODE',
225
+ name: 'Name',
226
+ gameName: 'Game Name',
227
+ },
228
+ },
229
+ })
230
+ assert.equal(gameInfo.game.portrait, 1)
231
+ const gameInfoLandscape = actions.setGameInfo.assignment(baseContext, {
232
+ data: {
233
+ game: {
234
+ providerId: 'P1',
235
+ gameId: 'G1',
236
+ gameTypeId: 'GT1',
237
+ mappingId: 'M1',
238
+ portrait: false,
239
+ gameCode: 'CODE',
240
+ name: 'Name',
241
+ gameName: 'Game Name',
242
+ },
243
+ },
244
+ })
245
+ assert.equal(gameInfoLandscape.game.portrait, 0)
246
+
247
+ const urlState = actions.setGameURL.assignment.type(baseContext, { data: { type: 'redirect' } })
248
+ assert.equal(urlState, 'redirect')
249
+ assert.equal(actions.setGameURL.assignment.gameToken(baseContext, { data: { gameToken: 'GT' } }), 'GT')
250
+ assert.equal(actions.setGameURL.assignment.gameHtml(baseContext, { data: { gameHtml: '<html/>' } }), '<html/>')
251
+ assert.equal(actions.setGameURL.assignment.gameURL(baseContext, { data: { gameURL: 'https://game.url' } }), 'https://game.url')
252
+ assert.equal(actions.setGameURL.assignment.gameWalletType(baseContext, { data: { gameWalletType: 'main' } }), 'main')
253
+ assert.deepEqual(actions.setSwitch.assignment(baseContext, { data: { game: { providerId: 'P2' } } }), { switchGame: { providerId: 'P2' } })
254
+ assert.equal(actions.setSwitchGameInfo.assignment({ ...baseContext, switchGame: { providerId: 'P3', gameId: 'G3' } }, {}).game.providerId, 'P3')
255
+ assert.equal(
256
+ actions.setSwitchGameInfo.assignment({ ...baseContext, switchGame: { providerId: 'P4', gameId: 'G4', portrait: true } }, {}).game.portrait,
257
+ 1
258
+ )
259
+ assert.equal(actions.setWalletType.assignment(baseContext, { data: { walletType: 'main' } }).walletType, 'main')
260
+ assert.equal(actions.setPageLoadingDone.assignment(baseContext, {}).pageLoading, true)
261
+ assert.equal(actions.setPageLoading.assignment(baseContext, {}).pageLoading, false)
262
+ assert.equal(actions.setLang.assignment(baseContext, { data: { locale: 'th-TH' } }).lang, 'th_TH')
263
+ assert.equal(actions.setLang.assignment(baseContext, { data: {} }).lang, 'en_US')
264
+ assert.equal(actions.setSite.assignment(baseContext, { data: { site: 'MY' } }).site, 'MY')
265
+ assert.equal(actions.setSite.assignment(baseContext, { data: {} }).site, undefined)
266
+ assert.equal(actions.setGameURL.assignment.type(baseContext, { data: undefined }), undefined)
267
+ assert.equal(actions.setGameDemoStatus.assignment(baseContext, { data: { isDemo: true } }).game.isDemo, true)
268
+ assert.equal(guards.isDifferentRoom({ ...baseContext, room: { categoryId: 1 } }, { data: { categoryId: 2 } }), true)
269
+ assert.equal(guards.isDifferentRoom({ ...baseContext, room: { categoryId: 1 } }, { data: { categoryId: 1 } }), false)
270
+ assert.equal(guards.hasNext({ ...baseContext, loadable: true, isLastPage: false }, {}), true)
271
+ assert.equal(guards.hasNext({ ...baseContext, loadable: false, isLastPage: false }, {}), false)
272
+ assert.equal(guards.hasRoomAndIsNotInGame({ ...baseContext, room: { categoryId: 1 }, isPlaying: false }, {}), true)
273
+ assert.equal(guards.hasRoomAndIsNotInGame({ ...baseContext, room: { categoryId: 1 }, isPlaying: true }, {}), false)
274
+ })
275
+
276
+ test('game_v2_1 services: batch/page/update/connect/demo/disconnect branches', async () => {
277
+ global.window = {
278
+ location: { href: 'https://example.com/path?x=1', origin: 'https://example.com' },
279
+ }
280
+
281
+ let hasToken = false
282
+ const sent = []
283
+ const request = {
284
+ config: { appSecret: 'secret' },
285
+ getToken: () => (hasToken ? 'token' : null),
286
+ send: async (req) => {
287
+ sent.push(req)
288
+ if (req.url?.includes('game/play')) {
289
+ return { type: 'redirect', redirect_url: 'https://game.url', gameToken: 'GT', gameHtml: '<html/>', wallet_type: 'main' }
290
+ }
291
+ if (req.url?.includes('game/demo')) {
292
+ return { type: 'html', redirect_url: '', gameToken: 'DG', gameHtml: '<demo/>', is_demo: true }
293
+ }
294
+ if (req.url?.includes('getListCategory') || req.url?.includes('getListCategoryByRange')) {
295
+ return { data: [{ isGame: true, id: 1 }] }
296
+ }
297
+ if (req.url?.includes('getListAddition') || req.url?.includes('getListAdditionByRange')) {
298
+ return { data: [{ id: 'addition' }] }
299
+ }
300
+ return { data: [] }
301
+ },
302
+ }
303
+
304
+ const machine = gameV21Factory(request)
305
+ const services = machine.options.services
306
+
307
+ const staticData = [
308
+ {
309
+ category: 1,
310
+ info: [
311
+ { isGame: true, id: 1 },
312
+ { isGame: false, id: 2 },
313
+ ],
314
+ },
315
+ ]
316
+ const batchNoToken = await services.batchFetch(
317
+ {
318
+ ...machine.initialState.context,
319
+ room: { categoryId: 1 },
320
+ index: 0,
321
+ additionEnable: false,
322
+ staticData,
323
+ },
324
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
325
+ )
326
+ assert.equal(batchNoToken.length, 1)
327
+ const batchNoTokenWithoutStaticData = await services.batchFetch(
328
+ {
329
+ ...machine.initialState.context,
330
+ room: { categoryId: 1 },
331
+ index: 0,
332
+ additionEnable: false,
333
+ staticData: undefined,
334
+ },
335
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
336
+ )
337
+ assert.equal(batchNoTokenWithoutStaticData.length, 0)
338
+ const batchNoTokenUnknownCategory = await services.batchFetch(
339
+ {
340
+ ...machine.initialState.context,
341
+ room: { categoryId: 999 },
342
+ index: 0,
343
+ additionEnable: false,
344
+ staticData,
345
+ },
346
+ { data: { list: [{ id: 999, i18n: 'unknown' }] } }
347
+ )
348
+ assert.equal(batchNoTokenUnknownCategory.length, 0)
349
+
350
+ hasToken = true
351
+ const batchWithToken = await services.batchFetch(
352
+ {
353
+ ...machine.initialState.context,
354
+ room: { categoryId: 1 },
355
+ index: 0,
356
+ additionEnable: true,
357
+ staticData: [],
358
+ },
359
+ {
360
+ data: {
361
+ list: [
362
+ { id: 1, i18n: 'slot' },
363
+ { id: null, i18n: 'invalid' },
364
+ ],
365
+ },
366
+ }
367
+ )
368
+ assert.equal(Array.isArray(batchWithToken), true)
369
+ const batchWithTokenAdditionNoRoom = await services.batchFetch(
370
+ {
371
+ ...machine.initialState.context,
372
+ room: null,
373
+ index: 0,
374
+ additionEnable: true,
375
+ staticData: [],
376
+ },
377
+ { data: { list: [{ id: 1, i18n: 'slot' }] } }
378
+ )
379
+ assert.equal(Array.isArray(batchWithTokenAdditionNoRoom), true)
380
+ const batchWithTokenNoAddition = await services.batchFetch(
381
+ {
382
+ ...machine.initialState.context,
383
+ room: { categoryId: 1 },
384
+ index: 0,
385
+ additionEnable: false,
386
+ staticData: [],
387
+ },
388
+ {
389
+ data: {
390
+ list: [
391
+ { id: 1, i18n: 'slot' },
392
+ { id: null, i18n: 'invalid' },
393
+ ],
394
+ },
395
+ }
396
+ )
397
+ assert.equal(Array.isArray(batchWithTokenNoAddition), true)
398
+
399
+ const noRoomPage = await services.getPageContent({ ...machine.initialState.context, room: null }, {})
400
+ assert.equal(noRoomPage[0].totalPage, 0)
401
+
402
+ const searchPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: GAME_SEARCH }, index: 0 }, {})
403
+ assert.equal(searchPage, undefined)
404
+
405
+ hasToken = false
406
+ const staticPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: 1 }, index: 0, staticData }, {})
407
+ assert.equal(staticPage[0].data.length, 2)
408
+
409
+ hasToken = true
410
+ const dynamicPage = await services.getPageContent({ ...machine.initialState.context, room: { categoryId: 1 }, index: 0, additionEnable: true }, {})
411
+ assert.equal(dynamicPage.length, 2)
412
+ const dynamicPageNoAddition = await services.getPageContent(
413
+ { ...machine.initialState.context, room: { categoryId: 1 }, index: 0, additionEnable: false },
414
+ {}
415
+ )
416
+ assert.equal(dynamicPageNoAddition.length, 1)
417
+
418
+ const noRoomUpdate = await services.updatePageContent({ ...machine.initialState.context, room: null }, {})
419
+ assert.deepEqual(noRoomUpdate, [])
420
+
421
+ const searchUpdate = await services.updatePageContent({ ...machine.initialState.context, room: { categoryId: GAME_SEARCH } }, {})
422
+ assert.deepEqual(searchUpdate, [])
423
+
424
+ hasToken = false
425
+ const noTokenUpdate = await services.updatePageContent({ ...machine.initialState.context, room: { categoryId: 1 } }, {})
426
+ assert.deepEqual(noTokenUpdate, [])
427
+
428
+ hasToken = true
429
+ const tokenUpdate = await services.updatePageContent(
430
+ { ...machine.initialState.context, room: { categoryId: 1 }, content: { timestamp: 1 }, index: 1, additionEnable: true },
431
+ {}
432
+ )
433
+ assert.equal(tokenUpdate.length, 2)
434
+ const tokenUpdateNoAddition = await services.updatePageContent(
435
+ { ...machine.initialState.context, room: { categoryId: 1 }, content: { timestamp: 1 }, index: 1, additionEnable: false },
436
+ {}
437
+ )
438
+ assert.equal(tokenUpdateNoAddition.length, 1)
439
+
440
+ const noGameConnect = await services.connectGame({ ...machine.initialState.context, game: { providerId: null, gameId: null } }, {})
441
+ assert.equal(noGameConnect, undefined)
442
+
443
+ const connectResult = await services.connectGame(
444
+ {
445
+ ...machine.initialState.context,
446
+ base: '/',
447
+ lang: 'en_US',
448
+ isMobile: 'mobile',
449
+ walletType: 'main',
450
+ game: { providerId: 'PG', gameId: 'G1', gameTypeId: 'GT1', mappingId: 'M1' },
451
+ },
452
+ {}
453
+ )
454
+ assert.equal(connectResult.gameToken, 'GT')
455
+ const connectResultNonReturnProvider = await services.connectGame(
456
+ {
457
+ ...machine.initialState.context,
458
+ base: '/',
459
+ lang: 'en_US',
460
+ isMobile: 'desktop',
461
+ walletType: 'main',
462
+ game: { providerId: 'XYZ', gameId: 'G2', gameTypeId: 'GT2', mappingId: 'M2' },
463
+ },
464
+ {}
465
+ )
466
+ assert.equal(connectResultNonReturnProvider.gameURL, 'https://game.url')
467
+
468
+ const demoResult = await services.demoGame(
469
+ {
470
+ ...machine.initialState.context,
471
+ site: 'MY',
472
+ lang: 'th_TH',
473
+ isMobile: 'desktop',
474
+ game: { providerId: 'PG', gameId: 'G1', gameTypeId: 'GT1', mappingId: 'M1', isDemo: false },
475
+ },
476
+ {}
477
+ )
478
+ assert.equal(demoResult.isDemo, true)
479
+
480
+ await services.disconnectGame({ ...machine.initialState.context, game: { providerId: 'PG' } }, { data: 'uid-site' })
481
+ assert.equal(
482
+ sent.some((req) => req.url?.includes('game/logout')),
483
+ true
484
+ )
485
+ })
486
+
487
+ test('withdraw_manual actions/guards/services cover major branches', async () => {
488
+ const sent = []
489
+ const request = {
490
+ config: { appSecret: 'secret' },
491
+ send: async (req) => {
492
+ sent.push(req)
493
+ if (req.url?.includes('getBindingPaymentList')) return { bankList: [] }
494
+ if (req.url?.includes('getBindingPaymentInfo')) return { bankList: [] }
495
+ if (req.url?.includes('getPaymentDetail')) return [{ method: 'manual' }]
496
+ if (req.url?.includes('getDoubleWalletWithdrawRule')) {
497
+ return { balance: 100, enableWithdraw: true, enableWithdrawAmount: 50, rules: [{ greaterEqualThen: 0, maxWithdrawAmount: 20 }] }
498
+ }
499
+ return { data: {} }
500
+ },
501
+ }
502
+
503
+ const machine = withdrawManualFactory(request)
504
+ const actions = machine.options.actions
505
+ const guards = machine.options.guards
506
+ const services = machine.options.services
507
+
508
+ const initData = actions.setInitData.assignment(machine.initialState.context, {
509
+ data: {
510
+ bindingPaymentList: { bankList: [{ bankCode: 'B1' }] },
511
+ bindingPaymentInfo: { bankList: [{ bankCode: 'B1' }], cryptoList: [] },
512
+ },
513
+ })
514
+ assert.equal(initData.boundBanks.length, 1)
515
+ assert.equal(actions.preset.assignment(machine.initialState.context, {}).attachmentType, 'withdraw')
516
+ assert.equal(actions.setMode.assignment(machine.initialState.context, { data: 'main' }).mode, 'main')
517
+
518
+ const cond = actions.updateWithdrawCondition.assignment(machine.initialState.context, {
519
+ data: {
520
+ enableWithdraw: true,
521
+ enableWithdrawAmount: '10',
522
+ currentWithdrawLimit: 1,
523
+ targetWithdrawLimit: 2,
524
+ balance: 100,
525
+ freeGameDetail: [],
526
+ freeGameExpired: false,
527
+ rules: [
528
+ { greaterEqualThen: 0, maxWithdrawAmount: 50 },
529
+ { greaterEqualThen: 80, maxWithdrawAmount: 90 },
530
+ ],
531
+ },
532
+ })
533
+ assert.equal(cond.maxWithdrawAmount, 90)
534
+ assert.equal(cond.enableWithdrawAmount, 10)
535
+
536
+ assert.equal(
537
+ guards.isAvailableAmount({
538
+ paymentDetail: [{ minimum: 10, maximum: 100 }],
539
+ currentBank: { bankCode: 'B1' },
540
+ amount: 20,
541
+ userInfo: { balance: 30 },
542
+ }),
543
+ true
544
+ )
545
+ assert.equal(guards.hasAttachmentType({ attachmentType: 'pool' }), true)
546
+ assert.equal(guards.haveProcessing({ paymentDetail: [{ processing: [{ id: 1 }] }] }), true)
547
+ assert.equal(guards.isBankNotBound({ boundBanks: [] }), true)
548
+ assert.equal(guards.isConvertible({ enableWithdraw: false, freeGameDetail: [{ freeGameCount: 1, freeGameUsedCount: 1 }] }), true)
549
+ assert.equal(guards.isNotWithdrawable({ balance: 1, enableWithdraw: true, paymentDetail: [{ minimum: 10 }] }), true)
550
+ assert.equal(guards.isOtpRequired({}, { data: { status: 'otp-verifying' } }), true)
551
+ assert.equal(guards.isNotWithdrawMinDepositAmount({ withdrawCheck: { passDepositeLimit: false } }), true)
552
+ assert.equal(guards.isPassWithdrawCooldownTime({ withdrawCheck: { passWithdrawCooldownTime: false } }), true)
553
+ assert.equal(guards.isNotWIthdrawServiceTime({ withdrawCheck: { withdrawInServiceTime: false } }), true)
554
+
555
+ await services.fetchInitData({}, {})
556
+ await services.fetchPaymentData({}, {})
557
+ await services.fetchWithdrawRules({ mode: 'main' }, {})
558
+ await services.fetchWithdrawRulePreview({}, {})
559
+ await services.fetchCalculation({ paymentDetail: [{ method: 'manual' }], currentBank: { cryptoCurrency: 'USDT' }, amount: 10 }, {})
560
+ await services.submitWithdraw(
561
+ {
562
+ paymentDetail: [{ method: 'manual' }],
563
+ currentBank: {
564
+ bindingType: 'BANK',
565
+ bankCode: 'B1',
566
+ branch: 'BRANCH',
567
+ accountNumber: '123',
568
+ ifscCode: 'IFSC',
569
+ holderName: 'Holder',
570
+ },
571
+ amount: 20,
572
+ },
573
+ {}
574
+ )
575
+ await services.submitWithdraw(
576
+ {
577
+ paymentDetail: [{ method: 'manual' }],
578
+ currentBank: {
579
+ bindingType: 'BANK',
580
+ bankCode: 'GCASH',
581
+ branch: 'BRANCH',
582
+ accountNumber: '123',
583
+ },
584
+ amount: 20,
585
+ },
586
+ {}
587
+ )
588
+ await services.convertFreeCredit({}, {})
589
+ await services.resetOtp({ requestId: 'RID', target: 'phone' }, {})
590
+ await services.acknowledge({ requestId: 'RID', target: 'phone' }, { data: '123456' })
591
+ await services.pool({ amount: 99 }, {})
592
+ await services.giveUp({}, {})
593
+ await services.withdrawCheck({}, {})
594
+
595
+ assert.equal(
596
+ sent.some((req) => req.url?.includes('/transaction')),
597
+ true
598
+ )
599
+ assert.equal(
600
+ sent.some((req) => req.url?.includes('restore')),
601
+ true
602
+ )
603
+ })