@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,226 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import mergeFactory from '../src/machine/merge.js'
5
+ import settingFactory from '../src/machine/setting.js'
6
+ import qrcodeCashFactory from '../src/machine/deposit/qrcode_cash.js'
7
+ import directCashFactory from '../src/machine/deposit/direct_cash.js'
8
+ import usdtCashFactory from '../src/machine/deposit/usdt_cash.js'
9
+ import authFactory from '../src/machine/auth.js'
10
+ import commonFactory from '../src/machine/common.js'
11
+ import { createLocalStorageMock } from './helpers.js'
12
+
13
+ function createRequestStub() {
14
+ return {
15
+ config: {
16
+ apiURL: 'https://api.example.com',
17
+ apiVersion: 'v1',
18
+ clientId: 'client',
19
+ appSecret: 'secret',
20
+ platform: 'web',
21
+ version: '1.0.0',
22
+ fpToken: 'fp-token',
23
+ sentry: { captureException: () => {}, setTag: () => {} },
24
+ defaultChannel: 'web',
25
+ defaultSubchannel: 'home',
26
+ socketURL: 'wss://socket.example.com',
27
+ bucketName: 'bucket',
28
+ },
29
+ send: async () => ({}),
30
+ getToken: () => null,
31
+ }
32
+ }
33
+
34
+ test('merge flow: becomes mergeable and enters merging on MERGE', () => {
35
+ const machine = mergeFactory(createRequestStub())
36
+
37
+ let state = machine.initialState
38
+ assert.equal(state.value, 'idle')
39
+
40
+ state = machine.transition(state, {
41
+ type: 'SET_USER_INFO',
42
+ data: { retain: 10, balance: '3', withdraw_policy: 'NORMAL' },
43
+ })
44
+ assert.equal(state.value, 'mergeable')
45
+
46
+ state = machine.transition(state, { type: 'MERGE' })
47
+ assert.equal(state.value, 'merging')
48
+ })
49
+
50
+ test('merge flow: remains idle when user is not mergeable', () => {
51
+ const machine = mergeFactory(createRequestStub())
52
+ let state = machine.initialState
53
+
54
+ state = machine.transition(state, {
55
+ type: 'SET_USER_INFO',
56
+ data: { retain: 0, balance: '100', withdraw_policy: 'NORMAL' },
57
+ })
58
+
59
+ assert.equal(state.value, 'idle')
60
+ })
61
+
62
+ test('setting flow: loads from localStorage and persists modify events', () => {
63
+ global.localStorage = createLocalStorageMock()
64
+ localStorage.setItem('setting', JSON.stringify({ sound: false, music: true, locale: 'th-TH' }))
65
+
66
+ const machine = settingFactory()
67
+ let state = machine.initialState
68
+
69
+ assert.equal(state.context.sound, false)
70
+ assert.equal(state.context.music, true)
71
+ assert.equal(state.context.locale, 'th-TH')
72
+
73
+ state = machine.transition(state, { type: 'MODIFY_SETTING', data: { sound: true, music: false, locale: 'en-US' } })
74
+ assert.equal(state.context.sound, true)
75
+ assert.equal(state.context.music, false)
76
+ assert.equal(JSON.parse(localStorage.getItem('setting')).music, false)
77
+ })
78
+
79
+ test('setting flow: DEFAULT_SETTING overrides current context', () => {
80
+ global.localStorage = createLocalStorageMock()
81
+ const machine = settingFactory()
82
+ let state = machine.initialState
83
+
84
+ state = machine.transition(state, { type: 'DEFAULT_SETTING', data: { sound: false, music: false, locale: 'ja-JP' } })
85
+ assert.equal(state.context.sound, false)
86
+ assert.equal(state.context.music, false)
87
+ assert.equal(state.context.locale, 'ja-JP')
88
+ })
89
+
90
+ test('qrcode_cash flow: initializes amount by minimum rule and handles input', () => {
91
+ const machine = qrcodeCashFactory(createRequestStub(), {
92
+ paymentDetail: [
93
+ {
94
+ category: 'qrcode',
95
+ transferType: 'deposit',
96
+ optional: [100, 200],
97
+ minimum: 50,
98
+ maximum: 5000,
99
+ method: 'qrcode_method',
100
+ grandTotalEnable: 0,
101
+ },
102
+ ],
103
+ promotion: { minimumAmount: 120 },
104
+ selectedAmount: 10,
105
+ })
106
+
107
+ let state = machine.initialState
108
+ assert.equal(state.value, 'debouncing')
109
+ assert.equal(state.context.selectedAmount, 120)
110
+
111
+ state = machine.transition(state, { type: 'INPUT_AMOUNT', data: 350 })
112
+ assert.equal(state.value, 'debouncing')
113
+ assert.equal(state.context.selectedAmount, 350)
114
+
115
+ state = machine.transition(state, { type: 'SET_PROMOTION', data: { minimumAmount: 400, promotionsNo: 'P001' } })
116
+ assert.equal(state.context.selectedAmount, 400)
117
+ })
118
+
119
+ test('auth flow: LOGIN_ID sets credentials and moves to authentication', () => {
120
+ global.localStorage = createLocalStorageMock()
121
+ const machine = authFactory(createRequestStub())
122
+
123
+ let state = machine.initialState
124
+ state = machine.transition(state, {
125
+ type: 'LOGIN_ID',
126
+ data: { username: 'alice', password: 'pw', reCaptchaToken: 'token' },
127
+ })
128
+
129
+ assert.equal(state.value, 'authentication')
130
+ assert.equal(state.context.reCaptchaToken, 'token')
131
+ assert.equal(state.context.loginData.provider, 'local')
132
+ assert.equal(state.context.loginData.username, 'alice')
133
+ })
134
+
135
+ test('auth flow: LOGIN_PHONE maps phone payload and countryAbbr', () => {
136
+ global.localStorage = createLocalStorageMock()
137
+ const machine = authFactory(createRequestStub())
138
+ let state = machine.initialState
139
+
140
+ state = machine.transition(state, {
141
+ type: 'LOGIN_PHONE',
142
+ data: { countryCode: '66', countryAbbr: 'TH', phone: '0800000000', password: 'pw', reCaptchaToken: 'r' },
143
+ })
144
+
145
+ assert.equal(state.value, 'authentication')
146
+ assert.equal(state.context.loginData.provider, 'phone')
147
+ assert.equal(state.context.loginData.countryCode, '66')
148
+ assert.equal(state.context.countryAbbr, 'TH')
149
+ })
150
+
151
+ test('common flow: login refresh then logout pause toggles feed/login flags', () => {
152
+ global.localStorage = createLocalStorageMock()
153
+ global.window = {
154
+ location: { search: '' },
155
+ atob: (value) => Buffer.from(value, 'base64').toString('binary'),
156
+ CC_JSB: false,
157
+ }
158
+ global.document = { cookie: '' }
159
+
160
+ const machine = commonFactory(createRequestStub())
161
+ let state = machine.initialState
162
+
163
+ assert.equal(state.value.feed, 'idle')
164
+ assert.equal(state.context.isLogin, false)
165
+
166
+ state = machine.transition(state, { type: 'LOGIN_REFRESH' })
167
+ assert.equal(state.value.feed, 'updating')
168
+ assert.equal(state.context.isLogin, true)
169
+
170
+ state = machine.transition(state, { type: 'LOGOUT_PAUSE' })
171
+ assert.equal(state.value.feed, 'idle')
172
+ assert.equal(state.context.isLogin, false)
173
+ assert.equal(state.context.broadcastList, null)
174
+ })
175
+
176
+ test('common flow: enter game pause resets feed payload and keeps feed idle', () => {
177
+ global.localStorage = createLocalStorageMock()
178
+ global.window = {
179
+ location: { search: '' },
180
+ atob: (value) => Buffer.from(value, 'base64').toString('binary'),
181
+ CC_JSB: false,
182
+ }
183
+ global.document = { cookie: '' }
184
+
185
+ const machine = commonFactory(createRequestStub())
186
+ let state = machine.initialState
187
+
188
+ state = machine.transition(state, {
189
+ type: 'ENTER_GAME_PAUSE',
190
+ })
191
+
192
+ assert.equal(state.value.feed, 'idle')
193
+ assert.equal(state.context.isPlaying, true)
194
+ assert.equal(state.context.mailBoxInfo, null)
195
+ })
196
+
197
+ test('direct_cash flow: init selects first method and clamps selectedAmount by promotion minimum', () => {
198
+ const machine = directCashFactory(createRequestStub(), {
199
+ paymentDetail: [
200
+ {
201
+ category: 'direct',
202
+ transferType: 'deposit',
203
+ minimum: 100,
204
+ maximum: 5000,
205
+ method: 'direct_1',
206
+ },
207
+ ],
208
+ promotion: { minimumAmount: 300 },
209
+ selectedAmount: 20,
210
+ })
211
+
212
+ const state = machine.initialState
213
+ assert.equal(state.context.selectedDirect.method, 'direct_1')
214
+ assert.equal(state.context.selectedAmount, 300)
215
+ })
216
+
217
+ test('usdt_cash flow: handles empty payment detail with safe defaults', () => {
218
+ const machine = usdtCashFactory(createRequestStub(), {
219
+ paymentDetail: [],
220
+ })
221
+
222
+ const state = machine.initialState
223
+ assert.equal(state.context.currentPayment, null)
224
+ assert.deepEqual(state.context.networks, [])
225
+ assert.equal(state.context.selectedNetwork, null)
226
+ })
@@ -0,0 +1,105 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import gameHotNewFactory from '../src/machine/game_hot_new.js'
5
+ import vipTableFactory from '../src/machine/vip_table.js'
6
+
7
+ test('game_hot_new actions and services cover id/game mapping branches', async () => {
8
+ const sent = []
9
+ const request = {
10
+ send: async (req) => {
11
+ sent.push(req)
12
+ if (req.url === 'game/list/v2/category' && req.params?.id == null) {
13
+ return {
14
+ list: [
15
+ { id: 10, category: 'SYSTEM_TOP_GAME' },
16
+ { id: 20, category: 'SYSTEM_NEW_GAME' },
17
+ ],
18
+ }
19
+ }
20
+ if (req.url === 'game/list/v2/category' && req.params?.id === 10) {
21
+ return { list: [{ g: { code: 'H1' } }, { g: { code: 'H2' } }] }
22
+ }
23
+ if (req.url === 'game/list/v2/category' && req.params?.id === 20) {
24
+ return { list: [{ g: { code: 'N1' } }] }
25
+ }
26
+ return {}
27
+ },
28
+ }
29
+
30
+ const machine = gameHotNewFactory(request)
31
+ const actions = machine.options.actions
32
+ const services = machine.options.services
33
+ const ctx = machine.initialState.context
34
+
35
+ const setId = actions.setId.assignment(ctx, {
36
+ data: {
37
+ list: [
38
+ { id: 10, category: 'SYSTEM_TOP_GAME' },
39
+ { id: 20, category: 'SYSTEM_NEW_GAME' },
40
+ ],
41
+ },
42
+ })
43
+ assert.equal(setId.hot.id, 10)
44
+ assert.equal(setId.new.id, 20)
45
+
46
+ const setIdMissing = actions.setId.assignment(ctx, { data: { list: [] } })
47
+ assert.equal(setIdMissing.hot.id, undefined)
48
+ assert.equal(setIdMissing.new.id, undefined)
49
+
50
+ const setGames = actions.setGames.assignment(ctx, {
51
+ data: { games: { hot: [{ code: 'H1' }], new: [{ code: 'N1' }] } },
52
+ })
53
+ assert.equal(setGames.hot.list.length, 1)
54
+ assert.equal(setGames.new.list.length, 1)
55
+
56
+ const roomItems = await services.getRoomItems(ctx, {})
57
+ assert.equal(roomItems.list.length, 2)
58
+ const games = await services.getGames({ ...ctx, hot: { ...ctx.hot, id: 10 }, new: { ...ctx.new, id: 20 } }, {})
59
+ assert.equal(games.games.hot.length, 2)
60
+ assert.equal(games.games.new.length, 1)
61
+ const emptyGames = await services.getGames({ ...ctx, hot: { ...ctx.hot, id: -1 }, new: { ...ctx.new, id: -2 } }, {})
62
+ assert.equal(emptyGames.games.hot, undefined)
63
+ assert.equal(emptyGames.games.new, undefined)
64
+
65
+ assert.equal(
66
+ sent.some((req) => req.url === 'game/list/v2/category'),
67
+ true
68
+ )
69
+ })
70
+
71
+ test('vip_table service supports both old and v2 response structures', async () => {
72
+ let call = 0
73
+ const request = {
74
+ config: { appSecret: 'secret' },
75
+ send: async (req) => {
76
+ call += 1
77
+ if (req.url === 'activities/viptable' && req.params?.appSecret === 'secret') {
78
+ if (call === 1) {
79
+ return { viptable: { data: [{ title: 'BRONZE' }, { title: 'SILVER' }] } }
80
+ }
81
+ return { data: [{ title: 'GOLD' }] }
82
+ }
83
+ return { data: [{ title: 'GOLD' }] }
84
+ },
85
+ }
86
+ const machine = vipTableFactory(request)
87
+ const actions = machine.options.actions
88
+ const services = machine.options.services
89
+ const ctx = machine.initialState.context
90
+
91
+ const setVip = actions.setVipTable.assignment(ctx, { data: [{ title: 'gold' }] })
92
+ assert.equal(setVip.vipTable[0].title, 'gold')
93
+
94
+ const v2 = await services.fetchVipTable(ctx, {})
95
+ assert.deepEqual(
96
+ v2.map((i) => i.title),
97
+ ['bronze', 'silver']
98
+ )
99
+
100
+ const legacy = await services.fetchVipTable({ ...ctx }, {})
101
+ assert.deepEqual(
102
+ legacy.map((i) => i.title),
103
+ ['gold']
104
+ )
105
+ })
@@ -0,0 +1,195 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import gameSearchCashFactory from '../src/machine/game_search_cash.js'
5
+
6
+ test('game_search_cash actions and guards cover assignment branches', () => {
7
+ const machine = gameSearchCashFactory({ send: async () => ({}) })
8
+ const actions = machine.options.actions
9
+ const guards = machine.options.guards
10
+ const ctx = machine.initialState.context
11
+
12
+ assert.equal(actions.setInitialized.assignment(ctx, {}).initialized, true)
13
+ assert.deepEqual(actions.setMainTagList.assignment(ctx, { data: [{ id: 1 }] }).mainTagList, [{ id: 1 }])
14
+
15
+ const initialData = actions.setInitialData.assignment(ctx, {
16
+ data: {
17
+ home: {
18
+ recentlySearch: [
19
+ { id: 1, i18n: 'ok' },
20
+ { id: null, i18n: 'x' },
21
+ { id: 2, i18n: null },
22
+ ],
23
+ recentlyGame: [{ id: 'g1' }],
24
+ youMayLike: [{ id: 'm1' }],
25
+ },
26
+ tag: { result: [{ id: 11 }] },
27
+ },
28
+ })
29
+ assert.equal(initialData.recentlySearch.length, 1)
30
+ assert.equal(initialData.mainTagList[0].id, 11)
31
+
32
+ const mainTagCtx = { ...ctx, mainTagList: [{ id: 11 }, { id: 12 }] }
33
+ const mainTagSelected = actions.setMainTagId.assignment(mainTagCtx, { data: 12 })
34
+ assert.equal(mainTagSelected.tagIndex, 1)
35
+ assert.equal(mainTagSelected.click, 1)
36
+ assert.equal(mainTagSelected.clickDefault, null)
37
+
38
+ const setTagFromMain = actions.setTagId.assignment(mainTagCtx, { data: { tagId: 11 } })
39
+ assert.equal(setTagFromMain.tagIndex, 0)
40
+ assert.equal(setTagFromMain.clickDefault, 1)
41
+
42
+ const setTagFromSearch = actions.setTagId.assignment({ ...ctx, tagList: [{ id: 21 }, { id: 22 }] }, { data: { tagId: 22 } })
43
+ assert.equal(setTagFromSearch.tagIndex, 1)
44
+ assert.equal(setTagFromSearch.click, 1)
45
+ assert.equal(setTagFromSearch.clickDefault, null)
46
+
47
+ assert.deepEqual(actions.setGames.assignment(ctx, { data: { traceId: 't1', gameList: [{ gameCode: 'A' }] } }), {
48
+ traceId: 't1',
49
+ gameList: [{ gameCode: 'A' }],
50
+ })
51
+ assert.equal(actions.setKeyword.assignment(ctx, { data: { keyword: 'slot' } }).keyword, 'slot')
52
+ assert.equal(actions.setLang.assignment(ctx, { data: { lang: 'th-TH' } }).lang, 'th-TH')
53
+ assert.deepEqual(actions.setGamesByProvider.assignment(ctx, { data: { gameList: [{ id: 1 }], tagList: [{ id: 9 }] } }), {
54
+ tagList: [{ id: 9 }],
55
+ gameList: [{ id: 1 }],
56
+ })
57
+ assert.equal(actions.clearKeyword.assignment({ ...ctx, keyword: 'x' }, {}).keyword, '')
58
+ assert.deepEqual(actions.setTagList.assignment(ctx, { data: { tagList: [{ id: 1 }] } }), { tagList: [{ id: 1 }] })
59
+
60
+ const codeSet = actions.setGameCode.assignment({ ...ctx, gameList: [{ gameCode: 'A' }, { gameCode: 'B' }] }, { data: 'B' })
61
+ assert.equal(codeSet.gameCode, 'B')
62
+ assert.equal(codeSet.gameCodeIndex, 1)
63
+
64
+ const providerSet = actions.setProviderName.assignment(ctx, {
65
+ data: { providerName: 'PG', keyword: 'hot', lang: 'en-US' },
66
+ })
67
+ assert.equal(providerSet.providerName, 'PG')
68
+ assert.equal(providerSet.keyword, 'hot')
69
+ assert.equal(providerSet.lang, 'en-US')
70
+
71
+ assert.equal(guards.hasMainTags({ ...ctx, mainTagList: [1] }, {}), true)
72
+ assert.equal(guards.hasTagList({ ...ctx, tagList: [1] }, {}), true)
73
+ assert.equal(guards.isInitialized({ ...ctx, initialized: true }, {}), true)
74
+ assert.equal(guards.isGameTagMode(ctx, { data: { isGameTagMode: true } }), true)
75
+ })
76
+
77
+ test('game_search_cash services cover tags/home/list/provider/trace branches', async () => {
78
+ const sent = []
79
+ const request = {
80
+ send: async (req) => {
81
+ sent.push(req)
82
+ if (req.url === 'game/search/home') {
83
+ return {
84
+ recentlySearch: [{ id: 1, i18n: 'slot' }],
85
+ recentlyGame: [{ id: 'g1' }],
86
+ youMayLike: [{ id: 'm1' }],
87
+ }
88
+ }
89
+ if (req.url === 'game/search') {
90
+ return { result: [{ id: 9, i18n: 'slot' }] }
91
+ }
92
+ if (req.url === 'game/search/list') {
93
+ return { traceId: 'trace-1', result: [{ gameCode: 'G001' }] }
94
+ }
95
+ if (req.url === 'game/search/trace') {
96
+ return { ok: true, params: req.params }
97
+ }
98
+ return {}
99
+ },
100
+ }
101
+
102
+ const machine = gameSearchCashFactory(request)
103
+ const services = machine.options.services
104
+ const base = {
105
+ ...machine.initialState.context,
106
+ keyword: 'slot',
107
+ lang: 'en-US',
108
+ tagId: 9,
109
+ tagIndex: 0,
110
+ click: 1,
111
+ clickDefault: null,
112
+ providerName: 'PG',
113
+ traceId: 'trace-1',
114
+ gameCode: 'G001',
115
+ gameCodeIndex: 0,
116
+ }
117
+
118
+ const tags = await services.fetchTags(base, {})
119
+ assert.deepEqual(tags.tagList, [{ id: 9, i18n: 'slot' }])
120
+
121
+ const initial = await services.fetchInitialData(base, {})
122
+ assert.equal(initial.home.recentlyGame[0].id, 'g1')
123
+ assert.equal(initial.tag.result[0].id, 9)
124
+
125
+ const games = await services.fetchGames(base, {})
126
+ assert.equal(games.traceId, 'trace-1')
127
+ assert.equal(games.gameList.length, 1)
128
+
129
+ const byProvider = await services.fetchGamesByProvider(base, {})
130
+ assert.equal(byProvider.gameList[0].gameCode, 'G001')
131
+ assert.equal(byProvider.tagList[0].id, 9)
132
+
133
+ const byKeyword = await services.fetchGamesByKeyword(base, {})
134
+ assert.equal(byKeyword.tagId, 9)
135
+ assert.equal(byKeyword.traceId, 'trace-1')
136
+ assert.equal(byKeyword.tagList[0].id, 9)
137
+
138
+ const trace = await services.sendTrace(base, {})
139
+ assert.equal(trace.ok, true)
140
+ assert.equal(trace.params.traceId, 'trace-1')
141
+ assert.equal(trace.params.gameCode, 'G001')
142
+
143
+ const mayLike = await services.sendMayLikeTrace(base, {})
144
+ assert.equal(mayLike.ok, true)
145
+ assert.equal(mayLike.params.isYouMayLike, true)
146
+
147
+ assert.equal(
148
+ sent.some((req) => req.url === 'game/search/home'),
149
+ true
150
+ )
151
+ assert.equal(
152
+ sent.some((req) => req.url === 'game/search/trace'),
153
+ true
154
+ )
155
+ })
156
+
157
+ test('game_search_cash fetchGamesByKeyword safely handles empty tag result', async () => {
158
+ const sent = []
159
+ const request = {
160
+ send: async (req) => {
161
+ sent.push(req)
162
+ if (req.url === 'game/search') {
163
+ return { result: [] }
164
+ }
165
+ if (req.url === 'game/search/list') {
166
+ return { traceId: 'unexpected', result: [{ gameCode: 'x' }] }
167
+ }
168
+ return {}
169
+ },
170
+ }
171
+
172
+ const machine = gameSearchCashFactory(request)
173
+ const services = machine.options.services
174
+ const result = await services.fetchGamesByKeyword(
175
+ {
176
+ ...machine.initialState.context,
177
+ keyword: 'no-result',
178
+ lang: 'en-US',
179
+ click: 1,
180
+ clickDefault: null,
181
+ },
182
+ {}
183
+ )
184
+
185
+ assert.deepEqual(result, {
186
+ tagId: null,
187
+ traceId: null,
188
+ gameList: [],
189
+ tagList: [],
190
+ })
191
+ assert.equal(
192
+ sent.some((req) => req.url === 'game/search/list'),
193
+ false
194
+ )
195
+ })