@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.
- package/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +36 -0
- package/package.json +5 -2
- package/resetGitBranch.sh +16 -16
- package/src/api/account.js +8 -0
- package/src/api/auth.js +1 -1
- package/src/api/common.js +6 -1
- package/src/api/index.js +3 -1
- package/src/api/otp.js +5 -0
- package/src/api/user.js +1 -0
- package/src/machine/activity/activity.js +23 -19
- package/src/machine/activity/activity_cash.js +27 -22
- package/src/machine/activity/cash_rain_activity.js +1 -0
- package/src/machine/activity/continue_deposit_activity.js +1 -0
- package/src/machine/activity/deposit_activity.js +1 -0
- package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
- package/src/machine/activity/fafafa_activity.js +1 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +1 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +1 -0
- package/src/machine/activity/otp_verified_activity.js +1 -0
- package/src/machine/activity/ranking_activity.js +1 -0
- package/src/machine/activity/return_bonus_activity.js +3 -1
- package/src/machine/activity/roulette_activity_v2.js +6 -0
- package/src/machine/activity/sign_in_activity.js +1 -0
- package/src/machine/activity/sign_in_monthly_activity.js +2 -1
- package/src/machine/activity/specify_bets_activity.js +1 -0
- package/src/machine/activity/specify_turnover_activity.js +1 -0
- package/src/machine/activity/time_bomb_activity.js +1 -0
- package/src/machine/activity/vip_card_activity.js +1 -0
- package/src/machine/auth.js +21 -8
- package/src/machine/auth_otp_v2.js +1 -0
- package/src/machine/auth_otp_v3.js +48 -11
- package/src/machine/bank_binding.js +1 -0
- package/src/machine/bank_binding_amb.js +1 -0
- package/src/machine/bonus.js +1 -0
- package/src/machine/common.js +41 -7
- package/src/machine/deposit/amb.js +1 -0
- package/src/machine/deposit/crypto_bank.js +20 -5
- package/src/machine/deposit/crypto_bank_cash.js +35 -9
- package/src/machine/deposit/crypto_qrcode.js +11 -1
- package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
- package/src/machine/deposit/crypto_way.js +11 -5
- package/src/machine/deposit/crypto_way_cash.js +15 -6
- package/src/machine/deposit/deposit_fc.js +1 -0
- package/src/machine/deposit/direct.js +1 -0
- package/src/machine/deposit/direct_cash.js +1 -0
- package/src/machine/deposit/float.js +1 -0
- package/src/machine/deposit/krway.js +1 -0
- package/src/machine/deposit/loadcard_cash.js +2 -1
- package/src/machine/deposit/loadcard_vn.js +1 -0
- package/src/machine/deposit/manual_cash.js +18 -10
- package/src/machine/deposit/manual_vn.js +10 -5
- package/src/machine/deposit/qrcode_cash.js +6 -5
- package/src/machine/deposit/qrcode_v2.js +1 -0
- package/src/machine/deposit/usdt.js +23 -4
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +11 -9
- package/src/machine/deposit/virtual_bank_vn.js +1 -0
- package/src/machine/deposit/vpay.js +7 -0
- package/src/machine/error.js +1 -0
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +14 -2
- package/src/machine/game_info.js +5 -0
- package/src/machine/game_replay.js +1 -0
- package/src/machine/game_search_cash.js +13 -2
- package/src/machine/game_search_v2.js +1 -0
- package/src/machine/game_v2_1.js +129 -50
- package/src/machine/honor_board.js +19 -7
- package/src/machine/honor_board_cash.js +11 -8
- package/src/machine/inbox.js +93 -43
- package/src/machine/leaderboard.js +1 -0
- package/src/machine/merge.js +1 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +1 -0
- package/src/machine/promotions.js +11 -18
- package/src/machine/ranking.js +5 -2
- package/src/machine/reward.js +1 -0
- package/src/machine/reward_cash.js +1 -0
- package/src/machine/reward_fc.js +1 -0
- package/src/machine/roulette_v2.js +18 -26
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +10 -4
- package/src/machine/side_cash.js +1 -0
- package/src/machine/side_v2.js +38 -24
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +5 -2
- package/src/machine/user_sign_up.js +1 -0
- package/src/machine/vip_table.js +1 -0
- package/src/machine/websocket.js +42 -14
- package/src/machine/welcome.js +1 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
- package/src/machine/withdraw/withdraw_krway.js +1 -0
- package/src/machine/withdraw/withdraw_manual.js +16 -8
- package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
- package/src/request/request.js +34 -30
- package/src/util/deviceToken.js +7 -6
- package/src/util/storage.js +4 -3
- package/test/api.behavior.test.js +69 -0
- package/test/api.contract.test.js +18 -0
- package/test/config.test.js +27 -0
- package/test/deviceToken.test.js +139 -0
- package/test/helpers.coverage.test.js +11 -0
- package/test/helpers.js +91 -0
- package/test/index.exports.test.js +14 -0
- package/test/machine.activity.core.coverage.test.js +337 -0
- package/test/machine.activity.gap.coverage.test.js +252 -0
- package/test/machine.activity.more.coverage.test.js +180 -0
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
- package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
- package/test/machine.activity_welcome.low.coverage.test.js +211 -0
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
- package/test/machine.auth.coverage.test.js +215 -0
- package/test/machine.bank_binding.test.js +143 -0
- package/test/machine.binding_otp_krway.coverage.test.js +223 -0
- package/test/machine.contract.test.js +50 -0
- package/test/machine.crypto_bank.coverage.test.js +270 -0
- package/test/machine.crypto_way.coverage.test.js +108 -0
- package/test/machine.crypto_way_cash.coverage.test.js +114 -0
- package/test/machine.definition.test.js +137 -0
- package/test/machine.deposit.manual.coverage.test.js +365 -0
- package/test/machine.deposit_fc.coverage.test.js +126 -0
- package/test/machine.direct.coverage.test.js +96 -0
- package/test/machine.direct_cash.coverage.test.js +108 -0
- package/test/machine.error.coverage.test.js +37 -0
- package/test/machine.events.test.js +126 -0
- package/test/machine.favorite_jackpot.coverage.test.js +82 -0
- package/test/machine.float.coverage.test.js +136 -0
- package/test/machine.flow.test.js +226 -0
- package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
- package/test/machine.game_search_cash.coverage.test.js +195 -0
- package/test/machine.game_search_v2.test.js +199 -0
- package/test/machine.game_user_profile.coverage.test.js +100 -0
- package/test/machine.honor_board.test.js +148 -0
- package/test/machine.inbox.common.coverage.test.js +304 -0
- package/test/machine.loadcard_cash.coverage.test.js +101 -0
- package/test/machine.loadcard_vn.coverage.test.js +122 -0
- package/test/machine.misc.coverage.test.js +361 -0
- package/test/machine.more2.coverage.test.js +261 -0
- package/test/machine.options.execution.test.js +272 -0
- package/test/machine.priority.coverage.test.js +629 -0
- package/test/machine.qrcode_cash.coverage.test.js +107 -0
- package/test/machine.qrcode_v2.coverage.test.js +121 -0
- package/test/machine.regression.test.js +82 -0
- package/test/machine.roulette_v2.test.js +142 -0
- package/test/machine.side_reward_reset.coverage.test.js +220 -0
- package/test/machine.targeted.coverage.test.js +313 -0
- package/test/machine.usdt.coverage.test.js +95 -0
- package/test/machine.usdt_cash.coverage.test.js +73 -0
- package/test/machine.vip_card_activity.test.js +114 -0
- package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
- package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
- package/test/machine.vpay.coverage.test.js +142 -0
- package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
- package/test/machine.withdraw_krway.coverage.test.js +123 -0
- package/test/machine.withdraw_manual.coverage.test.js +185 -0
- package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
- package/test/request.test.js +325 -0
- package/test/util.storage.errors.test.js +47 -0
- package/test/util.test.js +41 -0
|
@@ -0,0 +1,313 @@
|
|
|
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 websocketFactory from '../src/machine/websocket.js'
|
|
6
|
+
import sideV2Factory from '../src/machine/side_v2.js'
|
|
7
|
+
import storage from '../src/util/storage.js'
|
|
8
|
+
import { createLocalStorageMock } from './helpers.js'
|
|
9
|
+
|
|
10
|
+
test('user_sign_up: actions and authenticate service build registration payload', async () => {
|
|
11
|
+
global.localStorage = createLocalStorageMock()
|
|
12
|
+
global.window = { location: { href: 'https://example.com/register' } }
|
|
13
|
+
|
|
14
|
+
storage.set('ac', 'AFF_FROM_STORAGE')
|
|
15
|
+
storage.set('channel', 'channel_storage')
|
|
16
|
+
storage.set('subchannel', 'sub_storage')
|
|
17
|
+
|
|
18
|
+
const messages = []
|
|
19
|
+
let sentReq = null
|
|
20
|
+
const request = {
|
|
21
|
+
config: {
|
|
22
|
+
fpToken: 'fp-token',
|
|
23
|
+
sentry: { captureMessage: (msg) => messages.push(msg), captureException: () => {}, setTag: () => {} },
|
|
24
|
+
defaultChannel: 'default_channel',
|
|
25
|
+
defaultSubchannel: 'default_subchannel',
|
|
26
|
+
},
|
|
27
|
+
hosts: [],
|
|
28
|
+
send: async (req) => {
|
|
29
|
+
sentReq = req
|
|
30
|
+
return { data: { account: 'u1', currency: 'THB', site: 'S', strategy: 'normal', uid: 'uid' } }
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const machine = userSignUpFactory(request)
|
|
35
|
+
const setSignUpId = machine.options.actions.setSignUpId.assignment
|
|
36
|
+
const setRegistrationData = machine.options.actions.setRegistrationData.assignment
|
|
37
|
+
const authenticate = machine.options.services.authenticate
|
|
38
|
+
|
|
39
|
+
const signUpCtxPatch = setSignUpId(machine.initialState.context, {
|
|
40
|
+
data: {
|
|
41
|
+
email: 'a@example.com',
|
|
42
|
+
username: 'alice',
|
|
43
|
+
nick_name: 'Alice',
|
|
44
|
+
password: 'pw',
|
|
45
|
+
countryCode: '66',
|
|
46
|
+
phone: '0800000000',
|
|
47
|
+
channel: 'event_channel',
|
|
48
|
+
subchannel: 'event_sub',
|
|
49
|
+
affiliateCode: 'AFF_EVENT',
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
assert.equal(signUpCtxPatch.signUpData.provider, 'local')
|
|
54
|
+
assert.equal(signUpCtxPatch.channel, 'event_channel')
|
|
55
|
+
|
|
56
|
+
const authResult = await authenticate(
|
|
57
|
+
{
|
|
58
|
+
...machine.initialState.context,
|
|
59
|
+
...signUpCtxPatch,
|
|
60
|
+
reCaptchaToken: 'captcha',
|
|
61
|
+
fc: 'FC01',
|
|
62
|
+
deviceTokenEnable: false,
|
|
63
|
+
},
|
|
64
|
+
{}
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assert.ok(sentReq)
|
|
68
|
+
assert.equal(authResult.data.account, 'u1')
|
|
69
|
+
assert.equal(messages.length > 0, true)
|
|
70
|
+
assert.equal(sentReq.url.includes('ac=AFF_FROM_STORAGE'), true)
|
|
71
|
+
assert.equal(sentReq.url.includes('channel=channel_storage'), true)
|
|
72
|
+
assert.equal(sentReq.url.includes('subchannel=sub_storage'), true)
|
|
73
|
+
assert.equal(sentReq.url.includes('fc=FC01'), true)
|
|
74
|
+
|
|
75
|
+
const registration = setRegistrationData(machine.initialState.context, {
|
|
76
|
+
data: {
|
|
77
|
+
account: 'u2',
|
|
78
|
+
currency: 'USD',
|
|
79
|
+
site: 'site',
|
|
80
|
+
strategy: 'x',
|
|
81
|
+
uid: 'uid2',
|
|
82
|
+
channel: 'c',
|
|
83
|
+
sub_channel: 'sc',
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
assert.equal(registration.registrationData.account, 'u2')
|
|
87
|
+
assert.equal(registration.registrationData.sub_channel, 'sc')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('websocket: actions/guards/services work with mocked socket and fetch', async () => {
|
|
91
|
+
const pushed = []
|
|
92
|
+
const sentryErrors = []
|
|
93
|
+
const request = {
|
|
94
|
+
config: {
|
|
95
|
+
socketURL: 'https://socket.example.com',
|
|
96
|
+
bucketName: 'bucket',
|
|
97
|
+
clientId: 'client',
|
|
98
|
+
sentry: { captureException: (e) => sentryErrors.push(e) },
|
|
99
|
+
},
|
|
100
|
+
getToken: () => 'token',
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const machine = websocketFactory(request)
|
|
104
|
+
|
|
105
|
+
const setSocket = machine.options.actions.setSocket.assignment
|
|
106
|
+
const setConnectError = machine.options.actions.setConnectError.assignment
|
|
107
|
+
const setDisconnected = machine.options.actions.setDisconnected.assignment
|
|
108
|
+
const pushEvent = machine.options.actions.pushEvent.assignment
|
|
109
|
+
const setReconnectCount = machine.options.actions.setReconnectCount.assignment
|
|
110
|
+
const isNeedConnect = machine.options.guards.isNeedConnect
|
|
111
|
+
const isReconnect = machine.options.guards.isReconnect
|
|
112
|
+
|
|
113
|
+
const connected = setSocket(machine.initialState.context, { data: { id: 'socket-1' } })
|
|
114
|
+
assert.equal(connected.connectStatus, 2)
|
|
115
|
+
|
|
116
|
+
const connectErr = setConnectError(
|
|
117
|
+
{ ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) }, connectError: null },
|
|
118
|
+
{ data: 'io server disconnect' }
|
|
119
|
+
)
|
|
120
|
+
assert.equal(connectErr.connectStatus, 0)
|
|
121
|
+
assert.equal(sentryErrors.length > 0, true)
|
|
122
|
+
|
|
123
|
+
setDisconnected({ ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) } }, { reason: 'transport error' })
|
|
124
|
+
|
|
125
|
+
pushEvent(
|
|
126
|
+
{ ...machine.initialState.context, analytics: { push: (data) => pushed.push(data) } },
|
|
127
|
+
{
|
|
128
|
+
data: {
|
|
129
|
+
event: 'purchase',
|
|
130
|
+
isTracking: true,
|
|
131
|
+
data: { paymentMethod: 'bank', transactionId: 'tx1', currency: 'THB', value: 100, isFirst: true },
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const recon = setReconnectCount({ ...machine.initialState.context, reconnectCount: 1 }, {})
|
|
137
|
+
assert.equal(recon.reconnectCount, 2)
|
|
138
|
+
assert.equal(isNeedConnect({ connectStatus: 1, clientSocket: null }, {}), false)
|
|
139
|
+
assert.equal(isNeedConnect({ connectStatus: 0, clientSocket: { connected: true } }, {}), false)
|
|
140
|
+
assert.equal(isNeedConnect({ connectStatus: 0, clientSocket: null }, {}), true)
|
|
141
|
+
assert.equal(isReconnect({ reconnectCount: 1, connectError: 'io server disconnect' }, {}), true)
|
|
142
|
+
assert.equal(isReconnect({ reconnectCount: 3, connectError: 'io server disconnect' }, {}), false)
|
|
143
|
+
|
|
144
|
+
const originalFetch = global.fetch
|
|
145
|
+
global.fetch = async (url) => {
|
|
146
|
+
if (String(url).endsWith('target.json')) {
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
json: async () => ({ socket: ['https://a.example.com', 'https://b.example.com'] }),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
ok: true,
|
|
154
|
+
json: async () => ({}),
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const fetchSocket = machine.options.services.fetchSocket
|
|
158
|
+
const socketRes = await fetchSocket({ url: 'https://storage.googleapis.com/x/target.json' }, {})
|
|
159
|
+
assert.ok(socketRes.socketURL)
|
|
160
|
+
|
|
161
|
+
const callbacks = []
|
|
162
|
+
const handlers = {}
|
|
163
|
+
const fakeSocket = {
|
|
164
|
+
on: (event, fn) => {
|
|
165
|
+
handlers[event] = fn
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
const listen = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocket })
|
|
169
|
+
listen((event) => callbacks.push(event))
|
|
170
|
+
handlers['activity-info']?.({ id: 1 })
|
|
171
|
+
handlers['payment-info']?.({ windowType: 'toast', id: 2 })
|
|
172
|
+
handlers['connect']?.()
|
|
173
|
+
handlers['connect_error']?.({ message: 'x' })
|
|
174
|
+
handlers['disconnect']?.('io server disconnect')
|
|
175
|
+
assert.equal(callbacks.length > 0, true)
|
|
176
|
+
global.fetch = originalFetch
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('side_v2: menu actions/guards/services handle nested menu flow', async () => {
|
|
180
|
+
const menu = {
|
|
181
|
+
timestamp: 1,
|
|
182
|
+
data: [
|
|
183
|
+
{
|
|
184
|
+
categoryId: 1,
|
|
185
|
+
isGame: false,
|
|
186
|
+
sub: [{ categoryId: 11, isGame: false, sub: [{ categoryId: 111, isGame: true, sub: [] }] }],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let lastReq = null
|
|
192
|
+
const request = {
|
|
193
|
+
config: { appSecret: 'secret' },
|
|
194
|
+
send: async (req) => {
|
|
195
|
+
lastReq = req
|
|
196
|
+
return menu
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const machine = sideV2Factory(request)
|
|
201
|
+
const setMenu = machine.options.actions.setMenu.assignment
|
|
202
|
+
const setDefaultMenuItemStack = machine.options.actions.setDefaultMenuItemStack.assignment
|
|
203
|
+
const setMenuItemStack = machine.options.actions.setMenuItemStack.assignment
|
|
204
|
+
const restoreMenuItemStack = machine.options.actions.restoreMenuItemStack.assignment
|
|
205
|
+
const pushHistoryStack = machine.options.actions.pushHistoryStack.assignment
|
|
206
|
+
const popHistoryStack = machine.options.actions.popHistoryStack.assignment
|
|
207
|
+
const resetMenuItemStack = machine.options.actions.resetMenuItemStack.assignment
|
|
208
|
+
const resetHistoryStack = machine.options.actions.resetHistoryStack.assignment
|
|
209
|
+
const updateMenu = machine.options.actions.updateMenu.assignment
|
|
210
|
+
const isInMenu = machine.options.guards.isInMenu
|
|
211
|
+
|
|
212
|
+
const patch1 = setMenu(machine.initialState.context, { data: menu })
|
|
213
|
+
assert.equal(patch1.menu.data[0].level, 0)
|
|
214
|
+
const patchNoArray = setMenu(machine.initialState.context, { data: { timestamp: 2, data: null } })
|
|
215
|
+
assert.equal(patchNoArray.menu.timestamp, 2)
|
|
216
|
+
|
|
217
|
+
const patch2 = setDefaultMenuItemStack(machine.initialState.context, { data: menu })
|
|
218
|
+
assert.equal(Array.isArray(patch2.menuItemStack), true)
|
|
219
|
+
assert.equal(patch2.menuItemStack.length > 0, true)
|
|
220
|
+
|
|
221
|
+
const baseCtx = {
|
|
222
|
+
...machine.initialState.context,
|
|
223
|
+
...patch1,
|
|
224
|
+
...patch2,
|
|
225
|
+
historyStack: [],
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const selectedTop = setMenuItemStack(baseCtx, { data: menu.data[0] })
|
|
229
|
+
assert.equal(selectedTop.menuItemStack.length > 0, true)
|
|
230
|
+
const selectedTopNoSub = setMenuItemStack(baseCtx, { data: { categoryId: 2, level: 0, sub: [] } })
|
|
231
|
+
assert.equal(selectedTopNoSub.historyStack.length, 0)
|
|
232
|
+
const selectedNonTop = setMenuItemStack({ ...baseCtx, menuItemStack: [menu.data[0], menu.data[0].sub[0]] }, { data: { categoryId: 999, level: 1 } })
|
|
233
|
+
assert.equal(selectedNonTop.menuItemStack.length, 2)
|
|
234
|
+
|
|
235
|
+
const restored = restoreMenuItemStack({ ...baseCtx, previousMenuItemStack: [menu.data[0]] }, {})
|
|
236
|
+
assert.equal(restored.menuItemStack.length, 1)
|
|
237
|
+
|
|
238
|
+
const pushedStack = pushHistoryStack(baseCtx, { data: { name: 'x' } })
|
|
239
|
+
assert.equal(pushedStack.historyStack.length, 1)
|
|
240
|
+
const poppedStack = popHistoryStack({ ...baseCtx, historyStack: [{ name: 'x' }] }, {})
|
|
241
|
+
assert.equal(poppedStack.historyStack.length, 0)
|
|
242
|
+
|
|
243
|
+
const resetMenu = resetMenuItemStack({ ...baseCtx, defaultMenuItemStack: [menu.data[0]] }, {})
|
|
244
|
+
assert.equal(resetMenu.menuItemStack.length, 1)
|
|
245
|
+
const resetHistory = resetHistoryStack(baseCtx, {})
|
|
246
|
+
assert.deepEqual(resetHistory.historyStack, [])
|
|
247
|
+
|
|
248
|
+
const updated = updateMenu(baseCtx, { data: menu })
|
|
249
|
+
assert.equal(updated.defaultMenuItemStack.length > 0, true)
|
|
250
|
+
assert.equal(updateMenu(baseCtx, { data: { data: [] } }), undefined)
|
|
251
|
+
|
|
252
|
+
assert.equal(isInMenu({ ...baseCtx, menuItemStack: [menu.data[0]] }, {}), true)
|
|
253
|
+
assert.equal(
|
|
254
|
+
isInMenu({
|
|
255
|
+
...baseCtx,
|
|
256
|
+
menu: { ...menu, data: [menu.data[0], { categoryId: 2, isGame: true, sub: [] }] },
|
|
257
|
+
menuItemStack: [menu.data[0]],
|
|
258
|
+
}),
|
|
259
|
+
true
|
|
260
|
+
)
|
|
261
|
+
assert.equal(
|
|
262
|
+
isInMenu({
|
|
263
|
+
...baseCtx,
|
|
264
|
+
menuItemStack: [{ categoryId: 99999 }],
|
|
265
|
+
}),
|
|
266
|
+
false
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
const getMenu = machine.options.services.getMenu
|
|
270
|
+
const fetchUpdateMenu = machine.options.services.fetchUpdateMenu
|
|
271
|
+
await getMenu(baseCtx, {})
|
|
272
|
+
assert.ok(lastReq)
|
|
273
|
+
await fetchUpdateMenu({ ...baseCtx, menu: { timestamp: 99 } }, {})
|
|
274
|
+
assert.ok(lastReq)
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('side_v2: deep nested menu processing stays stable', () => {
|
|
278
|
+
const depth = 12000
|
|
279
|
+
const root = { categoryId: 1, isGame: false, sub: [] }
|
|
280
|
+
let cursor = root
|
|
281
|
+
for (let i = 2; i <= depth; i++) {
|
|
282
|
+
const next = { categoryId: i, isGame: false, sub: [] }
|
|
283
|
+
cursor.sub = [next]
|
|
284
|
+
cursor = next
|
|
285
|
+
}
|
|
286
|
+
// terminal node is game-like leaf in real menu trees
|
|
287
|
+
cursor.isGame = true
|
|
288
|
+
|
|
289
|
+
const request = {
|
|
290
|
+
config: { appSecret: 'secret' },
|
|
291
|
+
send: async () => ({ data: [root] }),
|
|
292
|
+
}
|
|
293
|
+
const machine = sideV2Factory(request)
|
|
294
|
+
const actions = machine.options.actions
|
|
295
|
+
const isInMenu = machine.options.guards.isInMenu
|
|
296
|
+
const ctx = machine.initialState.context
|
|
297
|
+
const menu = { timestamp: 1, data: [root] }
|
|
298
|
+
|
|
299
|
+
const patchedMenu = actions.setMenu.assignment(ctx, { data: menu })
|
|
300
|
+
const patchedDefaultStack = actions.setDefaultMenuItemStack.assignment(ctx, { data: menu })
|
|
301
|
+
assert.equal(patchedMenu.menu.data[0].level, 0)
|
|
302
|
+
assert.equal(patchedDefaultStack.menuItemStack.length, depth)
|
|
303
|
+
|
|
304
|
+
const inMenu = isInMenu(
|
|
305
|
+
{
|
|
306
|
+
...ctx,
|
|
307
|
+
menu: patchedMenu.menu,
|
|
308
|
+
menuItemStack: [{ categoryId: depth }],
|
|
309
|
+
},
|
|
310
|
+
{}
|
|
311
|
+
)
|
|
312
|
+
assert.equal(inMenu, true)
|
|
313
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import usdtFactory from '../src/machine/deposit/usdt.js'
|
|
5
|
+
|
|
6
|
+
test('usdt actions/guards/services cover payment setup, cache and submit error path', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
send: async (req) => {
|
|
10
|
+
sent.push(req)
|
|
11
|
+
if (req.url === 'payment/v2/paymentDetail') {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
category: 'usdt',
|
|
15
|
+
method: 'usdt',
|
|
16
|
+
channel: 'USDT',
|
|
17
|
+
networkName: ['TRC20', 'ERC20'],
|
|
18
|
+
networkOptional: ['TRON', 'ETH'],
|
|
19
|
+
},
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
if (req.url === 'payment/v2/usdt/transaction') {
|
|
23
|
+
return {
|
|
24
|
+
action: 'pay',
|
|
25
|
+
cdtime: 60,
|
|
26
|
+
accountNumber: 'ADDR',
|
|
27
|
+
currency: 'USDT',
|
|
28
|
+
network: 'TRC20',
|
|
29
|
+
name: 'USDT',
|
|
30
|
+
qrcode: 'QR',
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const machine = usdtFactory(request)
|
|
38
|
+
const { actions, guards, services } = machine.options
|
|
39
|
+
|
|
40
|
+
const setPayment = actions.setPayment.assignment(machine.initialState.context, {
|
|
41
|
+
data: [
|
|
42
|
+
{
|
|
43
|
+
category: 'usdt',
|
|
44
|
+
method: 'usdt',
|
|
45
|
+
channel: 'USDT',
|
|
46
|
+
networkName: ['TRC20', 'ERC20'],
|
|
47
|
+
networkOptional: ['TRON', 'ETH'],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
})
|
|
51
|
+
assert.equal(setPayment.currentPayment.method, 'usdt')
|
|
52
|
+
assert.equal(setPayment.networks.length, 2)
|
|
53
|
+
assert.equal(setPayment.selectedNetwork.value, 'TRC20')
|
|
54
|
+
|
|
55
|
+
const setPaymentNoMatch = actions.setPayment.assignment(machine.initialState.context, { data: [{ category: 'other' }] })
|
|
56
|
+
assert.equal(setPaymentNoMatch.currentPayment, null)
|
|
57
|
+
assert.deepEqual(setPaymentNoMatch.networks, [])
|
|
58
|
+
|
|
59
|
+
const setPaymentInvalidNetwork = actions.setPayment.assignment(machine.initialState.context, {
|
|
60
|
+
data: [{ category: 'usdt', method: 'usdt', channel: 'USDT', networkName: null }],
|
|
61
|
+
})
|
|
62
|
+
assert.deepEqual(setPaymentInvalidNetwork.networks, [])
|
|
63
|
+
assert.equal(setPaymentInvalidNetwork.selectedNetwork, null)
|
|
64
|
+
|
|
65
|
+
assert.equal(actions.setNetwork.assignment(machine.initialState.context, { data: { value: 'ERC20' } }).selectedNetwork.value, 'ERC20')
|
|
66
|
+
assert.deepEqual(actions.setResultFromLocal.assignment({ resultMap: {}, selectedNetwork: null }, {}), {})
|
|
67
|
+
assert.equal(actions.setResultFromLocal.assignment({ resultMap: { TRC20: { hit: 1 } }, selectedNetwork: { value: 'TRC20' } }, {}).result.hit, 1)
|
|
68
|
+
|
|
69
|
+
const result = actions.setResult.assignment(
|
|
70
|
+
{ resultMap: {}, selectedNetwork: { value: 'TRC20' } },
|
|
71
|
+
{ data: { action: 'pay', cdtime: 60, accountNumber: 'A', currency: 'USDT', network: 'TRC20', name: 'N', qrcode: 'Q' } }
|
|
72
|
+
)
|
|
73
|
+
assert.equal(result.resultMap.TRC20.currency, 'USDT')
|
|
74
|
+
|
|
75
|
+
assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: null }), false)
|
|
76
|
+
assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: { value: 'TRC20' } }), undefined)
|
|
77
|
+
assert.deepEqual(guards.isFound({ resultMap: { TRC20: { ok: 1 } }, selectedNetwork: { value: 'TRC20' } }), { ok: 1 })
|
|
78
|
+
|
|
79
|
+
const payments = await services.fetchPayments({}, {})
|
|
80
|
+
assert.equal(Array.isArray(payments), true)
|
|
81
|
+
|
|
82
|
+
await assert.rejects(
|
|
83
|
+
async () => {
|
|
84
|
+
await services.submitDeposit({ currentPayment: null, selectedNetwork: null }, {})
|
|
85
|
+
},
|
|
86
|
+
(error) => error && error.code === 'ERR_INVALID_USDT_NETWORK'
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const submitted = await services.submitDeposit({ currentPayment: { method: 'usdt', channel: 'USDT' }, selectedNetwork: { value: 'TRC20' } }, {})
|
|
90
|
+
assert.equal(submitted.currency, 'USDT')
|
|
91
|
+
|
|
92
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/usdt/transaction')
|
|
93
|
+
assert.equal(submitReq.params.cryptoCurrency, 'USDT')
|
|
94
|
+
assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
|
|
95
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import usdtCashFactory from '../src/machine/deposit/usdt_cash.js'
|
|
5
|
+
|
|
6
|
+
test('usdt_cash actions/guards/services cover network cache and submit mapping', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
send: async (req) => {
|
|
10
|
+
sent.push(req)
|
|
11
|
+
if (req.url === 'payment/v2/usdt_cash/transaction') {
|
|
12
|
+
return {
|
|
13
|
+
action: 'pay',
|
|
14
|
+
cdtime: 60,
|
|
15
|
+
accountNumber: 'ADDR',
|
|
16
|
+
currency: 'USDT',
|
|
17
|
+
network: 'TRC20',
|
|
18
|
+
name: 'USDT',
|
|
19
|
+
qrcode: 'QR',
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {}
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const machine = usdtCashFactory(request, {
|
|
27
|
+
paymentDetail: [
|
|
28
|
+
{
|
|
29
|
+
transferType: 'deposit',
|
|
30
|
+
category: 'usdt',
|
|
31
|
+
method: 'usdt_cash',
|
|
32
|
+
channel: 'USDT',
|
|
33
|
+
networkName: ['TRC20', 'ERC20'],
|
|
34
|
+
networkOptional: ['TRON', 'ETH'],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const { actions, guards, services } = machine.options
|
|
40
|
+
|
|
41
|
+
const setPayment = actions.setPayment.assignment(machine.initialState.context, {})
|
|
42
|
+
assert.equal(setPayment.currentPayment.method, 'usdt_cash')
|
|
43
|
+
assert.equal(setPayment.networks.length, 2)
|
|
44
|
+
assert.equal(setPayment.selectedNetwork.value, 'TRC20')
|
|
45
|
+
|
|
46
|
+
assert.equal(actions.setNetwork.assignment(machine.initialState.context, { data: { value: 'ERC20' } }).selectedNetwork.value, 'ERC20')
|
|
47
|
+
|
|
48
|
+
assert.deepEqual(actions.setResultFromLocal.assignment({ resultMap: {}, selectedNetwork: null }, {}), {})
|
|
49
|
+
assert.equal(actions.setResultFromLocal.assignment({ resultMap: { TRC20: { hit: 1 } }, selectedNetwork: { value: 'TRC20' } }, {}).result.hit, 1)
|
|
50
|
+
|
|
51
|
+
const setResult = actions.setResult.assignment(
|
|
52
|
+
{ resultMap: {}, selectedNetwork: { value: 'TRC20' } },
|
|
53
|
+
{ data: { action: 'pay', cdtime: 60, accountNumber: 'ADDR', currency: 'USDT', network: 'TRC20', name: 'USDT', qrcode: 'QR' } }
|
|
54
|
+
)
|
|
55
|
+
assert.equal(setResult.resultMap.TRC20.currency, 'USDT')
|
|
56
|
+
|
|
57
|
+
assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: null }), false)
|
|
58
|
+
assert.equal(guards.isFound({ resultMap: {}, selectedNetwork: { value: 'TRC20' } }), undefined)
|
|
59
|
+
assert.deepEqual(guards.isFound({ resultMap: { TRC20: { ok: 1 } }, selectedNetwork: { value: 'TRC20' } }), { ok: 1 })
|
|
60
|
+
|
|
61
|
+
const submit = await services.submitDeposit(
|
|
62
|
+
{
|
|
63
|
+
currentPayment: { method: 'usdt_cash', channel: 'USDT' },
|
|
64
|
+
selectedNetwork: { value: 'TRC20' },
|
|
65
|
+
},
|
|
66
|
+
{}
|
|
67
|
+
)
|
|
68
|
+
assert.equal(submit.currency, 'USDT')
|
|
69
|
+
|
|
70
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/usdt_cash/transaction')
|
|
71
|
+
assert.equal(submitReq.params.cryptoCurrency, 'USDT')
|
|
72
|
+
assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
|
|
73
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import vipCardActivityFactory from '../src/machine/activity/vip_card_activity.js'
|
|
5
|
+
|
|
6
|
+
test('vip_card_activity actions/services cover level, period and award branches', async () => {
|
|
7
|
+
const calls = []
|
|
8
|
+
const request = {
|
|
9
|
+
config: { appSecret: 'secret' },
|
|
10
|
+
send: async (req) => {
|
|
11
|
+
calls.push(req)
|
|
12
|
+
return {
|
|
13
|
+
data: {
|
|
14
|
+
activityNo: 'A1',
|
|
15
|
+
status: 'ok',
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
const machine = vipCardActivityFactory(request)
|
|
21
|
+
const actions = machine.options.actions
|
|
22
|
+
const services = machine.options.services
|
|
23
|
+
|
|
24
|
+
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A1' }).activityNo, 'A1')
|
|
25
|
+
|
|
26
|
+
const detailPatch = actions.setActivityDetail.assignment({ ...machine.initialState.context, activityDetail: { keep: true } }, { data: {} })
|
|
27
|
+
assert.deepEqual(detailPatch.activityDetail, { keep: true })
|
|
28
|
+
|
|
29
|
+
const setActivity = actions.setActivity.assignment(machine.initialState.context, {
|
|
30
|
+
data: { activityNo: 'A2', activityDetail: { x: 1 } },
|
|
31
|
+
})
|
|
32
|
+
assert.equal(setActivity.activityNo, 'A2')
|
|
33
|
+
assert.deepEqual(setActivity.activityDetail, { x: 1 })
|
|
34
|
+
|
|
35
|
+
const now = Math.floor(Date.now() / 1000)
|
|
36
|
+
const initAtMax = actions.setInitData.assignment(
|
|
37
|
+
{
|
|
38
|
+
...machine.initialState.context,
|
|
39
|
+
activityDetail: {
|
|
40
|
+
rebateType: 'R',
|
|
41
|
+
conditions: [
|
|
42
|
+
{ title: 'L1', depositLimit: '10', turnoverLimit: '20' },
|
|
43
|
+
{ title: 'L2', depositLimit: '30', turnoverLimit: '40' },
|
|
44
|
+
],
|
|
45
|
+
nextCycleCardCurrentReachLevel: { title: 'L2' },
|
|
46
|
+
nextCycleCardNextReachLevel: { title: 'L3', depositLimit: '50', turnoverLimit: '60' },
|
|
47
|
+
lastCycleCard: { title: 'L1' },
|
|
48
|
+
accumulateStartTime: now - 10,
|
|
49
|
+
accumulateEndTime: now + 10,
|
|
50
|
+
lastCycleCardStartTime: now - 5,
|
|
51
|
+
lastCycleCardEndTime: now + 5,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{}
|
|
55
|
+
)
|
|
56
|
+
assert.equal(initAtMax.nextDepositLimit, '30')
|
|
57
|
+
assert.equal(initAtMax.nextTurnoverLimit, '40')
|
|
58
|
+
assert.equal(initAtMax.isAccumulationPeriod, true)
|
|
59
|
+
assert.equal(initAtMax.isAwardPeriod, true)
|
|
60
|
+
|
|
61
|
+
const initAtNext = actions.setInitData.assignment(
|
|
62
|
+
{
|
|
63
|
+
...machine.initialState.context,
|
|
64
|
+
activityDetail: {
|
|
65
|
+
conditions: [{ title: 'L1', depositLimit: '10', turnoverLimit: '20' }],
|
|
66
|
+
nextCycleCardCurrentReachLevel: { title: 'L0' },
|
|
67
|
+
nextCycleCardNextReachLevel: { title: 'L1', depositLimit: '10', turnoverLimit: '20' },
|
|
68
|
+
accumulateStartTime: now + 100,
|
|
69
|
+
accumulateEndTime: now + 200,
|
|
70
|
+
lastCycleCardStartTime: now + 300,
|
|
71
|
+
lastCycleCardEndTime: now + 400,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
)
|
|
76
|
+
assert.equal(initAtNext.nextDepositLimit, '10')
|
|
77
|
+
assert.equal(initAtNext.nextTurnoverLimit, '20')
|
|
78
|
+
assert.equal(initAtNext.isAccumulationPeriod, false)
|
|
79
|
+
assert.equal(initAtNext.isAwardPeriod, false)
|
|
80
|
+
|
|
81
|
+
const durationAccumulation = actions.setDuration.assignment(
|
|
82
|
+
{
|
|
83
|
+
...machine.initialState.context,
|
|
84
|
+
isAwardPeriod: true,
|
|
85
|
+
activityDetail: {
|
|
86
|
+
rewardPeriodSameAsAccumulationPeriod: true,
|
|
87
|
+
accumulateEndTime: `${now + 50}`,
|
|
88
|
+
lastCycleCardEndTime: `${now + 99}`,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{}
|
|
92
|
+
)
|
|
93
|
+
assert.equal(durationAccumulation.duration > 0, true)
|
|
94
|
+
|
|
95
|
+
const durationAward = actions.setDuration.assignment(
|
|
96
|
+
{
|
|
97
|
+
...machine.initialState.context,
|
|
98
|
+
isAwardPeriod: true,
|
|
99
|
+
activityDetail: {
|
|
100
|
+
rewardPeriodSameAsAccumulationPeriod: false,
|
|
101
|
+
accumulateEndTime: `${now + 1}`,
|
|
102
|
+
lastCycleCardEndTime: `${now + 50}`,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{}
|
|
106
|
+
)
|
|
107
|
+
assert.equal(durationAward.duration >= 49, true)
|
|
108
|
+
|
|
109
|
+
const loadedDetail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
110
|
+
const awardResult = await services.sentAward({ activityNo: 'A1' }, {})
|
|
111
|
+
assert.equal(loadedDetail.activityNo, 'A1')
|
|
112
|
+
assert.equal(awardResult.status, 'ok')
|
|
113
|
+
assert.equal(calls.length, 2)
|
|
114
|
+
})
|