@jetthai/cuora 1.1.488 → 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.
- package/.husky/pre-commit +3 -1
- package/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +3 -316
- package/README.md +15 -299
- package/package.json +5 -5
- package/resetGitBranch.sh +101 -0
- package/src/api/account.js +1 -0
- package/src/api/activity.js +39 -24
- package/src/api/auth.js +36 -5
- package/src/api/common.js +3 -5
- package/src/api/game.js +10 -0
- package/src/api/payment.js +55 -17
- package/src/api/user.js +16 -10
- package/src/index.js +2 -2
- package/src/lib/fingerprint_v3_11_12.js +11433 -0
- package/src/machine/activity/activity.js +213 -0
- package/src/machine/activity/activity_cash.js +36 -84
- 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 +8 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
- package/src/machine/activity/fafafa_activity.js +11 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +115 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +69 -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 +155 -0
- package/src/machine/activity/roulette_activity_v2.js +1 -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 +112 -149
- package/src/machine/auth_otp_v2.js +178 -0
- package/src/machine/auth_otp_v3.js +22 -64
- package/src/machine/bank_binding.js +3 -2
- package/src/machine/bank_binding_amb.js +146 -0
- package/src/machine/bonus.js +76 -0
- package/src/machine/common.js +98 -14
- package/src/machine/deposit/amb.js +93 -0
- package/src/machine/deposit/crypto_bank.js +340 -0
- package/src/machine/deposit/crypto_bank_cash.js +35 -20
- package/src/machine/deposit/crypto_qrcode.js +158 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
- package/src/machine/deposit/crypto_way.js +253 -0
- package/src/machine/deposit/crypto_way_cash.js +37 -48
- package/src/machine/deposit/deposit_fc.js +272 -0
- package/src/machine/deposit/direct.js +311 -0
- package/src/machine/deposit/direct_cash.js +10 -8
- package/src/machine/deposit/float.js +375 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +152 -0
- package/src/machine/deposit/loadcard_cash.js +32 -14
- package/src/machine/deposit/loadcard_vn.js +352 -0
- package/src/machine/deposit/manual_cash.js +11 -8
- package/src/machine/deposit/manual_vn.js +459 -0
- package/src/machine/deposit/qrcode_cash.js +32 -15
- package/src/machine/deposit/qrcode_v2.js +339 -0
- package/src/machine/deposit/usdt.js +163 -0
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +12 -13
- package/src/machine/deposit/virtual_bank_vn.js +270 -0
- package/src/machine/deposit/vpay.js +374 -0
- package/src/machine/error.js +1 -7
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +80 -0
- package/src/machine/game_info.js +13 -1
- package/src/machine/game_replay.js +47 -0
- package/src/machine/game_search_cash.js +1 -0
- package/src/machine/game_search_v2.js +402 -0
- package/src/machine/game_v2_1.js +126 -39
- package/src/machine/honor_board.js +133 -0
- package/src/machine/honor_board_cash.js +28 -22
- package/src/machine/inbox.js +105 -43
- package/src/machine/index.js +32 -0
- package/src/machine/leaderboard.js +12 -8
- package/src/machine/merge.js +58 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +87 -0
- package/src/machine/promotions.js +163 -0
- package/src/machine/ranking.js +30 -45
- package/src/machine/reward.js +256 -0
- package/src/machine/reward_cash.js +42 -2
- package/src/machine/reward_fc.js +99 -0
- package/src/machine/roulette_v2.js +11 -14
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +160 -0
- package/src/machine/side_cash.js +3 -3
- package/src/machine/side_v2.js +223 -0
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +14 -0
- package/src/machine/user_sign_up.js +61 -46
- package/src/machine/vip_table.js +58 -0
- package/src/machine/websocket.js +349 -374
- package/src/machine/welcome.js +111 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
- package/src/machine/withdraw/withdraw_krway.js +223 -0
- package/src/machine/withdraw/withdraw_manual.js +541 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
- package/src/request/config.js +0 -2
- package/src/request/request.js +60 -124
- package/src/util/constant.js +2 -6
- package/src/util/deviceToken.js +60 -0
- package/src/util/index.js +4 -2
- package/src/util/math.js +4 -0
- 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 +155 -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 +133 -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 +603 -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
- package/.claude/commands/sync-ai-prompts.md +0 -93
- package/.claude/settings.local.json +0 -23
- package/.github/copilot-instructions.md +0 -448
- package/.husky/post-checkout +0 -32
- package/.husky/pre-push +0 -36
- package/AGENTS.md +0 -448
- package/AI_PROMPT_SOURCE.md +0 -446
- package/CLAUDE.md +0 -448
- package/GEMINI.md +0 -448
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
- package/docs/kibana/play-providerId-error.md +0 -202
- package/docs/kibana/play-selectedWalletType.md +0 -1
- package/docs/kibana/play-selectedWalletType_2.md +0 -1
- package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
- package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
- package/scripts/auto-version.js +0 -68
- package/scripts/auto-version.sh +0 -33
- package/scripts/branch-auto-npm-publish.js +0 -29
- package/scripts/check-version.sh +0 -36
- package/scripts/clean-tags.sh +0 -84
- package/src/util/amount.js +0 -8
- package/src/util/err998SentryExtra.js +0 -26
- package/src/util/paramStore.js +0 -139
- package/src/util/socketPolicy.js +0 -57
- package/test/auth_otp_v3.test.js +0 -323
- package/tests/websocket.test.mjs +0 -779
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import directCashFactory from '../src/machine/deposit/direct_cash.js'
|
|
5
|
+
|
|
6
|
+
test('direct_cash covers actions, guards and services branches', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
send: async (req) => {
|
|
10
|
+
sent.push(req)
|
|
11
|
+
if (req.url === 'payment/v2/direct_cash_1/getBankList') {
|
|
12
|
+
return { data: [{ bankCode: 'B1' }, { bankCode: 'B2' }] }
|
|
13
|
+
}
|
|
14
|
+
if (req.url === 'payment/v2/direct_cash_1/expected/result') {
|
|
15
|
+
return { data: { bonus: 3 } }
|
|
16
|
+
}
|
|
17
|
+
if (req.url === 'payment/v2/direct_cash_1/transaction') {
|
|
18
|
+
return { applyId: 'TX-1' }
|
|
19
|
+
}
|
|
20
|
+
return {}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const machine = directCashFactory(request, {
|
|
25
|
+
selectedAmount: 10,
|
|
26
|
+
promotion: { minimumAmount: 50, promotionsNo: 'P-1' },
|
|
27
|
+
paymentDetail: [
|
|
28
|
+
{ category: 'direct', transferType: 'deposit', method: 'direct_cash_1', minimum: 100, maximum: 500 },
|
|
29
|
+
{ category: 'direct', transferType: 'withdraw', method: 'ignored' },
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const { actions, guards, services } = machine.options
|
|
34
|
+
const initial = machine.initialState.context
|
|
35
|
+
|
|
36
|
+
const initData = actions.setInitData.assignment(initial, {})
|
|
37
|
+
assert.equal(initData.directs.length, 1)
|
|
38
|
+
assert.equal(initData.selectedDirect.method, 'direct_cash_1')
|
|
39
|
+
assert.equal(initData.selectedAmount, 100)
|
|
40
|
+
|
|
41
|
+
const setBanksFromObject = actions.setBanks.assignment(
|
|
42
|
+
{ ...initial, selectedDirect: { method: 'direct_cash_1' }, bankMap: {} },
|
|
43
|
+
{ data: { data: [{ bankCode: 'B1' }] } }
|
|
44
|
+
)
|
|
45
|
+
assert.equal(setBanksFromObject.bankMap.direct_cash_1[0].bankCode, 'B1')
|
|
46
|
+
assert.equal(setBanksFromObject.selectedUserBank.bankCode, 'B1')
|
|
47
|
+
|
|
48
|
+
const setBanksFromArray = actions.setBanks.assignment(
|
|
49
|
+
{ ...initial, selectedDirect: { method: 'direct_cash_1' }, bankMap: {} },
|
|
50
|
+
{ data: [{ bankCode: 'B2' }] }
|
|
51
|
+
)
|
|
52
|
+
assert.equal(setBanksFromArray.userBanks[0].bankCode, 'B2')
|
|
53
|
+
|
|
54
|
+
assert.equal(actions.setBanks.assignment({ ...initial, selectedDirect: null, bankMap: {} }, { data: [] }), undefined)
|
|
55
|
+
|
|
56
|
+
assert.equal(actions.setDirect.assignment(initial, { data: { method: 'direct_cash_2' } }).selectedDirect.method, 'direct_cash_2')
|
|
57
|
+
assert.equal(actions.setUserBank.assignment(initial, { data: { bankCode: 'B9' } }).selectedUserBank.bankCode, 'B9')
|
|
58
|
+
assert.equal(actions.setAmount.assignment(initial, { data: '333' }).selectedAmount, '333')
|
|
59
|
+
|
|
60
|
+
const calcFromV2 = actions.setCalculation.assignment(initial, { data: { data: { bonus: 9 } } })
|
|
61
|
+
assert.equal(calcFromV2.calculation.bonus, 9)
|
|
62
|
+
const calcLegacy = actions.setCalculation.assignment(initial, { data: { bonus: 8 } })
|
|
63
|
+
assert.equal(calcLegacy.calculation.bonus, 8)
|
|
64
|
+
|
|
65
|
+
assert.equal(actions.clearCalculation.assignment({ calculation: { x: 1 } }, {}).calculation, null)
|
|
66
|
+
assert.equal(actions.setResult.assignment(initial, { data: { applyId: 'TX-2' } }).result.applyId, 'TX-2')
|
|
67
|
+
assert.equal(actions.setPromotion.assignment(initial, { data: { promotionsNo: 'P-2' } }).promotion.promotionsNo, 'P-2')
|
|
68
|
+
|
|
69
|
+
assert.equal(guards.isCalculable({ selectedAmount: '100', selectedDirect: { minimum: 100, maximum: 500 } }), true)
|
|
70
|
+
assert.equal(guards.isCalculable({ selectedAmount: '99', selectedDirect: { minimum: 100, maximum: 500 } }), false)
|
|
71
|
+
assert.equal(guards.isCalculable({ selectedAmount: '501', selectedDirect: { minimum: 100, maximum: 500 } }), false)
|
|
72
|
+
|
|
73
|
+
assert.equal(guards.isSubmittable({ selectedAmount: 100, selectedDirect: { method: 'm' }, selectedUserBank: { bankCode: 'B1' } }).bankCode, 'B1')
|
|
74
|
+
assert.equal(guards.isSubmittable({ selectedAmount: 100, selectedDirect: null, selectedUserBank: { bankCode: 'B1' } }), null)
|
|
75
|
+
|
|
76
|
+
const noDirectBanks = await services.fetchBanksList({ selectedDirect: null, bankMap: {} })
|
|
77
|
+
assert.deepEqual(noDirectBanks, [])
|
|
78
|
+
|
|
79
|
+
const cachedBanks = await services.fetchBanksList({ selectedDirect: { method: 'direct_cash_1' }, bankMap: { direct_cash_1: [{ bankCode: 'BC' }] } })
|
|
80
|
+
assert.equal(cachedBanks[0].bankCode, 'BC')
|
|
81
|
+
|
|
82
|
+
const remoteBanks = await services.fetchBanksList({ selectedDirect: { method: 'direct_cash_1' }, bankMap: {} })
|
|
83
|
+
assert.equal(remoteBanks.data.length, 2)
|
|
84
|
+
|
|
85
|
+
const calcResult = await services.fetchCalculation({
|
|
86
|
+
selectedDirect: { method: 'direct_cash_1' },
|
|
87
|
+
selectedAmount: '450',
|
|
88
|
+
promotion: { promotionsNo: 'P-3' },
|
|
89
|
+
})
|
|
90
|
+
assert.equal(calcResult.data.bonus, 3)
|
|
91
|
+
|
|
92
|
+
const submitResult = await services.submitDeposit({
|
|
93
|
+
selectedDirect: { method: 'direct_cash_1' },
|
|
94
|
+
selectedAmount: 460,
|
|
95
|
+
selectedUserBank: { bankCode: 'B1' },
|
|
96
|
+
promotion: { promotionsNo: 'P-4' },
|
|
97
|
+
})
|
|
98
|
+
assert.equal(submitResult.applyId, 'TX-1')
|
|
99
|
+
|
|
100
|
+
const calcReq = sent.find((entry) => entry.url === 'payment/v2/direct_cash_1/expected/result')
|
|
101
|
+
assert.equal(calcReq.params.amount, 450)
|
|
102
|
+
assert.equal(calcReq.params.promotionsNo, 'P-3')
|
|
103
|
+
|
|
104
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/direct_cash_1/transaction')
|
|
105
|
+
assert.equal(submitReq.params.amount, 460)
|
|
106
|
+
assert.equal(submitReq.params.applyerBankCode, 'B1')
|
|
107
|
+
assert.equal(submitReq.params.promotionsNo, 'P-4')
|
|
108
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { State } from 'xstate'
|
|
5
|
+
import errorFactory from '../src/machine/error.js'
|
|
6
|
+
|
|
7
|
+
test('error machine actions, guards, services and routing branches', async () => {
|
|
8
|
+
const request = {
|
|
9
|
+
config: { appSecret: 'secret' },
|
|
10
|
+
send: async (req) => ({ data: [{ gameCode: req.params.gameCodes[0], name: 'Demo Game' }] }),
|
|
11
|
+
}
|
|
12
|
+
const machine = errorFactory(request)
|
|
13
|
+
const actions = machine.options.actions
|
|
14
|
+
const guards = machine.options.guards
|
|
15
|
+
const services = machine.options.services
|
|
16
|
+
const ctx = machine.initialState.context
|
|
17
|
+
|
|
18
|
+
assert.equal(actions.setError.assignment(ctx, { data: { code: 'ERR_G106' } }).error.code, 'ERR_G106')
|
|
19
|
+
assert.equal(actions.solveError.assignment.error, null)
|
|
20
|
+
assert.equal(actions.setUnfinishedGame.assignment({ ...ctx, error: { extend: 'unfinished_CODE123' } }, {}).gameCode, 'CODE123')
|
|
21
|
+
assert.equal(actions.setGame.assignment(ctx, { data: { data: [{ id: 9 }] } }).game.id, 9)
|
|
22
|
+
assert.equal(actions.setGame.assignment(ctx, { data: {} }).game, undefined)
|
|
23
|
+
|
|
24
|
+
assert.equal(guards.isLogout({ ...ctx, error: { code: 'ERR_A201' } }, {}), true)
|
|
25
|
+
assert.equal(guards.isNoBalance({ ...ctx, error: { code: 'ERR_G106' } }, {}), true)
|
|
26
|
+
assert.equal(guards.isUnfinishedGame({ ...ctx, error: { extend: 'unfinished_ABC' } }, {}), true)
|
|
27
|
+
assert.equal(guards.isFreeGameSettle({ ...ctx, error: { code: 'ERR_G124' } }, {}), true)
|
|
28
|
+
assert.equal(guards.isFreeGameGiveUp({ ...ctx, error: { code: 'ERR_G125' } }, {}), true)
|
|
29
|
+
|
|
30
|
+
const info = await services.getGameInfo({ ...ctx, gameCode: 'G001' }, {})
|
|
31
|
+
assert.equal(info.data[0].gameCode, 'G001')
|
|
32
|
+
|
|
33
|
+
const toLogout = machine.transition(State.from({ error: 'unknown' }, { ...ctx, error: { code: 'ERR_A201' } }), { type: 'xstate.null' })
|
|
34
|
+
assert.equal(toLogout.value.error, 'logout')
|
|
35
|
+
const toDeposit = machine.transition(State.from({ error: 'unknown' }, { ...ctx, error: { code: 'ERR_G106' } }), { type: 'xstate.null' })
|
|
36
|
+
assert.equal(toDeposit.value.error, 'deposit')
|
|
37
|
+
})
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import machine from '../src/machine/index.js'
|
|
5
|
+
import { createLocalStorageMock } from './helpers.js'
|
|
6
|
+
|
|
7
|
+
function collectEventsFromStates(states, output) {
|
|
8
|
+
if (!states || typeof states !== 'object') return
|
|
9
|
+
|
|
10
|
+
for (const stateNode of Object.values(states)) {
|
|
11
|
+
if (stateNode?.on && typeof stateNode.on === 'object') {
|
|
12
|
+
for (const eventType of Object.keys(stateNode.on)) {
|
|
13
|
+
output.add(eventType)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
collectEventsFromStates(stateNode?.states, output)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function collectMachineEvents(m) {
|
|
21
|
+
const events = new Set()
|
|
22
|
+
|
|
23
|
+
if (m.config?.on && typeof m.config.on === 'object') {
|
|
24
|
+
for (const eventType of Object.keys(m.config.on)) {
|
|
25
|
+
events.add(eventType)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
collectEventsFromStates(m.config?.states, events)
|
|
30
|
+
return [...events].filter((eventType) => typeof eventType === 'string' && !eventType.startsWith('xstate.'))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildEvent(type) {
|
|
34
|
+
return {
|
|
35
|
+
type,
|
|
36
|
+
data: {
|
|
37
|
+
callback: () => {},
|
|
38
|
+
locale: 'en-US',
|
|
39
|
+
site: 'test',
|
|
40
|
+
walletType: 'MAIN',
|
|
41
|
+
categoryId: 1,
|
|
42
|
+
game: {
|
|
43
|
+
providerId: 'P1',
|
|
44
|
+
gameId: 'G1',
|
|
45
|
+
gameTypeId: 'GT1',
|
|
46
|
+
mappingId: 'M1',
|
|
47
|
+
portrait: 0,
|
|
48
|
+
gameCode: 'CODE',
|
|
49
|
+
name: 'Name',
|
|
50
|
+
gameName: 'Game Name',
|
|
51
|
+
},
|
|
52
|
+
list: [{ id: 1, i18n: 'slot' }],
|
|
53
|
+
amount: 10,
|
|
54
|
+
label: 'USDT',
|
|
55
|
+
value: 'TRC20',
|
|
56
|
+
network: 'TRC20',
|
|
57
|
+
channel: 'USDT',
|
|
58
|
+
method: 'manual',
|
|
59
|
+
activityNo: 1,
|
|
60
|
+
requestId: 'req',
|
|
61
|
+
target: 'phone',
|
|
62
|
+
code: '1234',
|
|
63
|
+
uid_site: 'uid',
|
|
64
|
+
uidSite: 'uid',
|
|
65
|
+
provider_id: 'P1',
|
|
66
|
+
seqNo: 'S1',
|
|
67
|
+
appSecret: 'secret',
|
|
68
|
+
index: 0,
|
|
69
|
+
row: 10,
|
|
70
|
+
page: 1,
|
|
71
|
+
type: 'DEPOSIT',
|
|
72
|
+
transferType: 'DEPOSIT',
|
|
73
|
+
paymentMethod: 'manual',
|
|
74
|
+
promotion: { activityNo: 'none' },
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const requestStub = {
|
|
80
|
+
config: {
|
|
81
|
+
apiURL: 'https://api.example.com',
|
|
82
|
+
apiVersion: 'v1',
|
|
83
|
+
clientId: 'client',
|
|
84
|
+
appSecret: 'secret',
|
|
85
|
+
platform: 'web',
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
fpToken: 'fp-token',
|
|
88
|
+
sentry: { captureException: () => {}, setTag: () => {} },
|
|
89
|
+
defaultChannel: 'web',
|
|
90
|
+
defaultSubchannel: 'home',
|
|
91
|
+
socketURL: 'wss://socket.example.com',
|
|
92
|
+
bucketName: 'bucket',
|
|
93
|
+
},
|
|
94
|
+
send: async () => ({}),
|
|
95
|
+
getToken: () => null,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
global.localStorage = createLocalStorageMock()
|
|
99
|
+
global.window = {
|
|
100
|
+
location: {
|
|
101
|
+
search: '',
|
|
102
|
+
href: 'https://example.com/path',
|
|
103
|
+
origin: 'https://example.com',
|
|
104
|
+
protocol: 'https:',
|
|
105
|
+
host: 'example.com',
|
|
106
|
+
},
|
|
107
|
+
atob: (value) => Buffer.from(value, 'base64').toString('binary'),
|
|
108
|
+
CC_JSB: false,
|
|
109
|
+
}
|
|
110
|
+
global.document = { cookie: '' }
|
|
111
|
+
|
|
112
|
+
for (const [machineName, machineFactory] of Object.entries(machine)) {
|
|
113
|
+
test(`machine events do not throw: ${machineName}`, () => {
|
|
114
|
+
const m = machineFactory(requestStub, {})
|
|
115
|
+
const events = collectMachineEvents(m)
|
|
116
|
+
|
|
117
|
+
let state = m.initialState
|
|
118
|
+
for (const eventType of events) {
|
|
119
|
+
const event = buildEvent(eventType)
|
|
120
|
+
assert.doesNotThrow(() => {
|
|
121
|
+
state = m.transition(state, event)
|
|
122
|
+
}, `${machineName} should handle event ${eventType} without throwing`)
|
|
123
|
+
assert.ok(state)
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import favoriteFactory from '../src/machine/game_favorite_v2.js'
|
|
5
|
+
import jackpotFactory from '../src/machine/activity/jackpot.js'
|
|
6
|
+
|
|
7
|
+
test('game_favorite_v2 covers list actions, guards and service branches', async () => {
|
|
8
|
+
let hasToken = true
|
|
9
|
+
const request = {
|
|
10
|
+
getToken: () => (hasToken ? 'token' : null),
|
|
11
|
+
send: async (req) => {
|
|
12
|
+
if (req.url === 'game/list/v3/myFavorite') return { data: [{ gameCode: 'G1' }] }
|
|
13
|
+
if (req.url === 'game/list/v3/addMyFavorite') {
|
|
14
|
+
if (req.params.games[0] === 'ERR') throw new Error('boom')
|
|
15
|
+
return { ok: true }
|
|
16
|
+
}
|
|
17
|
+
if (req.url === 'game/list/v3/removeMyFavorite') {
|
|
18
|
+
if (req.params.games[0] === 'ERR') throw new Error('boom')
|
|
19
|
+
return { ok: true }
|
|
20
|
+
}
|
|
21
|
+
return {}
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const machine = favoriteFactory(request)
|
|
26
|
+
const actions = machine.options.actions
|
|
27
|
+
const guards = machine.options.guards
|
|
28
|
+
const services = machine.options.services
|
|
29
|
+
const ctx = machine.initialState.context
|
|
30
|
+
|
|
31
|
+
assert.equal(actions.setList.assignment(ctx, { data: [{ gameCode: 'G1' }] }).list.length, 1)
|
|
32
|
+
assert.equal(actions.clearList.assignment({ ...ctx, list: [{ gameCode: 'G1' }] }, {}).list.length, 0)
|
|
33
|
+
assert.equal(actions.addToList.assignment(ctx, { data: { gameCode: 'G2' } }).list[0].gameCode, 'G2')
|
|
34
|
+
assert.equal(
|
|
35
|
+
actions.removeFromList.assignment({ ...ctx, list: [{ gameCode: 'G1' }, { gameCode: 'G2' }] }, { data: { gameCode: 'G1' } }).list.length,
|
|
36
|
+
1
|
|
37
|
+
)
|
|
38
|
+
assert.equal(actions.setAuth.assignment(ctx, { data: 1 }).auth, true)
|
|
39
|
+
|
|
40
|
+
assert.equal(guards.isExist({ ...ctx, list: [{ gameCode: 'G1' }] }, { data: { gameCode: 'G1' } }), true)
|
|
41
|
+
assert.equal(guards.isNotExist({ ...ctx, list: [{ gameCode: 'G1' }] }, { data: { gameCode: 'G2' } }), true)
|
|
42
|
+
assert.equal(guards.isAuthChanged({ ...ctx, auth: false }, { data: 1 }), true)
|
|
43
|
+
assert.equal(guards.hasAuth({ ...ctx, auth: true }, {}), true)
|
|
44
|
+
|
|
45
|
+
const addOk = await services.add(ctx, { data: { gameCode: 'G2' } })
|
|
46
|
+
assert.equal(addOk.gameCode, 'G2')
|
|
47
|
+
await assert.rejects(() => services.add(ctx, { data: { gameCode: 'ERR' } }), { gameCode: 'ERR' })
|
|
48
|
+
const removeOk = await services.remove(ctx, { data: { gameCode: 'G2' } })
|
|
49
|
+
assert.equal(removeOk.gameCode, 'G2')
|
|
50
|
+
await assert.rejects(() => services.remove(ctx, { data: { gameCode: 'ERR' } }), { gameCode: 'ERR' })
|
|
51
|
+
|
|
52
|
+
hasToken = true
|
|
53
|
+
const listWithToken = await services.fetchList(ctx, {})
|
|
54
|
+
assert.equal(listWithToken.length, 1)
|
|
55
|
+
hasToken = false
|
|
56
|
+
const listWithoutToken = await services.fetchList(ctx, {})
|
|
57
|
+
assert.equal(listWithoutToken.length, 0)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('activity jackpot covers list/enable/timeout/fetch branches', async () => {
|
|
61
|
+
const request = {
|
|
62
|
+
config: { appSecret: 'secret' },
|
|
63
|
+
send: async (req) => {
|
|
64
|
+
if (req.url === 'activities/jackpot/list') return { data: [{ id: 1 }] }
|
|
65
|
+
return { data: [] }
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const machine = jackpotFactory(request)
|
|
70
|
+
const actions = machine.options.actions
|
|
71
|
+
const services = machine.options.services
|
|
72
|
+
const ctx = machine.initialState.context
|
|
73
|
+
|
|
74
|
+
assert.equal(actions.setJackpotList.assignment(ctx, { data: { jackpotList: [{ id: 1 }] } }).jackpotList.length, 1)
|
|
75
|
+
assert.equal(actions.setJackpotEnable.assignment(ctx, { data: true }).jackpotEnable, true)
|
|
76
|
+
assert.equal(machine.options.delays.TIMEOUT({ ...ctx, tick: 123 }, {}), 1230)
|
|
77
|
+
|
|
78
|
+
const enabled = await services.fetchList({ ...ctx, jackpotEnable: true }, {})
|
|
79
|
+
assert.equal(enabled.jackpotList.length, 1)
|
|
80
|
+
const disabled = await services.fetchList({ ...ctx, jackpotEnable: false }, {})
|
|
81
|
+
assert.equal(disabled.jackpotList.length, 0)
|
|
82
|
+
})
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import floatFactory from '../src/machine/deposit/float.js'
|
|
5
|
+
|
|
6
|
+
test('float covers actions, guards, inline conds and services', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
config: { appSecret: 'app-secret' },
|
|
10
|
+
send: async (req) => {
|
|
11
|
+
sent.push(req)
|
|
12
|
+
if (req.url === 'payment/v2/paymentInfo') {
|
|
13
|
+
return {
|
|
14
|
+
bankInfo: [
|
|
15
|
+
{ bindingType: 'CRYPTO', id: 1 },
|
|
16
|
+
{ bindingType: 'EWALLET', id: 2 },
|
|
17
|
+
{ bindingType: 'BANK', id: 3 },
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (req.url === 'getConfig') {
|
|
22
|
+
return { config: 'eyJib251c1ByZXZpZXdFbmFibGUiOnRydWV9' }
|
|
23
|
+
}
|
|
24
|
+
if (req.url === 'payment/v2/paymentDetail') {
|
|
25
|
+
return [{ method: 'ignored' }, { method: 'amb_float', optional: [100], minimum: 50, maximum: 500, grandTotalEnable: 1 }]
|
|
26
|
+
}
|
|
27
|
+
if (req.url === 'payment/v2/amb/getBankList') {
|
|
28
|
+
return { data: [{ code: 'B1' }] }
|
|
29
|
+
}
|
|
30
|
+
if (req.url === 'payment/v2/amb_float/bonus/preview') {
|
|
31
|
+
return [{ bonus: 9 }]
|
|
32
|
+
}
|
|
33
|
+
if (req.url === 'payment/v2/amb_float/transaction') {
|
|
34
|
+
return { accountName: 'House', accountNumber: '123456', bankName: 'Bank', amount: 444 }
|
|
35
|
+
}
|
|
36
|
+
if (req.url === 'payment/v2/amb_float/expected/result') {
|
|
37
|
+
return { data: { expectedAmount: 111 } }
|
|
38
|
+
}
|
|
39
|
+
return {}
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
global.window = { atob: (value) => Buffer.from(value, 'base64').toString('utf8') }
|
|
44
|
+
|
|
45
|
+
const machine = floatFactory(request)
|
|
46
|
+
const { actions, guards, services } = machine.options
|
|
47
|
+
const initial = machine.initialState.context
|
|
48
|
+
|
|
49
|
+
const checkingCond = machine.config.states.checking.always[0].cond
|
|
50
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' } }), true)
|
|
51
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: false }, promotion: { activityNo: 'A1' } }), false)
|
|
52
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'none' } }), false)
|
|
53
|
+
|
|
54
|
+
const countdownCond = machine.config.states.countdown.after[1000][0].cond
|
|
55
|
+
assert.equal(countdownCond({ ttl: 2 }), true)
|
|
56
|
+
assert.equal(countdownCond({ ttl: 0 }), false)
|
|
57
|
+
|
|
58
|
+
assert.equal(actions.setUserAccount.assignment(initial, { data: [{ account: 'u1' }] }).userAccount.account, 'u1')
|
|
59
|
+
assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'P1' } }).promotion.activityNo, 'P1')
|
|
60
|
+
assert.equal(actions.setBonusPreview.assignment(initial, { data: [{ bonus: 1 }] }).bonusPreviewData[0].bonus, 1)
|
|
61
|
+
|
|
62
|
+
const house = actions.setHouseBank.assignment(initial, {
|
|
63
|
+
data: { accountName: 'A', accountNumber: 'N', bankName: 'B', amount: 88 },
|
|
64
|
+
})
|
|
65
|
+
assert.equal(house.houseAccountName, 'A')
|
|
66
|
+
assert.equal(house.houseAccountNumber, 'N')
|
|
67
|
+
assert.equal(house.houseBankName, 'B')
|
|
68
|
+
assert.equal(house.calculatedAmount, 88)
|
|
69
|
+
|
|
70
|
+
const initFromData = actions.setInitialization.assignment(initial, {
|
|
71
|
+
data: {
|
|
72
|
+
siteConfig: { bonusPreviewEnable: true },
|
|
73
|
+
housePayment: { optional: [100, 200], minimum: 50, maximum: 500, grandTotalEnable: 1 },
|
|
74
|
+
bankList: { data: [{ code: 'B1' }] },
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
assert.equal(initFromData.bankList[0].code, 'B1')
|
|
78
|
+
|
|
79
|
+
const initFromArray = actions.setInitialization.assignment(initial, {
|
|
80
|
+
data: {
|
|
81
|
+
siteConfig: { bonusPreviewEnable: true },
|
|
82
|
+
housePayment: { optional: [300], minimum: 10, maximum: 20, grandTotalEnable: 0 },
|
|
83
|
+
bankList: [{ code: 'B2' }],
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
assert.equal(initFromArray.bankList[0].code, 'B2')
|
|
87
|
+
|
|
88
|
+
assert.equal(actions.addAmount.assignment({ amount: 200, maximum: 250 }, { data: 80 }).amount, 250)
|
|
89
|
+
assert.equal(actions.setAmount.assignment(initial, { data: 333 }).amount, 333)
|
|
90
|
+
|
|
91
|
+
const calcFromV2 = actions.setCalculation.assignment(initial, { data: { data: { expectedAmount: 5 } } })
|
|
92
|
+
assert.equal(calcFromV2.calculation.expectedAmount, 5)
|
|
93
|
+
const calcLegacy = actions.setCalculation.assignment(initial, { data: { expectedAmount: 6 } })
|
|
94
|
+
assert.equal(calcLegacy.calculation.expectedAmount, 6)
|
|
95
|
+
|
|
96
|
+
assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
|
|
97
|
+
assert.equal(actions.decreaseTtl.assignment({ ttl: 3 }, {}).ttl, 2)
|
|
98
|
+
assert.equal(actions.decreaseTtl.assignment({ ttl: 0 }, {}).ttl, 0)
|
|
99
|
+
|
|
100
|
+
assert.equal(guards.hasUserAccount(initial, { data: [] }), undefined)
|
|
101
|
+
assert.equal(guards.hasUserAccount(initial, { data: [{ id: 9 }] }).id, 9)
|
|
102
|
+
assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 1 }), true)
|
|
103
|
+
assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 0 }), false)
|
|
104
|
+
|
|
105
|
+
const filtered = await services.fetchPaymentInfo(initial)
|
|
106
|
+
assert.equal(filtered.length, 1)
|
|
107
|
+
assert.equal(filtered[0].id, 3)
|
|
108
|
+
|
|
109
|
+
const initialized = await services.initialize({ method: 'amb_float' })
|
|
110
|
+
assert.equal(initialized.siteConfig.bonusPreviewEnable, true)
|
|
111
|
+
assert.equal(initialized.housePayment.method, 'amb_float')
|
|
112
|
+
assert.equal(initialized.bankList.data[0].code, 'B1')
|
|
113
|
+
|
|
114
|
+
const bonusPreview = await services.fetchBonusPreview({ method: 'amb_float', promotion: { activityNo: 'P100' } })
|
|
115
|
+
assert.equal(bonusPreview[0].bonus, 9)
|
|
116
|
+
|
|
117
|
+
const submitResult = await services.submitDeposit({ method: 'amb_float', amount: 444, promotion: { activityNo: 'P9' } })
|
|
118
|
+
assert.equal(submitResult.bankName, 'Bank')
|
|
119
|
+
|
|
120
|
+
const calcResult = await services.fetchCalculation({ method: 'amb_float', amount: '45', promotion: { activityNo: 'P8' } })
|
|
121
|
+
assert.equal(calcResult.data.expectedAmount, 111)
|
|
122
|
+
|
|
123
|
+
const bonusReq = sent.find((entry) => entry.url === 'payment/v2/amb_float/bonus/preview')
|
|
124
|
+
assert.equal(bonusReq.params.promotionsNo, 'P100')
|
|
125
|
+
|
|
126
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/amb_float/transaction')
|
|
127
|
+
assert.equal(submitReq.params.amount, 444)
|
|
128
|
+
assert.equal(submitReq.params.promotionsNo, 'P9')
|
|
129
|
+
|
|
130
|
+
const calcReq = sent.find((entry) => entry.url === 'payment/v2/amb_float/expected/result')
|
|
131
|
+
assert.equal(calcReq.params.amount, 45)
|
|
132
|
+
assert.equal(calcReq.params.promotionsNo, 'P8')
|
|
133
|
+
|
|
134
|
+
const paymentDetailReq = sent.find((entry) => entry.url === 'payment/v2/paymentDetail')
|
|
135
|
+
assert.equal(paymentDetailReq.params.transferType, 'DEPOSIT')
|
|
136
|
+
})
|