@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,100 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import gameInfoFactory from '../src/machine/game_info.js'
5
+ import gameBetslipFactory from '../src/machine/game_betslip.js'
6
+ import gameReplayFactory from '../src/machine/game_replay.js'
7
+ import userInfoFactory from '../src/machine/user_info.js'
8
+ import userPhotoFactory from '../src/machine/user_photo.js'
9
+
10
+ test('game_info/game_betslip/game_replay services and actions map responses', async () => {
11
+ const sent = []
12
+ const request = {
13
+ config: { appSecret: 'secret' },
14
+ send: async (req) => {
15
+ sent.push(req)
16
+ if (req.url === 'game/info') return { data: { gameCode: req.params.gameCode } }
17
+ if (req.url === 'game/betslip') return { ticket: 't1' }
18
+ if (req.url === 'game/gameReplay') return { data: { replay: true } }
19
+ return {}
20
+ },
21
+ }
22
+
23
+ const gameInfoWithCode = gameInfoFactory(request, { gameCode: 'G001' })
24
+ const infoActions = gameInfoWithCode.options.actions
25
+ const infoServices = gameInfoWithCode.options.services
26
+ const infoCtx = gameInfoWithCode.initialState.context
27
+ assert.equal(infoActions.setGameInfo.assignment(infoCtx, { data: { data: { name: 'A' } } }).gameInfo.name, 'A')
28
+ const info = await infoServices.fetchGameInfo(infoCtx, {})
29
+ assert.equal(info.data.gameCode, 'G001')
30
+
31
+ const gameInfoNoCode = gameInfoFactory(request, { gameCode: null })
32
+ const emptyInfo = await gameInfoNoCode.options.services.fetchGameInfo(gameInfoNoCode.initialState.context, {})
33
+ assert.deepEqual(emptyInfo, { data: {} })
34
+
35
+ const betslip = gameBetslipFactory(request, { providerId: 'P1', seqNo: 'S1', lang: 'en-US' })
36
+ const bActions = betslip.options.actions
37
+ const bServices = betslip.options.services
38
+ assert.equal(bActions.setBetslip.assignment(betslip.initialState.context, { data: { ticket: 't1' } }).gameBetSlip.ticket, 't1')
39
+ const bData = await bServices.fetchBetslip(betslip.initialState.context, {})
40
+ assert.equal(bData.ticket, 't1')
41
+
42
+ const replay = gameReplayFactory(request, { providerId: 'P1', seqNo: 'S2', lang: 'en-US' })
43
+ const rActions = replay.options.actions
44
+ const rServices = replay.options.services
45
+ assert.equal(rActions.setGameReplayInfo.assignment(replay.initialState.context, { data: { data: { replay: 1 } } }).gameReplayInfo.replay, 1)
46
+ const rData = await rServices.fetchGameReplayInfo(replay.initialState.context, {})
47
+ assert.equal(rData.data.replay, true)
48
+
49
+ assert.equal(
50
+ sent.some((req) => req.url === 'game/betslip'),
51
+ true
52
+ )
53
+ assert.equal(
54
+ sent.some((req) => req.url === 'game/gameReplay'),
55
+ true
56
+ )
57
+ })
58
+
59
+ test('user_info and user_photo services/actions cover fetch and update', async () => {
60
+ const sent = []
61
+ const request = {
62
+ send: async (req) => {
63
+ sent.push(req)
64
+ if (req.url === 'self' && req.method === 'get') return { uid: 'u1', nick: 'A' }
65
+ if (req.url === 'self' && req.method === 'post') return { ok: true, params: req.params }
66
+ if (req.url === 'getAllAvatar') return { data: [{ id: 1 }, { id: 2 }] }
67
+ if (req.url === 'updateUserAvatar') return { ok: true, params: req.params }
68
+ return {}
69
+ },
70
+ }
71
+
72
+ const userInfo = userInfoFactory(request)
73
+ const uiActions = userInfo.options.actions
74
+ const uiServices = userInfo.options.services
75
+ const uiCtx = userInfo.initialState.context
76
+ assert.equal(uiActions.setUserInfo.assignment(uiCtx, { data: { uid: 'u1' } }).userInfo.uid, 'u1')
77
+ const info = await uiServices.fetchUserInfo(uiCtx, {})
78
+ assert.equal(info.uid, 'u1')
79
+ const upd = await uiServices.updateUserInfo(uiCtx, { data: { nick_name: 'B' } })
80
+ assert.equal(upd.ok, true)
81
+
82
+ const userPhoto = userPhotoFactory(request)
83
+ const upActions = userPhoto.options.actions
84
+ const upServices = userPhoto.options.services
85
+ const upCtx = userPhoto.initialState.context
86
+ assert.equal(upActions.setUserPhotoList.assignment(upCtx, { data: { data: [{ id: 1 }] } }).userPhotoList[0].id, 1)
87
+ const list = await upServices.fetchUserPhotoList(upCtx, {})
88
+ assert.equal(list.data.length, 2)
89
+ const updPhoto = await upServices.updateUserPhoto(upCtx, { data: { avatar: 2 } })
90
+ assert.equal(updPhoto.ok, true)
91
+
92
+ assert.equal(
93
+ sent.some((req) => req.url === 'self' && req.method === 'post'),
94
+ true
95
+ )
96
+ assert.equal(
97
+ sent.some((req) => req.url === 'updateUserAvatar'),
98
+ true
99
+ )
100
+ })
@@ -0,0 +1,133 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import honorBoardFactory from '../src/machine/honor_board.js'
5
+ import honorBoardCashFactory from '../src/machine/honor_board_cash.js'
6
+
7
+ function createRequestStub() {
8
+ const calls = []
9
+ return {
10
+ calls,
11
+ request: {
12
+ config: { appSecret: 'secret' },
13
+ send: async (req) => {
14
+ calls.push(req)
15
+ return {
16
+ data: [
17
+ { type: 'DEPOSIT', data: [{ broadcastId: 2, time: 2 }] },
18
+ { type: 'JACKPOT', data: [{ broadcastId: 1, time: 1 }] },
19
+ ],
20
+ }
21
+ },
22
+ },
23
+ }
24
+ }
25
+
26
+ test('honor_board: actions/guard/delay/service branches are stable', async () => {
27
+ const { request, calls } = createRequestStub()
28
+ const machine = honorBoardFactory(request)
29
+
30
+ const setBroadcastList = machine.options.actions.setBroadcastList.assignment
31
+ const setBroadcast = machine.options.actions.setBroadcast.assignment
32
+ const resetBroadcast = machine.options.actions.resetBroadcast.assignment
33
+ const leaveGame = machine.options.actions.leaveGame.assignment
34
+ const isNotInGame = machine.options.guards.isNotInGame
35
+ const timeout = machine.options.delays.TIMEOUT
36
+ const fetchHonorBoardList = machine.options.services.fetchHonorBoardList
37
+
38
+ const sorted = setBroadcastList(machine.initialState.context, {
39
+ data: [{ data: [{ broadcastId: 'b2', time: 3 }] }, { data: [{ broadcastId: 'b1', time: 1 }, { broadcastId: 'b0' }] }],
40
+ })
41
+ assert.deepEqual(
42
+ sorted.broadcastList.map((item) => item.broadcastId),
43
+ ['b0', 'b1', 'b2']
44
+ )
45
+
46
+ const firstPick = setBroadcast(
47
+ {
48
+ ...machine.initialState.context,
49
+ broadcastList: [{ broadcastId: 'a' }, { broadcastId: 'b' }],
50
+ sentNormalBroadcastList: [],
51
+ normalBroadcast: null,
52
+ },
53
+ {}
54
+ )
55
+ assert.equal(firstPick.normalBroadcast.broadcastId, 'a')
56
+
57
+ const secondPick = setBroadcast(
58
+ {
59
+ ...machine.initialState.context,
60
+ broadcastList: [{ broadcastId: 'a' }, { broadcastId: 'b' }],
61
+ sentNormalBroadcastList: [{ broadcastId: 'a' }],
62
+ normalBroadcast: { broadcastId: 'a' },
63
+ },
64
+ {}
65
+ )
66
+ assert.equal(secondPick.normalBroadcast.broadcastId, 'b')
67
+
68
+ assert.equal(resetBroadcast(machine.initialState.context, {}).isPlaying, true)
69
+ assert.equal(leaveGame({ ...machine.initialState.context, isPlaying: true }, {}).isPlaying, false)
70
+ assert.equal(isNotInGame({ isPlaying: false }, {}), true)
71
+ assert.equal(isNotInGame({ isPlaying: true }, {}), false)
72
+ assert.equal(timeout({ tick: 6 }, {}), 60)
73
+
74
+ const data = await fetchHonorBoardList(machine.initialState.context, {})
75
+ assert.equal(Array.isArray(data), true)
76
+ assert.equal(calls.length, 1)
77
+ })
78
+
79
+ test('honor_board_cash: action/delay/service map all tab branches', async () => {
80
+ const calls = []
81
+ const request = {
82
+ config: { appSecret: 'secret' },
83
+ send: async (req) => {
84
+ calls.push(req)
85
+ return {
86
+ data: [
87
+ { type: 'CASH_RAIN', id: 1 },
88
+ { type: 'DEPOSIT', id: 2 },
89
+ { type: 'FREE_ROULETTE_SPIN', id: 3 },
90
+ { type: 'JACKPOT', id: 4 },
91
+ { type: 'WIN_SCORE', id: 5 },
92
+ { type: 'WIN_MULTIPLIER', id: 6 },
93
+ { type: 'WITHDRAW', id: 7 },
94
+ { type: 'UNKNOWN', id: 8 },
95
+ ],
96
+ }
97
+ },
98
+ }
99
+
100
+ const machine = honorBoardCashFactory(request)
101
+ const setHonorBoardList = machine.options.actions.setHonorBoardList.assignment
102
+ const timeout = machine.options.delays.TIMEOUT
103
+ const fetchHonorBoardList = machine.options.services.fetchHonorBoardList
104
+
105
+ const mapped = setHonorBoardList(machine.initialState.context, {
106
+ data: [
107
+ { type: 'CASH_RAIN', value: 1 },
108
+ { type: 'DEPOSIT', value: 2 },
109
+ { type: 'FREE_ROULETTE_SPIN', value: 3 },
110
+ { type: 'JACKPOT', value: 4 },
111
+ { type: 'WIN_SCORE', value: 5 },
112
+ { type: 'WIN_MULTIPLIER', value: 6 },
113
+ { type: 'WITHDRAW', value: 7 },
114
+ { type: 'UNKNOWN', value: 8 },
115
+ ],
116
+ })
117
+ assert.deepEqual(mapped.tabs, ['cashRain', 'deposit', 'roulette', 'jackpot', 'bigWin', 'maxBet', 'withdraw', undefined])
118
+ assert.equal(mapped.cashRain.value, 1)
119
+ assert.equal(mapped.deposit.value, 2)
120
+ assert.equal(mapped.roulette.value, 3)
121
+ assert.equal(mapped.jackpot.value, 4)
122
+ assert.equal(mapped.bigWin.value, 5)
123
+ assert.equal(mapped.maxBet.value, 6)
124
+ assert.equal(mapped.withdraw.value, 7)
125
+ const emptyMapped = setHonorBoardList(machine.initialState.context, { data: null })
126
+ assert.deepEqual(emptyMapped.tabs, [])
127
+ assert.deepEqual(emptyMapped.cashRain, {})
128
+ assert.equal(timeout({ tick: 7 }, {}), 70)
129
+
130
+ const data = await fetchHonorBoardList(machine.initialState.context, {})
131
+ assert.equal(Array.isArray(data), true)
132
+ assert.equal(calls.length, 1)
133
+ })
@@ -0,0 +1,304 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import inboxFactory from '../src/machine/inbox.js'
5
+ import commonFactory from '../src/machine/common.js'
6
+ import { createLocalStorageMock } from './helpers.js'
7
+
8
+ function toBase64UrlJson(input) {
9
+ return Buffer.from(JSON.stringify(input)).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '')
10
+ }
11
+
12
+ test('inbox actions and guards cover selection/read/customer branches', () => {
13
+ const request = { config: { appSecret: 'secret' }, send: async () => ({}) }
14
+ const machine = inboxFactory(request)
15
+ const { actions, guards } = machine.options
16
+ const showMessageCustomerReadCond = machine.config.states.more.states.idle.on.SHOW_MESSAGE[0].cond
17
+
18
+ const baseContext = {
19
+ ...machine.initialState.context,
20
+ currentTab: 'CUSTOMER',
21
+ tabs: ['CUSTOMER', 'SYSTEM'],
22
+ inbox: {
23
+ CUSTOMER: {
24
+ page: 0,
25
+ totalPage: 2,
26
+ data: [
27
+ { groupId: 'g1', isSelected: false, isRead: false },
28
+ { groupId: 'g2', isSelected: true, isRead: true },
29
+ ],
30
+ },
31
+ },
32
+ }
33
+
34
+ assert.equal(guards.hasTabs(baseContext), true)
35
+ assert.equal(guards.isEnd(baseContext), false)
36
+ assert.equal(guards.isEnd({ ...baseContext, inbox: { CUSTOMER: { page: 0, totalPage: 1, data: [] } } }), true)
37
+ assert.equal(guards.isEnd({ ...baseContext, inbox: {} }), false)
38
+ assert.equal(guards.isRead(baseContext, { data: { isRead: true } }), true)
39
+ assert.equal(showMessageCustomerReadCond(baseContext, { data: { isRead: true } }), true)
40
+ assert.equal(guards.isCustomer(baseContext), true)
41
+ assert.equal(guards.isSendable({ messageTitle: 't', messageContent: 'c' }), true)
42
+
43
+ assert.equal(actions.setLang.assignment({ lang: null }, { data: { locale: 'th-TH' } }).lang, 'th-TH')
44
+ assert.equal(actions.setLang.assignment({ lang: 'en-US' }, { data: {} }).lang, 'en-US')
45
+ assert.equal(actions.reset.assignment(baseContext, {}).currentTab, null)
46
+
47
+ const resetPageMissing = actions.resetPage.assignment({ ...baseContext, currentTab: 'SYSTEM' }, {})
48
+ assert.equal(resetPageMissing.inbox.CUSTOMER.page, 0)
49
+ const resetPageHit = actions.resetPage.assignment(baseContext, {})
50
+ assert.equal(resetPageHit.inbox.CUSTOMER.page, -1)
51
+
52
+ assert.equal(
53
+ actions.setTabs.assignment({ ...baseContext, currentTab: null, hasCustomer: true }, { data: ['SYSTEM', 'CUSTOMER'] }).currentTab,
54
+ 'CUSTOMER'
55
+ )
56
+ assert.equal(actions.setTabs.assignment({ ...baseContext, currentTab: null, hasCustomer: false }, { data: ['SYSTEM'] }).currentTab, 'SYSTEM')
57
+ assert.equal(actions.setCurrentTab.assignment(baseContext, { data: 'SYSTEM' }).currentTab, 'SYSTEM')
58
+
59
+ const selected = actions.selectMessages.assignment(baseContext, { data: { groupId: 'g1' } })
60
+ assert.equal(selected.inbox.CUSTOMER.data[0].isSelected, true)
61
+
62
+ const cancelSelected = actions.cancelSelectMessages.assignment(baseContext, {})
63
+ assert.equal(
64
+ cancelSelected.inbox.CUSTOMER.data.every((item) => item.isSelected === false),
65
+ true
66
+ )
67
+ assert.equal(actions.cancelSelectMessages.assignment({ ...baseContext, inbox: {} }, {}).selectedDeleteMessages, null)
68
+
69
+ assert.equal(actions.setDelectMessages.assignment(baseContext, {}).selectedDeleteMessages, 'g2')
70
+
71
+ const customerCombined = actions.setCustomerMessage.assignment(baseContext, {
72
+ data: {
73
+ data: [
74
+ { from: 'SYSTEM', content: 'A', title: 'T1' },
75
+ { from: 'USER', content: 'B', title: 'T2' },
76
+ ],
77
+ },
78
+ })
79
+ assert.equal(typeof customerCombined.messageContent, 'string')
80
+ const customerSingle = actions.setCustomerMessage.assignment(baseContext, {
81
+ data: { data: [{ from: 'USER', content: 'Only', title: 'T3' }] },
82
+ })
83
+ assert.equal(customerSingle.messageContent, 'Only')
84
+
85
+ assert.equal(actions.showMessage.assignment(baseContext, { data: { groupId: 'g1' } }).currentMessage.groupId, 'g1')
86
+ assert.equal(actions.hideMessage.assignment(baseContext, {}).currentMessage, null)
87
+ assert.equal(actions.removeMessage.assignment(baseContext, { data: ['g1'] }).inbox.CUSTOMER.data.length, 1)
88
+ assert.equal(actions.setInbox.assignment(baseContext, { data: { X: { data: [] } } }).inbox.X.data.length, 0)
89
+ assert.equal(actions.setMessageIsRead.assignment(baseContext, { data: { groupId: 'g1' } }).inbox.CUSTOMER.data[0].isRead, true)
90
+ assert.equal(actions.setMessageTitle.assignment(baseContext, { data: 'title' }).messageTitle, 'title')
91
+ assert.equal(actions.setMessageContent.assignment(baseContext, { data: 'content' }).messageContent, 'content')
92
+ })
93
+
94
+ test('inbox services cover reward/mailbox fetch and mutation APIs', async () => {
95
+ const sent = []
96
+ const request = {
97
+ config: { appSecret: 'secret' },
98
+ send: async (req) => {
99
+ sent.push(req)
100
+ if (req.url === 'mailbox/getMessageTypes') return { data: [{ type: 'CUSTOMER' }, { type: 'REWARD' }] }
101
+ if (req.url === 'activities/rewards') return { data: [{ groupId: 'r1', isRead: false }] }
102
+ if (req.url === 'mailbox/getMessageList?include=cl') {
103
+ return { data: [{ groupId: 'm1', isRead: false }], page: 0, totalPage: 3 }
104
+ }
105
+ if (req.url === 'mailbox/updateMessage') {
106
+ if (req.params?.isDelete) return { groupId: req.params.groupId }
107
+ return { ok: true }
108
+ }
109
+ if (req.url === 'mailbox/sendMessage') return { ok: true }
110
+ if (req.url === 'mailbox/getMessage') return { data: [{ from: 'SYSTEM', content: 'hello', title: 'T' }] }
111
+ return {}
112
+ },
113
+ }
114
+
115
+ const machine = inboxFactory(request)
116
+ const { services } = machine.options
117
+
118
+ const tabs = await services.fetchTabs({}, {})
119
+ assert.deepEqual(tabs, ['CUSTOMER', 'REWARD'])
120
+
121
+ const rewardInbox = await services.fetchMessages({ lang: 'en-US', isRewardListEnable: true, currentTab: 'REWARD', inbox: {} }, {})
122
+ assert.equal(rewardInbox.REWARD.data.length, 1)
123
+
124
+ const mailboxInbox = await services.fetchMessages({ lang: 'en-US', isRewardListEnable: false, currentTab: 'CUSTOMER', inbox: {} }, {})
125
+ assert.equal(mailboxInbox.CUSTOMER.data[0].isSelected, false)
126
+
127
+ const reReward = await services.reFetchMessages({ lang: 'en-US', isRewardListEnable: true, currentTab: 'FREE_GAME', inbox: {} }, {})
128
+ assert.equal(reReward.FREE_GAME.page, 0)
129
+
130
+ const reMailbox = await services.reFetchMessages({ lang: 'en-US', isRewardListEnable: false, currentTab: 'CUSTOMER', inbox: {} }, {})
131
+ assert.equal(reMailbox.CUSTOMER.page, 0)
132
+
133
+ const isReadUpdated = await services.updateMessageIsRead({ currentMessage: { groupId: 'm1' } }, {})
134
+ assert.equal(isReadUpdated, true)
135
+
136
+ const deleted = await services.deleteMessages({ selectedDeleteMessages: 'm1,m2' }, {})
137
+ assert.deepEqual(deleted, ['m1', 'm2'])
138
+
139
+ const inquiry = await services.accountInquiry({}, { data: { from: 'USER', title: 'Need help', content: 'Please check' } })
140
+ assert.equal(inquiry.ok, true)
141
+
142
+ const msg = await services.getMessage({ currentMessage: { groupId: 'm1' } }, {})
143
+ assert.equal(Array.isArray(msg.data), true)
144
+
145
+ const sentMsg = await services.sendMessage({ messageTitle: 'T', messageContent: 'C' }, { data: { from: 'USER' } })
146
+ assert.equal(sentMsg.ok, true)
147
+
148
+ assert.equal(
149
+ sent.some((entry) => entry.url === 'mailbox/sendMessage'),
150
+ true
151
+ )
152
+ })
153
+
154
+ test('common actions/guards/services cover config decode, agent persistence and feed shaping', async () => {
155
+ global.localStorage = createLocalStorageMock()
156
+ global.window = {
157
+ location: { search: '?channel=ch&subchannel=sub&ac=aff&fc=friend&pix=p1&kpix=k1&fbclid=fb1' },
158
+ atob: (value) => Buffer.from(value, 'base64').toString('binary'),
159
+ CC_JSB: false,
160
+ }
161
+ global.document = { cookie: '' }
162
+
163
+ const sent = []
164
+ const request = {
165
+ config: { appSecret: 'secret', defaultChannel: 'def-ch', defaultSubchannel: 'def-sub' },
166
+ send: async (req) => {
167
+ sent.push(req)
168
+ if (req.url === 'getConfig') {
169
+ return {
170
+ config: `${toBase64UrlJson({
171
+ loginMethods: { phone: true, email: false },
172
+ registerMethods: { email: true, phone: false },
173
+ registerBindingAffiliateCodeInstructionsEnable: 'true',
174
+ csChat: [{ name: 'customermessage', enable: false }],
175
+ })}.sig`,
176
+ }
177
+ }
178
+ if (req.url === 'getQuickLayout') {
179
+ return { config: `${toBase64UrlJson({ theme: 'x' })}.sig` }
180
+ }
181
+ if (req.url === 'getAffiliateCode') return { affiliateCode: 'DA001' }
182
+ if (req.url === 'feeds')
183
+ return { broadcastList: { broadcasts: [{ type: '0', broadcast_id: 1 }] }, mailBoxInfo: { rows: 10, detailRows: { CUSTOMER: 2 } } }
184
+ if (req.url === 'getAnnouncements') return { data: [{ id: 1 }] }
185
+ return {}
186
+ },
187
+ }
188
+
189
+ const machine = commonFactory(request)
190
+ const { actions, guards, services, delays } = machine.options
191
+
192
+ const setUA = actions.setUA.assignment(machine.initialState.context, {})
193
+ assert.equal(typeof setUA.userAgent, 'object')
194
+
195
+ const setAgent = actions.setAgent.assignment(machine.initialState.context, {})
196
+ assert.equal(setAgent.channel, 'ch')
197
+ assert.equal(setAgent.subchannel, 'sub')
198
+
199
+ global.window.CC_JSB = true
200
+ assert.equal(actions.setAgent.assignment(machine.initialState.context, {}), undefined)
201
+ global.window.CC_JSB = false
202
+
203
+ assert.equal(actions.setFbclid.assignment(machine.initialState.context, {}).fbclid, 'fb1')
204
+ assert.equal(global.document.cookie.includes('_fbc='), true)
205
+
206
+ assert.equal(actions.setPixel.assignment(machine.initialState.context, {}).pix, 'p1')
207
+ assert.equal(actions.setKPixel.assignment(machine.initialState.context, {}).kpix, 'k1')
208
+
209
+ const layoutToken = `${toBase64UrlJson({ layout: 'v1' })}.sig`
210
+ const cfg = actions.setConfig.assignment(machine.initialState.context, {
211
+ data: {
212
+ siteConfig: {
213
+ loginMethods: { phone: true, email: false },
214
+ registerMethods: { email: true, phone: false },
215
+ },
216
+ layoutConfig: layoutToken,
217
+ },
218
+ })
219
+ assert.equal(cfg.siteConfig.loginMethods.phone, true)
220
+ assert.equal(cfg.siteConfig.loginMethods.email, undefined)
221
+ assert.equal(cfg.layoutConfig.layout, 'v1')
222
+
223
+ assert.equal(actions.setDefaultAffiliateCode.assignment(machine.initialState.context, { data: { affiliateCode: 'A1' } }).defaultAffiliateCode, 'A1')
224
+ assert.equal(actions.clearAnnouncements.assignment(machine.initialState.context, {}).announcementList, null)
225
+ assert.equal(actions.setAnnouncements.assignment(machine.initialState.context, { data: { data: [{ id: 1 }] } }).announcementList.data.length, 1)
226
+
227
+ const feeds = actions.setFeeds.assignment(
228
+ { ...machine.initialState.context, siteConfig: { csChat: [{ name: 'customermessage', enable: false }] } },
229
+ { data: { broadcastList: { broadcasts: [] }, mailBoxInfo: { rows: 10, detailRows: { CUSTOMER: 3 } } } }
230
+ )
231
+ assert.equal(feeds.mailBoxInfo.rows, 7)
232
+
233
+ const broadcast = actions.setBroadcast.assignment(
234
+ {
235
+ ...machine.initialState.context,
236
+ broadcastList: {
237
+ broadcasts: [
238
+ { type: '0', broadcast_id: 1 },
239
+ { type: '0', broadcast_id: 2 },
240
+ ],
241
+ },
242
+ sentNormalBroadcastList: [{ broadcast_id: 1 }],
243
+ normalBroadcast: { broadcast_id: 2 },
244
+ },
245
+ {}
246
+ )
247
+ assert.equal(broadcast.normalBroadcast, undefined)
248
+ assert.equal(broadcast.sentNormalBroadcastList.length, 2)
249
+ const broadcastNext = actions.setBroadcast.assignment(
250
+ {
251
+ ...machine.initialState.context,
252
+ broadcastList: {
253
+ broadcasts: [
254
+ { type: '1', broadcast_id: 10 },
255
+ { type: '0', broadcast_id: 11 },
256
+ ],
257
+ },
258
+ sentNormalBroadcastList: [{ broadcast_id: 1 }],
259
+ normalBroadcast: null,
260
+ },
261
+ {}
262
+ )
263
+ assert.equal(broadcastNext.normalBroadcast.broadcast_id, 11)
264
+ const broadcastWithoutQueue = actions.setBroadcast.assignment(
265
+ {
266
+ ...machine.initialState.context,
267
+ broadcastList: null,
268
+ sentNormalBroadcastList: [],
269
+ normalBroadcast: null,
270
+ },
271
+ {}
272
+ )
273
+ assert.equal(broadcastWithoutQueue.normalBroadcast, undefined)
274
+
275
+ assert.equal(actions.resetBroadcast.assignment(machine.initialState.context, {}).normalBroadcast, null)
276
+ assert.equal(actions.resetByEnterGame.assignment(machine.initialState.context, {}).isPlaying, true)
277
+ assert.equal(actions.leaveGame.assignment(machine.initialState.context, {}).isPlaying, false)
278
+ assert.equal(actions.resetByLogout.assignment(machine.initialState.context, {}).isLogin, false)
279
+ assert.equal(actions.login.assignment(machine.initialState.context, {}).isLogin, true)
280
+
281
+ assert.equal(
282
+ guards.isAffiliateCodeInstructionsEnable({}, { data: { siteConfig: { registerBindingAffiliateCodeInstructionsEnable: 'true' } } }),
283
+ true
284
+ )
285
+ assert.equal(guards.isAffiliateCodeInstructionsEnable({}, { data: { siteConfig: {} } }), false)
286
+ assert.equal(guards.isNotInGame({ isPlaying: false }), true)
287
+ assert.equal(delays.TIMEOUT({ tick: 3000 }), 30000)
288
+
289
+ const fetchedConfig = await services.fetchConfig({}, {})
290
+ assert.equal(fetchedConfig.siteConfig.loginMethods.phone, true)
291
+
292
+ const defaultAff = await services.fetchDefaultAffiliateCode({}, {})
293
+ assert.equal(defaultAff.affiliateCode, 'DA001')
294
+
295
+ const feedData = await services.fetchFeeds({}, {})
296
+ assert.equal(feedData.mailBoxInfo.rows, 10)
297
+
298
+ const ann = await services.fetchAnnouncements({}, {})
299
+ assert.equal(ann.data.length, 1)
300
+ assert.equal(
301
+ sent.some((entry) => entry.url === 'getConfig'),
302
+ true
303
+ )
304
+ })
@@ -0,0 +1,101 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import loadcardCashFactory from '../src/machine/deposit/loadcard_cash.js'
5
+
6
+ test('loadcard_cash actions/services cover init, promotion, card fields and submit mapping', async () => {
7
+ const sent = []
8
+ const request = {
9
+ send: async (req) => {
10
+ sent.push(req)
11
+ if (req.url === 'payment/v2/loadcard_cash/expected/result') return { data: { bonus: 12 } }
12
+ if (req.url === 'payment/v2/loadcard_cash/transaction') return { applyId: 808 }
13
+ return {}
14
+ },
15
+ }
16
+
17
+ const machine = loadcardCashFactory(request, {
18
+ paymentDetail: [
19
+ {
20
+ transferType: 'deposit',
21
+ category: 'loadcard',
22
+ method: 'loadcard_cash',
23
+ minimum: 50,
24
+ maximum: 5000,
25
+ channel_id: 'LC1',
26
+ optional: [100, 200],
27
+ },
28
+ {
29
+ transferType: 'deposit',
30
+ category: 'loadcard',
31
+ method: 'loadcard_cash_2',
32
+ minimum: 80,
33
+ maximum: 8000,
34
+ channel_id: 'LC2',
35
+ optional: [300],
36
+ },
37
+ ],
38
+ promotion: { promotionsNo: 'P1', minimumAmount: 120 },
39
+ selectedAmount: 10,
40
+ })
41
+
42
+ const { actions, services } = machine.options
43
+ const debounceCond = machine.config.states.debouncing.after[1000][0].cond
44
+
45
+ const init = actions.setInitData.assignment(machine.initialState.context, {})
46
+ assert.equal(init.loadcards.length, 2)
47
+ assert.equal(init.selectedLoadcard.method, 'loadcard_cash')
48
+ assert.equal(init.selectedAmount, 120)
49
+
50
+ const initNoMatch = actions.setInitData.assignment(
51
+ { paymentDetail: [{ category: 'other', transferType: 'deposit', minimum: 10 }], currentCategory: 'loadcard' },
52
+ {}
53
+ )
54
+ assert.equal(initNoMatch.selectedLoadcard, undefined)
55
+ assert.equal(initNoMatch.selectedAmount, 0)
56
+
57
+ const promo = actions.setPromotion.assignment({ ...init, selectedAmount: 30 }, { data: { promotionsNo: 'P2', minimumAmount: 300 } })
58
+ assert.equal(promo.selectedAmount, 300)
59
+ assert.equal(promo.calculation, null)
60
+
61
+ const setLoadcard = actions.setLoadcard.assignment(
62
+ { ...init, promotion: { minimumAmount: 200 }, selectedAmount: 100 },
63
+ { data: { method: 'loadcard_cash_2', optional: [300], channel_id: 'LC2' } }
64
+ )
65
+ assert.equal(setLoadcard.selectedLoadcard.method, 'loadcard_cash_2')
66
+ assert.equal(setLoadcard.selectedAmount, 200)
67
+
68
+ assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: 456 }).selectedAmount, 456)
69
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { x: 1 } } }).calculation, { x: 1 })
70
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { y: 2 } }).calculation, { y: 2 })
71
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
72
+ assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
73
+ assert.equal(actions.setCardNumber.assignment(machine.initialState.context, { data: 'CARD' }).cardNumber, 'CARD')
74
+ assert.equal(actions.setSerialNumber.assignment(machine.initialState.context, { data: 'SERIAL' }).serialNumber, 'SERIAL')
75
+ assert.equal(debounceCond({ selectedLoadcard: { minimum: 100, maximum: 500 }, selectedAmount: 200 }, {}), true)
76
+ assert.equal(debounceCond({ selectedLoadcard: null, selectedAmount: 100 }, {}), false)
77
+
78
+ const calc = await services.fetchCalculation(
79
+ { selectedLoadcard: { method: 'loadcard_cash' }, selectedAmount: 500, promotion: { promotionsNo: 'P3' } },
80
+ {}
81
+ )
82
+ assert.equal(calc.data.bonus, 12)
83
+
84
+ const submitted = await services.submitDeposit(
85
+ {
86
+ selectedLoadcard: { method: 'loadcard_cash', channel_id: 'LC1' },
87
+ selectedAmount: 700,
88
+ promotion: { promotionsNo: 'P4' },
89
+ cardNumber: 'CARD123',
90
+ serialNumber: 'SERIAL123',
91
+ },
92
+ {}
93
+ )
94
+ assert.equal(submitted.applyId, 808)
95
+
96
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/loadcard_cash/transaction')
97
+ assert.equal(submitReq.params.card_type, 'LC1')
98
+ assert.equal(submitReq.params.card_code, 'CARD123')
99
+ assert.equal(submitReq.params.card_seri, 'SERIAL123')
100
+ assert.equal(submitReq.params.promotionsNo, 'P4')
101
+ })