@jetthai/cuora 2.0.0-beta.0 → 2.0.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/.claude/commands/sync-ai-prompts.md +93 -0
- package/.claude/settings.local.json +23 -0
- package/.github/copilot-instructions.md +405 -0
- package/.husky/post-checkout +32 -0
- package/.husky/pre-commit +1 -3
- package/.husky/pre-push +36 -0
- package/AGENTS.md +405 -0
- package/AI_PROMPT_SOURCE.md +403 -0
- package/CHANGELOG.md +274 -3
- package/CLAUDE.md +405 -0
- package/GEMINI.md +405 -0
- package/README.md +299 -15
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
- package/docs/kibana/play-providerId-error.md +202 -0
- package/docs/kibana/play-selectedWalletType.md +1 -0
- package/docs/kibana/play-selectedWalletType_2.md +1 -0
- package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
- package/package.json +3 -3
- package/scripts/auto-version.js +68 -0
- package/scripts/auto-version.sh +33 -0
- package/scripts/branch-auto-npm-publish.js +29 -0
- package/scripts/check-version.sh +36 -0
- package/scripts/clean-tags.sh +84 -0
- package/src/api/account.js +0 -1
- package/src/api/activity.js +22 -37
- package/src/api/auth.js +5 -36
- package/src/api/common.js +5 -3
- package/src/api/game.js +0 -10
- package/src/api/payment.js +17 -55
- package/src/api/user.js +10 -16
- package/src/index.js +2 -2
- package/src/machine/activity/activity_cash.js +84 -36
- package/src/machine/activity/cash_rain_activity.js +0 -1
- package/src/machine/activity/continue_deposit_activity.js +0 -1
- package/src/machine/activity/deposit_activity.js +0 -1
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
- package/src/machine/activity/fafafa_activity.js +0 -11
- package/src/machine/activity/friend_invite_friends_activity.js +8 -7
- package/src/machine/activity/index.js +0 -12
- package/src/machine/activity/instant_rebate_activity.js +0 -1
- package/src/machine/activity/jackpot.js +0 -1
- package/src/machine/activity/otp_verified_activity.js +0 -1
- package/src/machine/activity/ranking_activity.js +0 -1
- package/src/machine/activity/roulette_activity_v2.js +0 -1
- package/src/machine/activity/sign_in_activity.js +0 -1
- package/src/machine/activity/sign_in_monthly_activity.js +1 -2
- package/src/machine/activity/specify_bets_activity.js +0 -1
- package/src/machine/activity/specify_turnover_activity.js +0 -1
- package/src/machine/activity/time_bomb_activity.js +0 -1
- package/src/machine/activity/vip_card_activity.js +0 -1
- package/src/machine/auth.js +112 -112
- package/src/machine/auth_otp_v3.js +11 -8
- package/src/machine/bank_binding.js +2 -3
- package/src/machine/common.js +14 -98
- package/src/machine/deposit/crypto_bank_cash.js +20 -35
- package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
- package/src/machine/deposit/crypto_way_cash.js +48 -37
- package/src/machine/deposit/direct_cash.js +8 -10
- package/src/machine/deposit/index.js +0 -28
- package/src/machine/deposit/loadcard_cash.js +14 -32
- package/src/machine/deposit/manual_cash.js +8 -11
- package/src/machine/deposit/qrcode_cash.js +15 -32
- package/src/machine/deposit/usdt_cash.js +1 -15
- package/src/machine/deposit/virtual_bank_cash.js +13 -12
- package/src/machine/error.js +7 -1
- package/src/machine/game_betslip.js +0 -1
- package/src/machine/game_favorite_v2.js +0 -1
- package/src/machine/game_info.js +1 -13
- package/src/machine/game_search_cash.js +0 -1
- package/src/machine/game_v2_1.js +39 -126
- package/src/machine/honor_board_cash.js +8 -11
- package/src/machine/inbox.js +43 -105
- package/src/machine/index.js +0 -32
- package/src/machine/leaderboard.js +8 -12
- package/src/machine/navbar.js +1 -3
- package/src/machine/ranking.js +45 -30
- package/src/machine/reward_cash.js +0 -40
- package/src/machine/roulette_v2.js +14 -11
- package/src/machine/setting.js +0 -1
- package/src/machine/side_cash.js +3 -3
- package/src/machine/user_info.js +0 -1
- package/src/machine/user_photo.js +0 -1
- package/src/machine/user_reset_password.js +0 -14
- package/src/machine/user_sign_up.js +46 -61
- package/src/machine/websocket.js +18 -62
- package/src/machine/withdraw/index.js +0 -6
- package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
- package/src/request/config.js +2 -0
- package/src/request/request.js +49 -60
- package/src/util/amount.js +8 -0
- package/src/util/constant.js +0 -1
- package/src/util/err998SentryExtra.js +26 -0
- package/src/util/index.js +2 -4
- package/src/util/paramStore.js +139 -0
- package/src/util/storage.js +3 -4
- package/BREAKING_CHANGES.md +0 -9
- package/resetGitBranch.sh +0 -101
- package/src/lib/fingerprint_v3_11_12.js +0 -11433
- package/src/machine/activity/activity.js +0 -213
- package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
- package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
- package/src/machine/activity/invite_friends_activity.js +0 -115
- package/src/machine/activity/mini_game_activity.js +0 -69
- package/src/machine/activity/return_bonus_activity.js +0 -155
- package/src/machine/auth_otp_v2.js +0 -178
- package/src/machine/bank_binding_amb.js +0 -146
- package/src/machine/bonus.js +0 -76
- package/src/machine/deposit/amb.js +0 -93
- package/src/machine/deposit/crypto_bank.js +0 -340
- package/src/machine/deposit/crypto_qrcode.js +0 -158
- package/src/machine/deposit/crypto_way.js +0 -253
- package/src/machine/deposit/deposit_fc.js +0 -272
- package/src/machine/deposit/direct.js +0 -311
- package/src/machine/deposit/float.js +0 -375
- package/src/machine/deposit/krway.js +0 -152
- package/src/machine/deposit/loadcard_vn.js +0 -352
- package/src/machine/deposit/manual_vn.js +0 -459
- package/src/machine/deposit/qrcode_v2.js +0 -339
- package/src/machine/deposit/usdt.js +0 -163
- package/src/machine/deposit/virtual_bank_vn.js +0 -270
- package/src/machine/deposit/vpay.js +0 -374
- package/src/machine/game_hot_new.js +0 -80
- package/src/machine/game_replay.js +0 -47
- package/src/machine/game_search_v2.js +0 -402
- package/src/machine/honor_board.js +0 -133
- package/src/machine/merge.js +0 -58
- package/src/machine/payment_data.js +0 -87
- package/src/machine/promotions.js +0 -163
- package/src/machine/reward.js +0 -256
- package/src/machine/reward_fc.js +0 -99
- package/src/machine/side.js +0 -160
- package/src/machine/side_v2.js +0 -223
- package/src/machine/vip_table.js +0 -58
- package/src/machine/welcome.js +0 -111
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
- package/src/machine/withdraw/withdraw_krway.js +0 -223
- package/src/machine/withdraw/withdraw_manual.js +0 -541
- package/src/util/deviceToken.js +0 -60
- package/src/util/math.js +0 -4
- package/test/api.behavior.test.js +0 -69
- package/test/api.contract.test.js +0 -18
- package/test/config.test.js +0 -27
- package/test/deviceToken.test.js +0 -139
- package/test/helpers.coverage.test.js +0 -11
- package/test/helpers.js +0 -91
- package/test/index.exports.test.js +0 -14
- package/test/machine.activity.core.coverage.test.js +0 -337
- package/test/machine.activity.gap.coverage.test.js +0 -252
- package/test/machine.activity.more.coverage.test.js +0 -180
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
- package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
- package/test/machine.activity_welcome.low.coverage.test.js +0 -211
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
- package/test/machine.auth.coverage.test.js +0 -215
- package/test/machine.bank_binding.test.js +0 -143
- package/test/machine.binding_otp_krway.coverage.test.js +0 -223
- package/test/machine.contract.test.js +0 -50
- package/test/machine.crypto_bank.coverage.test.js +0 -270
- package/test/machine.crypto_way.coverage.test.js +0 -108
- package/test/machine.crypto_way_cash.coverage.test.js +0 -114
- package/test/machine.definition.test.js +0 -137
- package/test/machine.deposit.manual.coverage.test.js +0 -365
- package/test/machine.deposit_fc.coverage.test.js +0 -126
- package/test/machine.direct.coverage.test.js +0 -96
- package/test/machine.direct_cash.coverage.test.js +0 -108
- package/test/machine.error.coverage.test.js +0 -37
- package/test/machine.events.test.js +0 -126
- package/test/machine.favorite_jackpot.coverage.test.js +0 -82
- package/test/machine.float.coverage.test.js +0 -136
- package/test/machine.flow.test.js +0 -226
- package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
- package/test/machine.game_search_cash.coverage.test.js +0 -155
- package/test/machine.game_search_v2.test.js +0 -199
- package/test/machine.game_user_profile.coverage.test.js +0 -100
- package/test/machine.honor_board.test.js +0 -133
- package/test/machine.inbox.common.coverage.test.js +0 -304
- package/test/machine.loadcard_cash.coverage.test.js +0 -101
- package/test/machine.loadcard_vn.coverage.test.js +0 -122
- package/test/machine.misc.coverage.test.js +0 -361
- package/test/machine.more2.coverage.test.js +0 -261
- package/test/machine.options.execution.test.js +0 -272
- package/test/machine.priority.coverage.test.js +0 -603
- package/test/machine.qrcode_cash.coverage.test.js +0 -107
- package/test/machine.qrcode_v2.coverage.test.js +0 -121
- package/test/machine.regression.test.js +0 -82
- package/test/machine.roulette_v2.test.js +0 -142
- package/test/machine.side_reward_reset.coverage.test.js +0 -220
- package/test/machine.targeted.coverage.test.js +0 -313
- package/test/machine.usdt.coverage.test.js +0 -95
- package/test/machine.usdt_cash.coverage.test.js +0 -73
- package/test/machine.vip_card_activity.test.js +0 -114
- package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
- package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
- package/test/machine.vpay.coverage.test.js +0 -142
- package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
- package/test/machine.withdraw_krway.coverage.test.js +0 -123
- package/test/machine.withdraw_manual.coverage.test.js +0 -185
- package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
- package/test/request.test.js +0 -325
- package/test/util.storage.errors.test.js +0 -47
- package/test/util.test.js +0 -41
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import miniGameActivityFactory from '../src/machine/activity/mini_game_activity.js'
|
|
5
|
-
import signInMonthlyActivityFactory from '../src/machine/activity/sign_in_monthly_activity.js'
|
|
6
|
-
import otpVerifiedActivityFactory from '../src/machine/activity/otp_verified_activity.js'
|
|
7
|
-
import rouletteActivityV2Factory from '../src/machine/activity/roulette_activity_v2.js'
|
|
8
|
-
import timeBombActivityFactory from '../src/machine/activity/time_bomb_activity.js'
|
|
9
|
-
import bonusFactory from '../src/machine/bonus.js'
|
|
10
|
-
|
|
11
|
-
test('mini_game/sign_in_monthly/otp_verified cover actions and fetch services', async () => {
|
|
12
|
-
const request = {
|
|
13
|
-
config: { appSecret: 'secret' },
|
|
14
|
-
send: async (req) => {
|
|
15
|
-
if (req.url === 'activities') return { data: { receiveStatus: 1, rewardsCalendar: [1], activityNo: req.params.activityNo } }
|
|
16
|
-
return { data: [] }
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const mini = miniGameActivityFactory(request)
|
|
21
|
-
const mActions = mini.options.actions
|
|
22
|
-
const mServices = mini.options.services
|
|
23
|
-
const mCtx = mini.initialState.context
|
|
24
|
-
assert.equal(mActions.setActivityNo.assignment(mCtx, { data: 3 }).activityNo, 3)
|
|
25
|
-
const diamond = mActions.setDiamondShopActivities.assignment(mCtx, {
|
|
26
|
-
data: [
|
|
27
|
-
{ activityType: 92, activityNo: 5 },
|
|
28
|
-
{ activityType: 1, activityNo: 2 },
|
|
29
|
-
],
|
|
30
|
-
})
|
|
31
|
-
assert.equal(diamond.rankActivities.length, 1)
|
|
32
|
-
assert.equal(diamond.activityNo, 5)
|
|
33
|
-
assert.equal(mActions.setActivityDetail.assignment(mCtx, { data: { x: 1 } }).activityDetail.x, 1)
|
|
34
|
-
const md = await mServices.fetchActivityDetail({ ...mCtx, activityNo: 3 }, {})
|
|
35
|
-
assert.equal(md.activityNo, 3)
|
|
36
|
-
|
|
37
|
-
const monthly = signInMonthlyActivityFactory(request)
|
|
38
|
-
const sActions = monthly.options.actions
|
|
39
|
-
const sServices = monthly.options.services
|
|
40
|
-
const sCtx = monthly.initialState.context
|
|
41
|
-
assert.equal(sActions.setActivityNo.assignment(sCtx, { data: 4 }).activityNo, 4)
|
|
42
|
-
const init = sActions.setInitData.assignment(sCtx, { data: { rewardsCalendar: [1, 2], receiveStatus: 1 } })
|
|
43
|
-
assert.equal(init.rewardsCalendar.length, 2)
|
|
44
|
-
assert.equal(init.receiveStatus, 1)
|
|
45
|
-
const initDefault = sActions.setInitData.assignment(sCtx, { data: null })
|
|
46
|
-
assert.equal(initDefault.receiveStatus, 0)
|
|
47
|
-
const sd = await sServices.fetchActivityDetail({ ...sCtx, activityNo: 4 }, {})
|
|
48
|
-
assert.equal(sd.activityNo, 4)
|
|
49
|
-
|
|
50
|
-
const otp = otpVerifiedActivityFactory(request)
|
|
51
|
-
const oActions = otp.options.actions
|
|
52
|
-
const oGuards = otp.options.guards
|
|
53
|
-
const oServices = otp.options.services
|
|
54
|
-
const oCtx = otp.initialState.context
|
|
55
|
-
assert.equal(oActions.setActivityNo.assignment(oCtx, { data: 9 }).activityNo, 9)
|
|
56
|
-
assert.equal(oActions.setActivityDetail.assignment(oCtx, { data: { receiveStatus: 1 } }).activityDetail.receiveStatus, 1)
|
|
57
|
-
assert.equal(oGuards.isReceived({ ...oCtx, activityDetail: { receiveStatus: 1 } }, {}), true)
|
|
58
|
-
const od = await oServices.fetchActivityDetail({ ...oCtx, activityNo: 9 }, {})
|
|
59
|
-
assert.equal(od.activityNo, 9)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('roulette_activity_v2 and time_bomb_activity cover duration/expired branches', async () => {
|
|
63
|
-
const request = {
|
|
64
|
-
config: { appSecret: 'secret' },
|
|
65
|
-
send: async (req) => ({
|
|
66
|
-
data: { activityNo: req.params.activityNo, periodEndTime: Math.floor(Date.now() / 1000) + 5, deadline: Math.floor(Date.now() / 1000) + 5 },
|
|
67
|
-
}),
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const roulette = rouletteActivityV2Factory(request, { activityNo: 1 })
|
|
71
|
-
const rActions = roulette.options.actions
|
|
72
|
-
const rGuards = roulette.options.guards
|
|
73
|
-
const rServices = roulette.options.services
|
|
74
|
-
const rCtx = roulette.initialState.context
|
|
75
|
-
assert.equal(rActions.setActivityNo.assignment(rCtx, { data: 2 }).activityNo, 2)
|
|
76
|
-
assert.equal(rActions.setActivityDetail.assignment(rCtx, { data: { periodEndTime: 10 } }).activityDetail.periodEndTime, 10)
|
|
77
|
-
assert.ok(
|
|
78
|
-
Number.isFinite(rActions.setDuration.assignment({ ...rCtx, activityDetail: { periodEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration)
|
|
79
|
-
)
|
|
80
|
-
assert.equal(rGuards.isExpired({ ...rCtx, duration: -1 }, {}), true)
|
|
81
|
-
const rd = await rServices.fetchActivityDetail({ ...rCtx, activityNo: 2 }, {})
|
|
82
|
-
assert.equal(rd.activityNo, 2)
|
|
83
|
-
|
|
84
|
-
const timeBomb = timeBombActivityFactory(request, { activityNo: 3 })
|
|
85
|
-
const tActions = timeBomb.options.actions
|
|
86
|
-
const tGuards = timeBomb.options.guards
|
|
87
|
-
const tServices = timeBomb.options.services
|
|
88
|
-
const tCtx = timeBomb.initialState.context
|
|
89
|
-
assert.equal(tActions.setActivityNo.assignment(tCtx, { data: 4 }).activityNo, 4)
|
|
90
|
-
assert.equal(tActions.setActivityDetail.assignment(tCtx, { data: { deadline: 10 } }).activityDetail.deadline, 10)
|
|
91
|
-
assert.ok(
|
|
92
|
-
Number.isFinite(tActions.setDuration.assignment({ ...tCtx, activityDetail: { deadline: Math.floor(Date.now() / 1000) + 1 } }, {}).duration)
|
|
93
|
-
)
|
|
94
|
-
assert.equal(tGuards.isExpired({ ...tCtx, duration: 0 }, {}), true)
|
|
95
|
-
const td = await tServices.fetchActivityDetail({ ...tCtx, activityNo: 4 }, {})
|
|
96
|
-
assert.equal(td.activityNo, 4)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
test('bonus covers switch conditions, send actions, and services', async () => {
|
|
100
|
-
const sent = []
|
|
101
|
-
const request = {
|
|
102
|
-
send: async (req) => {
|
|
103
|
-
sent.push(req)
|
|
104
|
-
if (req.url === 'payment/v2/paymentInfo') return { bonus: 1 }
|
|
105
|
-
return { ok: true }
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
const machine = bonusFactory(request)
|
|
109
|
-
const actions = machine.options.actions
|
|
110
|
-
const services = machine.options.services
|
|
111
|
-
const ctx = machine.initialState.context
|
|
112
|
-
|
|
113
|
-
assert.equal(actions.setBonus.assignment(ctx, { data: 1 }).bonus, 1)
|
|
114
|
-
const switchOnCond = machine.config.states.idle.on.SWITCH_ON.cond
|
|
115
|
-
const switchOffCond = machine.config.states.idle.on.SWITCH_OFF.cond
|
|
116
|
-
assert.equal(switchOnCond({ ...ctx, bonus: 0 }, {}), true)
|
|
117
|
-
assert.equal(switchOnCond({ ...ctx, bonus: 1 }, {}), false)
|
|
118
|
-
assert.equal(switchOffCond({ ...ctx, bonus: 1 }, {}), true)
|
|
119
|
-
assert.equal(switchOffCond({ ...ctx, bonus: 0 }, {}), false)
|
|
120
|
-
|
|
121
|
-
const switchOnAction = machine.config.states.idle.on.SWITCH_ON.actions
|
|
122
|
-
const switchOffAction = machine.config.states.idle.on.SWITCH_OFF.actions
|
|
123
|
-
assert.deepEqual(switchOnAction.event({ ...ctx, bonus: 0 }, {}), { type: 'TOGGLE', data: 1 })
|
|
124
|
-
assert.deepEqual(switchOffAction.event({ ...ctx, bonus: 1 }, {}), { type: 'TOGGLE', data: 0 })
|
|
125
|
-
|
|
126
|
-
const initBonus = await services.fetchInitData(ctx, {})
|
|
127
|
-
assert.equal(initBonus, 1)
|
|
128
|
-
const toggledFrom1 = await services.toggleBonus({ ...ctx, bonus: 1 }, {})
|
|
129
|
-
assert.equal(toggledFrom1, 0)
|
|
130
|
-
const toggledFrom0 = await services.toggleBonus({ ...ctx, bonus: 0 }, {})
|
|
131
|
-
assert.equal(toggledFrom0, 1)
|
|
132
|
-
assert.equal(
|
|
133
|
-
sent.some((req) => req.url === 'payment/v2/setting'),
|
|
134
|
-
true
|
|
135
|
-
)
|
|
136
|
-
})
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import fafafaActivityFactory from '../src/machine/activity/fafafa_activity.js'
|
|
5
|
-
import specifyBetsActivityFactory from '../src/machine/activity/specify_bets_activity.js'
|
|
6
|
-
import specifyTurnoverActivityFactory from '../src/machine/activity/specify_turnover_activity.js'
|
|
7
|
-
import depositActivityFactory from '../src/machine/activity/deposit_activity.js'
|
|
8
|
-
import returnBonusActivityFactory from '../src/machine/activity/return_bonus_activity.js'
|
|
9
|
-
import welcomeFactory from '../src/machine/welcome.js'
|
|
10
|
-
import { createLocalStorageMock } from './helpers.js'
|
|
11
|
-
|
|
12
|
-
test('fafafa_activity actions/guards/services cover reward and period branches', async () => {
|
|
13
|
-
const sent = []
|
|
14
|
-
const request = {
|
|
15
|
-
config: { appSecret: 'secret' },
|
|
16
|
-
send: async (req) => {
|
|
17
|
-
sent.push(req)
|
|
18
|
-
if (req.url === 'activities') return { data: { receiveStatus: 2, periodEndTime: Math.floor(Date.now() / 1000) + 30 } }
|
|
19
|
-
if (req.url === 'activities/sentAward') {
|
|
20
|
-
return { data: { awards: [{ id: 1 }], periodBeginTime: 1, periodEndTime: 2, receiveNo: req.params.activityNo, receiveReward: true } }
|
|
21
|
-
}
|
|
22
|
-
if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
|
|
23
|
-
return { data: {} }
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
const machine = fafafaActivityFactory(request, { activityNo: 88, isAutoReceiving: true })
|
|
27
|
-
const actions = machine.options.actions
|
|
28
|
-
const guards = machine.options.guards
|
|
29
|
-
const services = machine.options.services
|
|
30
|
-
const ctx = machine.initialState.context
|
|
31
|
-
|
|
32
|
-
assert.equal(actions.setActivityNo.assignment(ctx, { data: 99 }).activityNo, 99)
|
|
33
|
-
const detailSet = actions.setActivityDetail.assignment({ ...ctx, lastCheckedPeriodEndTime: 1 }, { data: { periodEndTime: 10, receiveStatus: 2 } })
|
|
34
|
-
assert.equal(detailSet.lastCheckedPeriodEndTime, null)
|
|
35
|
-
assert.equal(
|
|
36
|
-
actions.setAward.assignment(ctx, { data: { awards: [1], periodBeginTime: 1, periodEndTime: 2, receiveNo: '3', receiveReward: true } }).receiveNo,
|
|
37
|
-
'3'
|
|
38
|
-
)
|
|
39
|
-
assert.equal(typeof actions.setCallback.assignment(ctx, { data: {} }).callback, 'function')
|
|
40
|
-
let cb = 0
|
|
41
|
-
actions.doCallback({ ...ctx, callback: () => cb++ }, {})
|
|
42
|
-
assert.equal(cb, 1)
|
|
43
|
-
assert.ok(actions.setDuration.assignment({ ...ctx, activityDetail: { periodEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
|
|
44
|
-
|
|
45
|
-
assert.equal(guards.isAwardable({ ...ctx, activityDetail: { receiveStatus: 2 } }, {}), true)
|
|
46
|
-
assert.equal(guards.isAutoReceiving({ ...ctx, isAutoReceiving: true }, {}), true)
|
|
47
|
-
const periodCtx = { ...ctx, duration: 0, activityDetail: { periodEndTime: 123 }, lastCheckedPeriodEndTime: null }
|
|
48
|
-
assert.equal(guards.shouldCheckNewPeriod(periodCtx, {}), true)
|
|
49
|
-
assert.equal(guards.shouldCheckNewPeriod(periodCtx, {}), false)
|
|
50
|
-
assert.equal(guards.shouldCheckNewPeriod({ ...ctx, duration: 1, activityDetail: { periodEndTime: 123 } }, {}), false)
|
|
51
|
-
|
|
52
|
-
await services.fetchActivityDetail({ ...ctx, activityNo: 88 }, {})
|
|
53
|
-
await services.awardPrize({ ...ctx, activityNo: 88 }, {})
|
|
54
|
-
const r0 = await services.receiveReward({ ...ctx, activityNo: 88, receiveNo: '0' }, {})
|
|
55
|
-
assert.equal(r0.ok, true)
|
|
56
|
-
const r2 = await services.receiveReward({ ...ctx, activityNo: 88, receiveNo: '2' }, {})
|
|
57
|
-
assert.equal(r2.receiveNo, 2)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test('specify_bets_activity and specify_turnover_activity cover timer and receive branches', async () => {
|
|
61
|
-
const sent = []
|
|
62
|
-
const request = {
|
|
63
|
-
config: { appSecret: 'secret' },
|
|
64
|
-
send: async (req) => {
|
|
65
|
-
sent.push(req)
|
|
66
|
-
if (req.url === 'activities')
|
|
67
|
-
return { data: { activityNo: 7, receiveStatus: 2, receiveNo: '2', taskTimer: 1, registerTime: 0, activityEndTime: 1 } }
|
|
68
|
-
if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
|
|
69
|
-
return { data: [] }
|
|
70
|
-
},
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const bets = specifyBetsActivityFactory(request, { activityNo: 7 })
|
|
74
|
-
const bActions = bets.options.actions
|
|
75
|
-
const bGuards = bets.options.guards
|
|
76
|
-
const bServices = bets.options.services
|
|
77
|
-
const bCtx = bets.initialState.context
|
|
78
|
-
let typeSeen = null
|
|
79
|
-
bActions.doCallback({ ...bCtx, callback: (type) => (typeSeen = type) }, { data: { type: 'bets' } })
|
|
80
|
-
assert.equal(typeSeen, 'bets')
|
|
81
|
-
assert.equal(bActions.setActivityNo.assignment(bCtx, { data: 8 }).activityNo, 8)
|
|
82
|
-
assert.equal(bActions.setActivityDetail.assignment(bCtx, { data: { receiveStatus: 0 } }).activityDetail.receiveStatus, 0)
|
|
83
|
-
assert.equal(typeof bActions.setCallback.assignment(bCtx, { data: {} }).callback, 'function')
|
|
84
|
-
assert.ok(bActions.setDuration.assignment({ ...bCtx, activityDetail: { taskTimer: 1, registerTime: 0 } }, {}).duration >= 0)
|
|
85
|
-
assert.ok(
|
|
86
|
-
bActions.setDuration.assignment({ ...bCtx, activityDetail: { taskTimer: 0, activityEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >=
|
|
87
|
-
0
|
|
88
|
-
)
|
|
89
|
-
assert.equal(bGuards.isReceivable({ ...bCtx, activityDetail: { receiveStatus: 2 } }, {}), true)
|
|
90
|
-
assert.equal(bGuards.isReceived({ ...bCtx, activityDetail: { receiveStatus: 1 } }, {}), true)
|
|
91
|
-
assert.equal(bGuards.isOngoing({ ...bCtx, activityDetail: { receiveStatus: 0 } }, {}), true)
|
|
92
|
-
await bServices.fetchActivityDetail({ ...bCtx, activityNo: 7 }, {})
|
|
93
|
-
await bServices.receiveReward({ ...bCtx, activityDetail: { activityNo: 7, receiveNo: '0' } }, {})
|
|
94
|
-
const bReward = await bServices.receiveReward({ ...bCtx, activityDetail: { activityNo: 7, receiveNo: '2' } }, {})
|
|
95
|
-
assert.equal(bReward.receiveNo, 2)
|
|
96
|
-
|
|
97
|
-
const turnover = specifyTurnoverActivityFactory(request, { activityNo: 9 })
|
|
98
|
-
const tActions = turnover.options.actions
|
|
99
|
-
const tGuards = turnover.options.guards
|
|
100
|
-
const tServices = turnover.options.services
|
|
101
|
-
const tCtx = turnover.initialState.context
|
|
102
|
-
tActions.doCallback({ ...tCtx, callback: (type) => (typeSeen = type) }, { data: { type: 'turnover' } })
|
|
103
|
-
assert.equal(typeSeen, 'turnover')
|
|
104
|
-
assert.equal(tActions.setActivityNo.assignment(tCtx, { data: 10 }).activityNo, 10)
|
|
105
|
-
assert.equal(tActions.setActivityDetail.assignment(tCtx, { data: { receiveStatus: 1 } }).activityDetail.receiveStatus, 1)
|
|
106
|
-
assert.equal(typeof tActions.setCallback.assignment(tCtx, { data: {} }).callback, 'function')
|
|
107
|
-
assert.ok(tActions.setDuration.assignment({ ...tCtx, activityDetail: { activityEndTime: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
|
|
108
|
-
assert.equal(tGuards.isReceivable({ ...tCtx, activityDetail: { receiveStatus: 2 } }, {}), true)
|
|
109
|
-
assert.equal(tGuards.isReceived({ ...tCtx, activityDetail: { receiveStatus: 1 } }, {}), true)
|
|
110
|
-
assert.equal(tGuards.isOngoing({ ...tCtx, activityDetail: { receiveStatus: 0 } }, {}), true)
|
|
111
|
-
await tServices.fetchActivityDetail({ ...tCtx, activityNo: 9 }, {})
|
|
112
|
-
await tServices.receiveReward({ ...tCtx, activityDetail: { activityNo: 9, receiveNo: '0' } }, {})
|
|
113
|
-
const tReward = await tServices.receiveReward({ ...tCtx, activityDetail: { activityNo: 9, receiveNo: '2' } }, {})
|
|
114
|
-
assert.equal(tReward.receiveNo, 2)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('deposit_activity and return_bonus_activity cover guards/filter/reward branches', async () => {
|
|
118
|
-
const request = {
|
|
119
|
-
config: { appSecret: 'secret' },
|
|
120
|
-
send: async (req) => {
|
|
121
|
-
if (req.url === 'activities') return { data: { achieveStatus: 1, deadline: Math.floor(Date.now() / 1000) + 100, rebateAmount: 0 } }
|
|
122
|
-
if (req.url === 'activities/rewards' && req.method === 'post') return { data: { ok: true, receiveNo: req.params.receiveNo } }
|
|
123
|
-
if (req.url === 'activities/rewards' && req.method === 'get')
|
|
124
|
-
return { data: [{ activityType: 4, receiveStatus: 0, activityNo: 3, receiveNo: '2' }] }
|
|
125
|
-
return { data: [] }
|
|
126
|
-
},
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const deposit = depositActivityFactory(request, { activityNo: 1 })
|
|
130
|
-
const dActions = deposit.options.actions
|
|
131
|
-
const dGuards = deposit.options.guards
|
|
132
|
-
const dServices = deposit.options.services
|
|
133
|
-
const dCtx = deposit.initialState.context
|
|
134
|
-
assert.equal(dActions.setActivityNo.assignment(dCtx, { data: 2 }).activityNo, 2)
|
|
135
|
-
assert.equal(dActions.setActivityDetail.assignment(dCtx, { data: { achieveStatus: 1 } }).activityDetail.achieveStatus, 1)
|
|
136
|
-
assert.ok(dActions.setDuration.assignment({ ...dCtx, activityDetail: { deadline: Math.floor(Date.now() / 1000) + 1 } }, {}).duration >= 0)
|
|
137
|
-
assert.equal(dGuards.isExpired({ ...dCtx, duration: 0 }, {}), true)
|
|
138
|
-
assert.equal(dGuards.isNotAvailable({ ...dCtx, activityDetail: { achieveStatus: 0 } }, {}), true)
|
|
139
|
-
await dServices.fetchActivityDetail({ ...dCtx, activityNo: 1 }, {})
|
|
140
|
-
|
|
141
|
-
const bonus = returnBonusActivityFactory(request)
|
|
142
|
-
const rActions = bonus.options.actions
|
|
143
|
-
const rGuards = bonus.options.guards
|
|
144
|
-
const rServices = bonus.options.services
|
|
145
|
-
const rCtx = bonus.initialState.context
|
|
146
|
-
assert.equal(rActions.setActivityNo.assignment(rCtx, { data: 10 }).activityNo, 10)
|
|
147
|
-
assert.equal(rActions.setActivityDetail.assignment(rCtx, { data: { rebateAmount: 10 } }).activityDetail.rebateAmount, 10)
|
|
148
|
-
const filtered = rActions.setRewardList.assignment(rCtx, {
|
|
149
|
-
data: [
|
|
150
|
-
{ activityType: 4, receiveStatus: 0, receiveNo: '2', activityNo: 3 },
|
|
151
|
-
{ activityType: 4, receiveStatus: 1, receiveNo: '3', activityNo: 4 },
|
|
152
|
-
],
|
|
153
|
-
})
|
|
154
|
-
assert.equal(filtered.rewardList.length, 1)
|
|
155
|
-
assert.equal(rActions.setRewardList.assignment(rCtx, { data: null }).rewardList.length, 0)
|
|
156
|
-
assert.equal(typeof rActions.setCallback.assignment(rCtx, { data: {} }).callback, 'function')
|
|
157
|
-
rActions.doCallback({ ...rCtx, callback: () => {} }, {})
|
|
158
|
-
assert.equal(rGuards.isActivityChanged({ ...rCtx, activityNo: 1 }, { data: 2 }), true)
|
|
159
|
-
assert.equal(rGuards.hasActivityNo({ ...rCtx, activityNo: 1 }, {}), 1)
|
|
160
|
-
assert.equal(rGuards.isReceivable({ ...rCtx, rewardList: [{}] }, {}), true)
|
|
161
|
-
assert.equal(rGuards.isNotReceivableYet({ ...rCtx, rewardList: [], activityDetail: { rebateAmount: 10 } }, {}), true)
|
|
162
|
-
await rServices.fetchActivityDetail({ ...rCtx, activityNo: 3 }, {})
|
|
163
|
-
const rr = await rServices.receiveReward({ ...rCtx, rewardList: [{ activityNo: 3, receiveNo: '2' }] }, {})
|
|
164
|
-
assert.equal(rr.receiveNo, 2)
|
|
165
|
-
const list = await rServices.fetchRewardList(rCtx, {})
|
|
166
|
-
assert.equal(list.length, 1)
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
test('welcome machine guards/actions/services cover first-login flow branches', async () => {
|
|
170
|
-
global.localStorage = createLocalStorageMock()
|
|
171
|
-
|
|
172
|
-
const sent = []
|
|
173
|
-
const request = {
|
|
174
|
-
send: async (req) => {
|
|
175
|
-
sent.push(req)
|
|
176
|
-
if (req.url === 'self' && req.method === 'get') return { uid: 'u1', topup: 0, verification_status: 0 }
|
|
177
|
-
if (req.url === 'payment/v2/setting') return { ok: true }
|
|
178
|
-
if (req.url === 'self' && req.method === 'post') return { ok: true }
|
|
179
|
-
return { data: {} }
|
|
180
|
-
},
|
|
181
|
-
}
|
|
182
|
-
const machine = welcomeFactory(request)
|
|
183
|
-
const actions = machine.options.actions
|
|
184
|
-
const guards = machine.options.guards
|
|
185
|
-
const services = machine.options.services
|
|
186
|
-
const ctx = machine.initialState.context
|
|
187
|
-
|
|
188
|
-
assert.equal(actions.setUserInfo.assignment(ctx, { data: { uid: 'u1' } }).userInfo.uid, 'u1')
|
|
189
|
-
assert.equal(actions.setBonus.assignment(ctx, { data: 5 }).bonus, 5)
|
|
190
|
-
assert.equal(actions.setGender.assignment(ctx, { data: 'M' }).gender, 'M')
|
|
191
|
-
actions.setInfo({ ...ctx, userInfo: { uid: 'u1' } }, {})
|
|
192
|
-
assert.equal(global.localStorage.getItem('welcome_u1') !== null, true)
|
|
193
|
-
|
|
194
|
-
global.localStorage.clear()
|
|
195
|
-
assert.equal(guards.isFirstLogin({ ...ctx, userInfo: { uid: 'u2', topup: 0, verification_status: 0 } }, {}), true)
|
|
196
|
-
assert.equal(guards.isFirstLogin({ ...ctx, userInfo: { uid: 'u2', topup: 1, verification_status: 0 } }, {}), false)
|
|
197
|
-
assert.equal(guards.isFilled({ ...ctx, bonus: 1, gender: 'F' }, {}), true)
|
|
198
|
-
assert.equal(guards.isFilled({ ...ctx, bonus: null, gender: 'F' }, {}), false)
|
|
199
|
-
|
|
200
|
-
const info = await services.fetchUserInfo(ctx, {})
|
|
201
|
-
assert.equal(info.uid, 'u1')
|
|
202
|
-
await services.updatingInfo({ ...ctx, bonus: 1, gender: 'M' }, {})
|
|
203
|
-
assert.equal(
|
|
204
|
-
sent.some((req) => req.url === 'payment/v2/setting'),
|
|
205
|
-
true
|
|
206
|
-
)
|
|
207
|
-
assert.equal(
|
|
208
|
-
sent.some((req) => req.url === 'self' && req.method === 'post'),
|
|
209
|
-
true
|
|
210
|
-
)
|
|
211
|
-
})
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import ambFactory from '../src/machine/deposit/amb.js'
|
|
5
|
-
import rewardFcFactory from '../src/machine/reward_fc.js'
|
|
6
|
-
import websocketFactory from '../src/machine/websocket.js'
|
|
7
|
-
|
|
8
|
-
test('deposit amb covers user account guard and initialization mapping', async () => {
|
|
9
|
-
const request = {
|
|
10
|
-
send: async (req) => {
|
|
11
|
-
if (req.url === 'payment/v2/paymentInfo') {
|
|
12
|
-
return {
|
|
13
|
-
bankInfo: [
|
|
14
|
-
{ bindingType: 'BANK', id: 1 },
|
|
15
|
-
{ bindingType: 'CRYPTO', id: 2 },
|
|
16
|
-
{ bindingType: 'EWALLET', id: 3 },
|
|
17
|
-
],
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (req.url === 'payment/v2/amb/transaction') {
|
|
21
|
-
return { accountName: 'House', accountNumber: '123', bankName: 'AMB Bank' }
|
|
22
|
-
}
|
|
23
|
-
if (req.url === 'payment/v2/amb/getBankList') {
|
|
24
|
-
return { data: [{ bankCode: 'AMB1' }] }
|
|
25
|
-
}
|
|
26
|
-
return {}
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const machine = ambFactory(request)
|
|
31
|
-
const actions = machine.options.actions
|
|
32
|
-
const guards = machine.options.guards
|
|
33
|
-
const services = machine.options.services
|
|
34
|
-
const ctx = machine.initialState.context
|
|
35
|
-
|
|
36
|
-
assert.equal(actions.setUserAccount.assignment(ctx, { data: [{ id: 1 }] }).userAccount.id, 1)
|
|
37
|
-
const initA = actions.setInitialization.assignment(ctx, {
|
|
38
|
-
data: {
|
|
39
|
-
houseAccount: { accountName: 'A', accountNumber: 'B', bankName: 'C' },
|
|
40
|
-
bankList: { data: [{ bankCode: 'X' }] },
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
assert.equal(initA.houseAccountName, 'A')
|
|
44
|
-
assert.equal(initA.bankList[0].bankCode, 'X')
|
|
45
|
-
const initB = actions.setInitialization.assignment(ctx, {
|
|
46
|
-
data: {
|
|
47
|
-
houseAccount: { accountName: 'A', accountNumber: 'B', bankName: 'C' },
|
|
48
|
-
bankList: [{ bankCode: 'Y' }],
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
assert.equal(initB.bankList[0].bankCode, 'Y')
|
|
52
|
-
|
|
53
|
-
assert.equal(guards.hasUserAccount(ctx, { data: [{ id: 1 }] }).id, 1)
|
|
54
|
-
assert.equal(guards.hasUserAccount(ctx, { data: [] }), undefined)
|
|
55
|
-
|
|
56
|
-
const paymentInfo = await services.fetchPaymentInfo(ctx, {})
|
|
57
|
-
assert.equal(paymentInfo.length, 1)
|
|
58
|
-
const init = await services.initialize(ctx, {})
|
|
59
|
-
assert.equal(init.houseAccount.accountName, 'House')
|
|
60
|
-
assert.equal(init.bankList.data[0].bankCode, 'AMB1')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('reward_fc covers setRewardList fallback and receive validation', async () => {
|
|
64
|
-
const request = {
|
|
65
|
-
config: { appSecret: 'secret' },
|
|
66
|
-
send: async (req) => {
|
|
67
|
-
if (req.url === 'activities/rewards' && req.method === 'get') return { data: [{ receiveNo: 1 }] }
|
|
68
|
-
if (req.url === 'activities/rewards' && req.method === 'post') return { ok: true, receiveNo: req.params.receiveNo }
|
|
69
|
-
return {}
|
|
70
|
-
},
|
|
71
|
-
}
|
|
72
|
-
const machine = rewardFcFactory(request)
|
|
73
|
-
const actions = machine.options.actions
|
|
74
|
-
const services = machine.options.services
|
|
75
|
-
const ctx = machine.initialState.context
|
|
76
|
-
|
|
77
|
-
assert.equal(actions.setRewardList.assignment(ctx, { data: null }).rewardList.length, 0)
|
|
78
|
-
assert.equal(actions.setRewardList.assignment(ctx, { data: [{ id: 1 }] }).rewardList.length, 1)
|
|
79
|
-
let called = 0
|
|
80
|
-
actions.doCallback({ ...ctx, callback: () => called++ }, {})
|
|
81
|
-
assert.equal(called, 1)
|
|
82
|
-
const fallbackCb = actions.setCallback.assignment(ctx, { data: {} }).callback
|
|
83
|
-
assert.equal(typeof fallbackCb, 'function')
|
|
84
|
-
assert.doesNotThrow(() => fallbackCb())
|
|
85
|
-
assert.equal(typeof actions.setCallback.assignment(ctx, { data: { callback: () => 1 } }).callback, 'function')
|
|
86
|
-
|
|
87
|
-
const list = await services.fetchRewardList(ctx, {})
|
|
88
|
-
assert.equal(list.length, 1)
|
|
89
|
-
const r0 = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '0', attended: false } })
|
|
90
|
-
assert.equal(r0.receiveNo, undefined)
|
|
91
|
-
const rBlank = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: ' ', attended: false } })
|
|
92
|
-
assert.equal(rBlank.receiveNo, undefined)
|
|
93
|
-
const r2 = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '2', attended: false } })
|
|
94
|
-
assert.equal(r2.receiveNo, 2)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test('websocket additional actions/listeners branches are covered', () => {
|
|
98
|
-
const request = {
|
|
99
|
-
config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', sentry: { captureException: () => {} } },
|
|
100
|
-
getToken: () => 't',
|
|
101
|
-
}
|
|
102
|
-
const machine = websocketFactory(request)
|
|
103
|
-
const actions = machine.options.actions
|
|
104
|
-
const ctx = machine.initialState.context
|
|
105
|
-
|
|
106
|
-
assert.equal(actions.saveSocketURL.assignment(ctx, { data: { socketURL: 'wss://new' } }).socketURL, 'wss://new')
|
|
107
|
-
assert.equal(actions.setConnecting.assignment(ctx, {}).connectStatus, 1)
|
|
108
|
-
|
|
109
|
-
let disconnected = false
|
|
110
|
-
const patched = actions.disconnectSocket.assignment({ ...ctx, clientSocket: { disconnect: () => (disconnected = true) } }, {})
|
|
111
|
-
assert.equal(disconnected, true)
|
|
112
|
-
assert.equal(patched.clientSocket, null)
|
|
113
|
-
|
|
114
|
-
const callbacks = []
|
|
115
|
-
const handlers = {}
|
|
116
|
-
const removed = []
|
|
117
|
-
const fakeSocket = {
|
|
118
|
-
id: 's1',
|
|
119
|
-
on: (event, fn) => (handlers[event] = fn),
|
|
120
|
-
off: (event) => removed.push(event),
|
|
121
|
-
}
|
|
122
|
-
const listen = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocket })
|
|
123
|
-
const cleanup = listen((event) => callbacks.push(event))
|
|
124
|
-
handlers['activity-reward-info']?.({ x: 1 })
|
|
125
|
-
handlers['message-notice-info']?.({ y: 1 })
|
|
126
|
-
handlers['payment-info']?.({ windowType: 'modal' })
|
|
127
|
-
assert.equal(
|
|
128
|
-
callbacks.some((e) => e.type === 'ACTIVITY_INFO'),
|
|
129
|
-
true
|
|
130
|
-
)
|
|
131
|
-
cleanup()
|
|
132
|
-
assert.equal(removed.includes('activity-info'), true)
|
|
133
|
-
assert.equal(removed.includes('disconnect'), true)
|
|
134
|
-
|
|
135
|
-
// null socket should safely no-op
|
|
136
|
-
assert.doesNotThrow(() => machine.options.services.listenToSocketEvents({ clientSocket: null })(() => {}))
|
|
137
|
-
|
|
138
|
-
// cleanup should no-op when socket.off is unavailable
|
|
139
|
-
const fakeSocketNoOff = { id: 's2', on: () => {} }
|
|
140
|
-
const cleanupNoOff = machine.options.services.listenToSocketEvents({ clientSocket: fakeSocketNoOff })(() => {})
|
|
141
|
-
assert.doesNotThrow(() => cleanupNoOff())
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('websocket connectSocket and fetchSocket fallback branches are covered', async () => {
|
|
145
|
-
let offCalled = 0
|
|
146
|
-
const socketIoConnect = () => {
|
|
147
|
-
const handlers = {}
|
|
148
|
-
const sock = {
|
|
149
|
-
id: 'sid-1',
|
|
150
|
-
on: (event, fn) => {
|
|
151
|
-
handlers[event] = fn
|
|
152
|
-
if (event === 'connect') setTimeout(() => handlers.connect?.(), 0)
|
|
153
|
-
},
|
|
154
|
-
off: () => {
|
|
155
|
-
offCalled += 1
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
return sock
|
|
159
|
-
}
|
|
160
|
-
const socketIoError = () => {
|
|
161
|
-
const handlers = {}
|
|
162
|
-
const sock = {
|
|
163
|
-
id: 'sid-2',
|
|
164
|
-
on: (event, fn) => {
|
|
165
|
-
handlers[event] = fn
|
|
166
|
-
if (event === 'connect_error') setTimeout(() => handlers.connect_error?.({ message: 'nope' }), 0)
|
|
167
|
-
},
|
|
168
|
-
}
|
|
169
|
-
return sock
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const requestConnect = {
|
|
173
|
-
config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', socketIo: socketIoConnect },
|
|
174
|
-
getToken: () => 'token',
|
|
175
|
-
}
|
|
176
|
-
const machineConnect = websocketFactory(requestConnect)
|
|
177
|
-
const connected = await machineConnect.options.services.connectSocket({ ...machineConnect.initialState.context, socketURL: 'wss://x' }, {})
|
|
178
|
-
assert.equal(connected.id, 'sid-1')
|
|
179
|
-
assert.equal(offCalled > 0, true)
|
|
180
|
-
|
|
181
|
-
const requestError = {
|
|
182
|
-
config: { socketURL: 'wss://x', bucketName: 'b', clientId: 'c', socketIo: socketIoError },
|
|
183
|
-
getToken: () => 'token',
|
|
184
|
-
}
|
|
185
|
-
const machineError = websocketFactory(requestError)
|
|
186
|
-
await assert.rejects(
|
|
187
|
-
() => machineError.options.services.connectSocket({ ...machineError.initialState.context, socketURL: 'wss://x' }, {}),
|
|
188
|
-
(error) => error === 'nope'
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
const originalFetch = global.fetch
|
|
192
|
-
global.fetch = async (url) => {
|
|
193
|
-
if (String(url).endsWith('target.json')) {
|
|
194
|
-
return { json: async () => ({ socket: ['https://dead-1', 'https://dead-2'] }) }
|
|
195
|
-
}
|
|
196
|
-
throw new Error('ping fail')
|
|
197
|
-
}
|
|
198
|
-
const fallback = await machineConnect.options.services.fetchSocket({ url: 'https://storage.googleapis.com/x/target.json' }, {})
|
|
199
|
-
assert.equal(fallback.socketURL, 'https://dead-1')
|
|
200
|
-
global.fetch = originalFetch
|
|
201
|
-
})
|