@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,185 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
import { interpret, State } from 'xstate'
|
|
4
|
-
|
|
5
|
-
import withdrawManualFactory from '../src/machine/withdraw/withdraw_manual.js'
|
|
6
|
-
|
|
7
|
-
function waitForMatch(service, matcher, timeout = 1000) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
if (matcher(service.state)) {
|
|
10
|
-
resolve(service.state)
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const timer = setTimeout(() => {
|
|
15
|
-
sub.unsubscribe()
|
|
16
|
-
reject(new Error('timeout waiting for state match'))
|
|
17
|
-
}, timeout)
|
|
18
|
-
|
|
19
|
-
const sub = service.subscribe((state) => {
|
|
20
|
-
if (matcher(state)) {
|
|
21
|
-
clearTimeout(timer)
|
|
22
|
-
sub.unsubscribe()
|
|
23
|
-
resolve(state)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test('withdraw_manual fills uncovered action branches and guards', () => {
|
|
30
|
-
const request = { config: { appSecret: 'secret' }, send: async () => ({}) }
|
|
31
|
-
const machine = withdrawManualFactory(request)
|
|
32
|
-
const actions = machine.options.actions
|
|
33
|
-
const guards = machine.options.guards
|
|
34
|
-
|
|
35
|
-
const noMatchRule = actions.updateWithdrawCondition.assignment(machine.initialState.context, {
|
|
36
|
-
data: {
|
|
37
|
-
enableWithdraw: true,
|
|
38
|
-
enableWithdrawAmount: '7',
|
|
39
|
-
currentWithdrawLimit: 0,
|
|
40
|
-
targetWithdrawLimit: 0,
|
|
41
|
-
balance: 10,
|
|
42
|
-
freeGameDetail: [],
|
|
43
|
-
freeGameExpired: false,
|
|
44
|
-
rules: [{ greaterEqualThen: 20, maxWithdrawAmount: 99 }],
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
assert.equal(noMatchRule.maxWithdrawAmount, 99)
|
|
48
|
-
|
|
49
|
-
const noRule = actions.updateWithdrawCondition.assignment(machine.initialState.context, {
|
|
50
|
-
data: {
|
|
51
|
-
enableWithdraw: true,
|
|
52
|
-
enableWithdrawAmount: '7',
|
|
53
|
-
currentWithdrawLimit: 0,
|
|
54
|
-
targetWithdrawLimit: 0,
|
|
55
|
-
balance: 10,
|
|
56
|
-
freeGameDetail: [],
|
|
57
|
-
freeGameExpired: false,
|
|
58
|
-
rules: [],
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
assert.equal(noRule.maxWithdrawAmount, 10)
|
|
62
|
-
const initData = actions.setInitData.assignment(machine.initialState.context, {
|
|
63
|
-
data: {
|
|
64
|
-
bindingPaymentList: { bankList: [{ bankCode: 'B1' }] },
|
|
65
|
-
bindingPaymentInfo: {
|
|
66
|
-
bankList: [{ bankCode: 'B1' }],
|
|
67
|
-
ewalletList: { bankCode: 'EW1' },
|
|
68
|
-
ignoredType: [{ bankCode: 'X1' }],
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
assert.equal(initData.boundBanks.length, 2)
|
|
73
|
-
assert.equal(initData.currentBank.bankCode, 'B1')
|
|
74
|
-
|
|
75
|
-
assert.equal(actions.setWithdrawRulePreview.assignment(machine.initialState.context, { data: { a: 1 } }).withdrawRule.a, 1)
|
|
76
|
-
assert.equal(actions.setAttachmentType.assignment(machine.initialState.context, { data: 'pool' }).attachmentType, 'pool')
|
|
77
|
-
assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: 88 }).amount, 88)
|
|
78
|
-
assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
|
|
79
|
-
assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { fee: 1 } } }).calculation, { fee: 1 })
|
|
80
|
-
assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { fee: 2 } }).calculation, { fee: 2 })
|
|
81
|
-
|
|
82
|
-
const otp = actions.setOtp.assignment(machine.initialState.context, {
|
|
83
|
-
data: { requestId: 'RID', status: 'otp-verifying', target: 'phone', ttl: 3 },
|
|
84
|
-
})
|
|
85
|
-
assert.equal(otp.requestId, 'RID')
|
|
86
|
-
assert.equal(otp.ttl, 3)
|
|
87
|
-
assert.equal(actions.decreaseTtl.assignment({ ttl: 3 }, {}).ttl, 2)
|
|
88
|
-
assert.equal(actions.decreaseTtl.assignment({ ttl: 0 }, {}).ttl, 0)
|
|
89
|
-
|
|
90
|
-
const verified = actions.setVerificationData.assignment(machine.initialState.context, { data: { requestId: 'R2', ttl: 9, target: 'email' } })
|
|
91
|
-
assert.equal(verified.requestId, 'R2')
|
|
92
|
-
assert.equal(verified.target, 'email')
|
|
93
|
-
|
|
94
|
-
assert.equal(
|
|
95
|
-
guards.isAvailableAmount({
|
|
96
|
-
paymentDetail: [{ minimum: 10, maximum: 100 }],
|
|
97
|
-
currentBank: { bankCode: 'B1' },
|
|
98
|
-
amount: 20,
|
|
99
|
-
userInfo: { balance: 15 },
|
|
100
|
-
}),
|
|
101
|
-
false
|
|
102
|
-
)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test('withdraw_manual stateflow covers withdrawCheck assign, pool cond and submitted entry', async () => {
|
|
106
|
-
const sent = []
|
|
107
|
-
const request = {
|
|
108
|
-
config: { appSecret: 'secret' },
|
|
109
|
-
send: async (req) => {
|
|
110
|
-
sent.push(req.url)
|
|
111
|
-
if (req.url?.includes('getBindingPaymentList')) {
|
|
112
|
-
return { bankList: [{ bankCode: 'B1' }] }
|
|
113
|
-
}
|
|
114
|
-
if (req.url?.includes('getBindingPaymentInfo')) {
|
|
115
|
-
return { bankList: [{ bankCode: 'B1', bindingType: 'BANK', accountNumber: '123', branch: 'Main' }] }
|
|
116
|
-
}
|
|
117
|
-
if (req.url?.includes('withdrawRule')) {
|
|
118
|
-
return { balance: 100, enableWithdraw: true, enableWithdrawAmount: 10, rules: [] }
|
|
119
|
-
}
|
|
120
|
-
if (req.url?.includes('withdrawCheck')) {
|
|
121
|
-
return {
|
|
122
|
-
passDepositeLimit: true,
|
|
123
|
-
passWithdrawCooldownTime: true,
|
|
124
|
-
withdrawInServiceTime: true,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (req.url?.includes('manual/transaction')) {
|
|
128
|
-
return { applyId: 42, balance: 777, realAmount: 760, charge: 17, status: 'ok' }
|
|
129
|
-
}
|
|
130
|
-
if (req.url?.includes('paymentDetail')) {
|
|
131
|
-
return [{ minimum: 1, maximum: 999, processing: [] }]
|
|
132
|
-
}
|
|
133
|
-
if (req.url?.includes('restore')) return { ok: true }
|
|
134
|
-
return {}
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const machine = withdrawManualFactory(request)
|
|
139
|
-
|
|
140
|
-
const s1 = interpret(machine).start()
|
|
141
|
-
await waitForMatch(s1, (state) => state.matches('pending'))
|
|
142
|
-
s1.send({ type: 'SET_MODE', data: 'main' })
|
|
143
|
-
const withdrawable = await waitForMatch(s1, (state) => state.matches({ cash: 'withdrawable' }), 2000)
|
|
144
|
-
assert.equal(withdrawable.context.withdrawCheck.withdrawInServiceTime, true)
|
|
145
|
-
s1.send({
|
|
146
|
-
type: 'SET_CURRENT_BANK',
|
|
147
|
-
data: { bankCode: 'B2', bindingType: 'BANK', accountNumber: '123', branch: 'Main', method: 'manual' },
|
|
148
|
-
})
|
|
149
|
-
assert.equal(s1.state.context.currentBank.bankCode, 'B2')
|
|
150
|
-
s1.send({ type: 'SET_AMOUNT', data: 12 })
|
|
151
|
-
s1.send({ type: 'SET_ATTACHMENT_TYPE', data: 'pool' })
|
|
152
|
-
s1.send({ type: 'SUBMIT' })
|
|
153
|
-
await waitForMatch(s1, (state) => state.matches({ cash: 'pooled' }))
|
|
154
|
-
s1.stop()
|
|
155
|
-
|
|
156
|
-
const s3 = interpret(machine).start(
|
|
157
|
-
State.from(
|
|
158
|
-
{ cash: 'withdrawable' },
|
|
159
|
-
{
|
|
160
|
-
...machine.initialState.context,
|
|
161
|
-
attachmentType: 'withdraw',
|
|
162
|
-
amount: 20,
|
|
163
|
-
userInfo: { balance: 100 },
|
|
164
|
-
paymentDetail: [{ minimum: 1, maximum: 999, processing: [], method: 'manual' }],
|
|
165
|
-
currentBank: {
|
|
166
|
-
bankCode: 'B1',
|
|
167
|
-
bindingType: 'BANK',
|
|
168
|
-
accountNumber: '123',
|
|
169
|
-
ifscCode: 'IFSC',
|
|
170
|
-
branch: 'Main',
|
|
171
|
-
holderName: 'H',
|
|
172
|
-
},
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
)
|
|
176
|
-
s3.send({ type: 'SUBMIT' })
|
|
177
|
-
const inProcessing = await waitForMatch(s3, (state) => state.matches({ cash: 'inProcessing' }))
|
|
178
|
-
assert.equal(inProcessing.context.applyId, 42)
|
|
179
|
-
assert.equal(inProcessing.context.realAmount, 760)
|
|
180
|
-
assert.equal(
|
|
181
|
-
sent.some((url) => url?.includes('manual/transaction')),
|
|
182
|
-
true
|
|
183
|
-
)
|
|
184
|
-
s3.stop()
|
|
185
|
-
})
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import withdrawManualCashFactory from '../src/machine/withdraw/withdraw_manual_cash.js'
|
|
5
|
-
|
|
6
|
-
test('withdraw_manual_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/getBindingPaymentInfo') {
|
|
12
|
-
return {
|
|
13
|
-
bankList: [{ bankCode: 'KB', accountNumber: '123', branch: 'B1', holderName: 'Tony' }],
|
|
14
|
-
cryptoList: [{ cryptoCurrency: 'USDT', cryptoNetwork: 'TRC20', cryptoAddress: 'ADDR', holderName: 'Tony' }],
|
|
15
|
-
ewalletList: [{ walletCode: 'W1', accountNumber: '999', holderName: 'Tony' }],
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (req.url === 'payment/v2/withdrawRule') {
|
|
19
|
-
return { balance: 900 }
|
|
20
|
-
}
|
|
21
|
-
if (req.url === 'payment/v2/pendingOrder') {
|
|
22
|
-
return [{ applyId: 'P-1' }]
|
|
23
|
-
}
|
|
24
|
-
if (req.url === 'payment/v2/manual_cash/transaction') {
|
|
25
|
-
return { status: 'otp-verifying', requestId: 'RID-1', target: 'phone', ttl: 60 }
|
|
26
|
-
}
|
|
27
|
-
if (req.url === '/otpsso/reset') {
|
|
28
|
-
return { requestId: 'RID-2', ttl: 30, target: 'email' }
|
|
29
|
-
}
|
|
30
|
-
if (req.url === '/otpsso/acknowledge') {
|
|
31
|
-
return { ok: true }
|
|
32
|
-
}
|
|
33
|
-
return {}
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const machine = withdrawManualCashFactory(request, {
|
|
38
|
-
paymentDetail: [{ category: 'manual', transferType: 'withdraw', method: 'manual_cash', minimum: 100, maximum: 1000 }],
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const { actions, guards, services } = machine.options
|
|
42
|
-
const initial = machine.initialState.context
|
|
43
|
-
|
|
44
|
-
const init = await services.fetchInitData(initial)
|
|
45
|
-
assert.equal(init.currentPayment.method, 'manual_cash')
|
|
46
|
-
assert.equal(init.processing.applyId, 'P-1')
|
|
47
|
-
|
|
48
|
-
const initData = actions.setInitData.assignment(initial, { data: init })
|
|
49
|
-
assert.equal(initData.userBanks.length, 3)
|
|
50
|
-
assert.equal(initData.selectedUserBank.bankCode, 'KB')
|
|
51
|
-
assert.equal(initData.withdrawRule.balance, 900)
|
|
52
|
-
|
|
53
|
-
assert.equal(actions.setAmount.assignment(initial, { data: 456 }).selectedAmount, 456)
|
|
54
|
-
assert.equal(actions.setUserBank.assignment(initial, { data: { bankCode: 'GCASH' } }).selectedUserBank.bankCode, 'GCASH')
|
|
55
|
-
assert.equal(actions.setProcessing.assignment(initial, { data: { applyId: 'P-2' } }).processing.applyId, 'P-2')
|
|
56
|
-
|
|
57
|
-
const otp = actions.setOtp.assignment(initial, { data: { requestId: 'RID-1', status: 'otp-verifying', target: 'phone', ttl: 60 } })
|
|
58
|
-
assert.equal(otp.requestId, 'RID-1')
|
|
59
|
-
assert.equal(otp.status, 'otp-verifying')
|
|
60
|
-
assert.equal(otp.target, 'phone')
|
|
61
|
-
assert.equal(otp.ttl, 60)
|
|
62
|
-
|
|
63
|
-
assert.equal(actions.decreaseTtl.assignment({ ttl: 2 }, {}).ttl, 1)
|
|
64
|
-
assert.equal(actions.decreaseTtl.assignment({ ttl: 0 }, {}).ttl, 0)
|
|
65
|
-
|
|
66
|
-
const verification = actions.setVerificationData.assignment(initial, { data: { requestId: 'RID-2', ttl: 30, target: 'email' } })
|
|
67
|
-
assert.equal(verification.requestId, 'RID-2')
|
|
68
|
-
assert.equal(verification.ttl, 30)
|
|
69
|
-
assert.equal(verification.target, 'email')
|
|
70
|
-
|
|
71
|
-
assert.equal(guards.hasNoBank({ userBanks: [] }), true)
|
|
72
|
-
assert.equal(guards.hasNoBank({ userBanks: [{}] }), false)
|
|
73
|
-
assert.equal(guards.isProcessing({ processing: null }), null)
|
|
74
|
-
assert.equal(guards.isProcessing({ processing: { applyId: 'P-1' } }).applyId, 'P-1')
|
|
75
|
-
assert.equal(guards.isSubmittable({ currentPayment: { minimum: 100, maximum: 1000 }, selectedUserBank: {}, selectedAmount: 300 }), true)
|
|
76
|
-
assert.equal(guards.isSubmittable({ currentPayment: { minimum: 100, maximum: 1000 }, selectedUserBank: {}, selectedAmount: 50 }), false)
|
|
77
|
-
assert.equal(guards.isOtpRequired({}, { data: { status: 'otp-verifying' } }), true)
|
|
78
|
-
assert.equal(guards.isOtpRequired({}, { data: { status: 'done' } }), false)
|
|
79
|
-
|
|
80
|
-
const submitNormal = await services.submitWithdraw({
|
|
81
|
-
currentPayment: { method: 'manual_cash' },
|
|
82
|
-
selectedUserBank: { bankCode: 'KB', accountNumber: '123', ifscCode: 'IFSC', branch: 'B1', holderName: 'Tony' },
|
|
83
|
-
selectedAmount: 200,
|
|
84
|
-
})
|
|
85
|
-
assert.equal(submitNormal.status, 'otp-verifying')
|
|
86
|
-
|
|
87
|
-
await services.submitWithdraw({
|
|
88
|
-
currentPayment: { method: 'manual_cash' },
|
|
89
|
-
selectedUserBank: { bankCode: 'GCASH', accountNumber: '456', ifscCode: '', branch: 'SHOULD_CLEAR', holderName: 'Tony' },
|
|
90
|
-
selectedAmount: 201,
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
await services.submitWithdrawCrypto({
|
|
94
|
-
currentPayment: { method: 'manual_cash' },
|
|
95
|
-
selectedUserBank: { cryptoCurrency: 'USDT', cryptoNetwork: 'TRC20', cryptoAddress: 'ADDR', holderName: 'Tony' },
|
|
96
|
-
selectedAmount: 202,
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
const reset = await services.resetOtp({ requestId: 'RID-1', target: 'phone' })
|
|
100
|
-
assert.equal(reset.requestId, 'RID-2')
|
|
101
|
-
|
|
102
|
-
const ack = await services.acknowledge({ requestId: 'RID-2', target: 'email' }, { data: '123456' })
|
|
103
|
-
assert.equal(ack.ok, true)
|
|
104
|
-
|
|
105
|
-
const ruleReq = sent.find((entry) => entry.url === 'payment/v2/withdrawRule')
|
|
106
|
-
assert.equal(ruleReq.params.walletType, 'CASH')
|
|
107
|
-
|
|
108
|
-
const submitReqKB = sent.find((entry) => entry.url === 'payment/v2/manual_cash/transaction' && entry.params.amount === 200)
|
|
109
|
-
assert.equal(submitReqKB.params.branch, 'B1')
|
|
110
|
-
|
|
111
|
-
const submitReqGCASH = sent.find((entry) => entry.url === 'payment/v2/manual_cash/transaction' && entry.params.amount === 201)
|
|
112
|
-
assert.equal(submitReqGCASH.params.branch, '')
|
|
113
|
-
|
|
114
|
-
const submitReqCrypto = sent.find((entry) => entry.url === 'payment/v2/manual_cash/transaction' && entry.params.amount === 202)
|
|
115
|
-
assert.equal(submitReqCrypto.params.cryptoCurrency, 'USDT')
|
|
116
|
-
assert.equal(submitReqCrypto.params.targetAddress, 'ADDR')
|
|
117
|
-
|
|
118
|
-
const resetReq = sent.find((entry) => entry.url === '/otpsso/reset')
|
|
119
|
-
assert.equal(resetReq.params.requestId, 'RID-1')
|
|
120
|
-
|
|
121
|
-
const ackReq = sent.find((entry) => entry.url === '/otpsso/acknowledge')
|
|
122
|
-
assert.equal(ackReq.params.code, '123456')
|
|
123
|
-
})
|
package/test/request.test.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import Config from '../src/request/config.js'
|
|
5
|
-
import Request from '../src/request/request.js'
|
|
6
|
-
import { createAxiosMock, createLocalStorageMock } from './helpers.js'
|
|
7
|
-
|
|
8
|
-
function createConfig() {
|
|
9
|
-
return new Config({
|
|
10
|
-
apiURL: 'https://api.example.com',
|
|
11
|
-
apiVersion: 'v2',
|
|
12
|
-
clientId: 'cid',
|
|
13
|
-
appSecret: 'secret',
|
|
14
|
-
platform: 'web',
|
|
15
|
-
version: '1.2.3',
|
|
16
|
-
fpToken: 'fp',
|
|
17
|
-
sentry: {
|
|
18
|
-
captureException: () => {},
|
|
19
|
-
setTag: () => {},
|
|
20
|
-
},
|
|
21
|
-
defaultChannel: 'channel',
|
|
22
|
-
defaultSubchannel: 'subchannel',
|
|
23
|
-
socketURL: 'wss://socket.example.com',
|
|
24
|
-
bucketName: 'bucket',
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
test('request initializes serializers and request headers', async () => {
|
|
29
|
-
global.localStorage = createLocalStorageMock()
|
|
30
|
-
localStorage.setItem('cuora_cid', JSON.stringify({ value: 'token-123' }))
|
|
31
|
-
|
|
32
|
-
const { axios, handlers } = createAxiosMock()
|
|
33
|
-
const request = new Request(axios, createConfig())
|
|
34
|
-
|
|
35
|
-
const serialized = axios.defaults.paramsSerializer({ q: 'a b!', empty: null, page: 1 })
|
|
36
|
-
assert.equal(serialized, 'q=a%20b%21&page=1')
|
|
37
|
-
|
|
38
|
-
const config = await handlers.requestSuccess({ headers: {} })
|
|
39
|
-
assert.equal(config.headers['X-TH1GAMES-VERSION'], '1.2.3')
|
|
40
|
-
assert.equal(config.headers['X-TH1GAMES-PLATFORM'], 'web')
|
|
41
|
-
assert.equal(config.headers.Authorization, 'Bearer token-123')
|
|
42
|
-
|
|
43
|
-
assert.equal(request.getToken(), 'token-123')
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('request interceptor reads token once per request', async () => {
|
|
47
|
-
global.localStorage = createLocalStorageMock()
|
|
48
|
-
localStorage.setItem('cuora_cid', JSON.stringify({ value: 'token-once' }))
|
|
49
|
-
|
|
50
|
-
const { axios, handlers } = createAxiosMock()
|
|
51
|
-
const request = new Request(axios, createConfig())
|
|
52
|
-
let tokenReadCount = 0
|
|
53
|
-
const originalGetToken = request.getToken.bind(request)
|
|
54
|
-
request.getToken = () => {
|
|
55
|
-
tokenReadCount += 1
|
|
56
|
-
return originalGetToken()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const config = await handlers.requestSuccess({ headers: {} })
|
|
60
|
-
assert.equal(config.headers.Authorization, 'Bearer token-once')
|
|
61
|
-
assert.equal(tokenReadCount, 1)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('request creates config with params/data and v2 url conversion', () => {
|
|
65
|
-
global.localStorage = createLocalStorageMock()
|
|
66
|
-
localStorage.setItem('cuora_cid', JSON.stringify({ value: 'token-456' }))
|
|
67
|
-
|
|
68
|
-
const { axios } = createAxiosMock()
|
|
69
|
-
const request = new Request(axios, createConfig())
|
|
70
|
-
|
|
71
|
-
const getConfig = request._createConfig(
|
|
72
|
-
{
|
|
73
|
-
method: 'get',
|
|
74
|
-
url: 'activities/cashRain',
|
|
75
|
-
params: { keep: 1, removeMe: undefined, keepFalse: false },
|
|
76
|
-
isPublic: true,
|
|
77
|
-
headers: { foo: 'bar' },
|
|
78
|
-
},
|
|
79
|
-
{ token: 'token' }
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
assert.equal(getConfig.url, 'activities/cash-rain/exchange')
|
|
83
|
-
assert.deepEqual(getConfig.params, { keep: 1, keepFalse: false })
|
|
84
|
-
|
|
85
|
-
const postConfig = request._createConfig(
|
|
86
|
-
{
|
|
87
|
-
method: 'post',
|
|
88
|
-
url: 'gameSearchTrace',
|
|
89
|
-
params: { amount: 10 },
|
|
90
|
-
isPublic: false,
|
|
91
|
-
headers: { foo: 'bar' },
|
|
92
|
-
},
|
|
93
|
-
{ token: 'token' }
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
assert.deepEqual(postConfig.data, { amount: 10 })
|
|
97
|
-
assert.equal(postConfig.url, 'gameSearchTrace')
|
|
98
|
-
|
|
99
|
-
assert.equal(request._convertUrlToKebabCase('userInfo/getProfile'), 'user-info/get-profile')
|
|
100
|
-
|
|
101
|
-
const dynamicConfig = request._createConfig(
|
|
102
|
-
{
|
|
103
|
-
method: 'get',
|
|
104
|
-
url: 'callback/google',
|
|
105
|
-
params: { state: 'ok' },
|
|
106
|
-
isPublic: true,
|
|
107
|
-
},
|
|
108
|
-
{ token: 'token' }
|
|
109
|
-
)
|
|
110
|
-
assert.equal(dynamicConfig.url, 'callback/google')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('request handles token checks and maintenance errors', async () => {
|
|
114
|
-
global.localStorage = createLocalStorageMock()
|
|
115
|
-
const { axios } = createAxiosMock()
|
|
116
|
-
const request = new Request(axios, createConfig())
|
|
117
|
-
|
|
118
|
-
await assert.rejects(
|
|
119
|
-
async () => {
|
|
120
|
-
await request.send({ method: 'get', url: 'self', params: {}, isPublic: false })
|
|
121
|
-
},
|
|
122
|
-
(error) => error.code === 'ERR_A103'
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
let handledError = null
|
|
126
|
-
request.setErrorHandler((error) => {
|
|
127
|
-
handledError = error
|
|
128
|
-
})
|
|
129
|
-
axios.request = async () => {
|
|
130
|
-
throw { code: 'ERR_F108' }
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
await assert.rejects(
|
|
134
|
-
async () => {
|
|
135
|
-
await request.send({ method: 'get', url: 'self', params: {}, isPublic: true })
|
|
136
|
-
},
|
|
137
|
-
(error) => error.code === 'ERR_F108'
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
assert.equal(request.isBlocked, true)
|
|
141
|
-
assert.deepEqual(handledError, { code: 'ERR_F108' })
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('request rethrows unknown errors without error.code', async () => {
|
|
145
|
-
global.localStorage = createLocalStorageMock()
|
|
146
|
-
const { axios } = createAxiosMock()
|
|
147
|
-
const request = new Request(axios, createConfig())
|
|
148
|
-
const rawError = new Error('unknown')
|
|
149
|
-
axios.request = async () => {
|
|
150
|
-
throw rawError
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
await assert.rejects(
|
|
154
|
-
async () => {
|
|
155
|
-
await request.send({ method: 'get', url: 'self', params: {}, isPublic: true })
|
|
156
|
-
},
|
|
157
|
-
(error) => error === rawError
|
|
158
|
-
)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('request response interceptor maps network error to ERR_998', async () => {
|
|
162
|
-
global.localStorage = createLocalStorageMock()
|
|
163
|
-
const sentry = {
|
|
164
|
-
captured: null,
|
|
165
|
-
captureException(payload) {
|
|
166
|
-
this.captured = payload
|
|
167
|
-
},
|
|
168
|
-
setTag: () => {},
|
|
169
|
-
}
|
|
170
|
-
const config = createConfig()
|
|
171
|
-
config.sentry = sentry
|
|
172
|
-
|
|
173
|
-
const { axios, handlers } = createAxiosMock()
|
|
174
|
-
new Request(axios, config)
|
|
175
|
-
|
|
176
|
-
await assert.rejects(
|
|
177
|
-
async () => {
|
|
178
|
-
await handlers.responseError({ message: 'Network Error' })
|
|
179
|
-
},
|
|
180
|
-
(error) => error.code === 'ERR_998'
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
assert.equal(sentry.captured, 'ERR_998:Network Error')
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
test('request response interceptor maps 404 message to ERR_998', async () => {
|
|
187
|
-
global.localStorage = createLocalStorageMock()
|
|
188
|
-
const sentry = {
|
|
189
|
-
captured: null,
|
|
190
|
-
captureException(payload) {
|
|
191
|
-
this.captured = payload
|
|
192
|
-
},
|
|
193
|
-
setTag: () => {},
|
|
194
|
-
}
|
|
195
|
-
const config = createConfig()
|
|
196
|
-
config.sentry = sentry
|
|
197
|
-
const { axios, handlers } = createAxiosMock()
|
|
198
|
-
new Request(axios, config)
|
|
199
|
-
|
|
200
|
-
await assert.rejects(
|
|
201
|
-
async () => {
|
|
202
|
-
await handlers.responseError({ message: 'Request failed with status code 404' })
|
|
203
|
-
},
|
|
204
|
-
(error) => error.code === 'ERR_998'
|
|
205
|
-
)
|
|
206
|
-
assert.equal(sentry.captured, 'ERR_998:Request failed with status code 404')
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
test('request response interceptor keeps backend error payload and raw errors', async () => {
|
|
210
|
-
global.localStorage = createLocalStorageMock()
|
|
211
|
-
const { axios, handlers } = createAxiosMock()
|
|
212
|
-
new Request(axios, createConfig())
|
|
213
|
-
|
|
214
|
-
await assert.rejects(
|
|
215
|
-
async () => {
|
|
216
|
-
await handlers.responseError({ response: { data: { error: { code: 'ERR_BACKEND' } } } })
|
|
217
|
-
},
|
|
218
|
-
(error) => error.code === 'ERR_BACKEND'
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
const rawError = { message: 'boom' }
|
|
222
|
-
await assert.rejects(
|
|
223
|
-
async () => {
|
|
224
|
-
await handlers.responseError(rawError)
|
|
225
|
-
},
|
|
226
|
-
(error) => error === rawError
|
|
227
|
-
)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
test('request response success interceptor rejects when payload has error', async () => {
|
|
231
|
-
global.localStorage = createLocalStorageMock()
|
|
232
|
-
const { axios, handlers } = createAxiosMock()
|
|
233
|
-
new Request(axios, createConfig())
|
|
234
|
-
|
|
235
|
-
await assert.rejects(
|
|
236
|
-
async () => {
|
|
237
|
-
await handlers.responseSuccess({ data: { error: { code: 'ERR_X' } } })
|
|
238
|
-
},
|
|
239
|
-
(error) => error.code === 'ERR_X'
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
const ok = await handlers.responseSuccess({ data: { ok: true } })
|
|
243
|
-
assert.deepEqual(ok.data, { ok: true })
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('request throws explicit error when blocked by maintenance mode', async () => {
|
|
247
|
-
global.localStorage = createLocalStorageMock()
|
|
248
|
-
const { axios } = createAxiosMock()
|
|
249
|
-
const request = new Request(axios, createConfig())
|
|
250
|
-
request.isBlocked = true
|
|
251
|
-
|
|
252
|
-
await assert.rejects(
|
|
253
|
-
async () => {
|
|
254
|
-
await request.send({ method: 'get', url: 'self', params: {}, isPublic: true })
|
|
255
|
-
},
|
|
256
|
-
(error) => error.code === 'ERR_MAINTENANCE_BLOCKED' && error.url === 'self'
|
|
257
|
-
)
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
test('request allows getConfig even in maintenance mode', async () => {
|
|
261
|
-
global.localStorage = createLocalStorageMock()
|
|
262
|
-
const { axios } = createAxiosMock()
|
|
263
|
-
const request = new Request(axios, createConfig())
|
|
264
|
-
request.isBlocked = true
|
|
265
|
-
|
|
266
|
-
const result = await request.send({ method: 'get', url: 'getConfig', params: {}, isPublic: true })
|
|
267
|
-
assert.deepEqual(result, { ok: true })
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
test('request allows get-config even in maintenance mode', async () => {
|
|
271
|
-
global.localStorage = createLocalStorageMock()
|
|
272
|
-
const { axios } = createAxiosMock()
|
|
273
|
-
const request = new Request(axios, createConfig())
|
|
274
|
-
request.isBlocked = true
|
|
275
|
-
|
|
276
|
-
const result = await request.send({ method: 'get', url: 'get-config', params: {}, isPublic: true })
|
|
277
|
-
assert.deepEqual(result, { ok: true })
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
test('request swallows ERR_800 without throwing', async () => {
|
|
281
|
-
global.localStorage = createLocalStorageMock()
|
|
282
|
-
const { axios } = createAxiosMock()
|
|
283
|
-
const request = new Request(axios, createConfig())
|
|
284
|
-
axios.request = async () => {
|
|
285
|
-
throw { code: 'ERR_800' }
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const result = await request.send({ method: 'get', url: 'self', params: {}, isPublic: true })
|
|
289
|
-
assert.equal(result, undefined)
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
test('sourceUpdate and sourceGenerate create fresh cancel sources', () => {
|
|
293
|
-
global.localStorage = createLocalStorageMock()
|
|
294
|
-
const { axios } = createAxiosMock()
|
|
295
|
-
const request = new Request(axios, createConfig())
|
|
296
|
-
|
|
297
|
-
const oldToken = request.source.token
|
|
298
|
-
request.sourceUpdate()
|
|
299
|
-
assert.notEqual(request.source.token, oldToken)
|
|
300
|
-
|
|
301
|
-
const customSource = request.sourceGenerate()
|
|
302
|
-
assert.ok(customSource.token)
|
|
303
|
-
assert.equal(typeof customSource.cancel, 'function')
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
test('request _createConfig supports form-data requests', () => {
|
|
307
|
-
global.localStorage = createLocalStorageMock()
|
|
308
|
-
const { axios } = createAxiosMock()
|
|
309
|
-
const request = new Request(axios, createConfig())
|
|
310
|
-
|
|
311
|
-
const formConfig = request._createConfig(
|
|
312
|
-
{
|
|
313
|
-
method: 'post',
|
|
314
|
-
url: 'uploadCommonSlip',
|
|
315
|
-
params: { file: 'mock' },
|
|
316
|
-
isPublic: false,
|
|
317
|
-
isFormData: true,
|
|
318
|
-
},
|
|
319
|
-
{ token: 'token' }
|
|
320
|
-
)
|
|
321
|
-
|
|
322
|
-
assert.equal(formConfig.url, 'uploadCommonSlip')
|
|
323
|
-
assert.equal(formConfig.headers['Content-Type'], 'multipart/form-data')
|
|
324
|
-
assert.deepEqual(formConfig.data, { file: 'mock' })
|
|
325
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import storage from '../src/util/storage.js'
|
|
5
|
-
|
|
6
|
-
test('storage returns null when localStorage get throws', () => {
|
|
7
|
-
const errors = []
|
|
8
|
-
const originalError = console.error
|
|
9
|
-
console.error = (...args) => errors.push(args)
|
|
10
|
-
|
|
11
|
-
global.localStorage = {
|
|
12
|
-
getItem() {
|
|
13
|
-
throw new Error('get fail')
|
|
14
|
-
},
|
|
15
|
-
setItem() {},
|
|
16
|
-
removeItem() {},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
assert.equal(storage.get('k'), null)
|
|
20
|
-
assert.equal(errors.length > 0, true)
|
|
21
|
-
|
|
22
|
-
console.error = originalError
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('storage set/remove swallow localStorage exceptions', () => {
|
|
26
|
-
const errors = []
|
|
27
|
-
const originalError = console.error
|
|
28
|
-
console.error = (...args) => errors.push(args)
|
|
29
|
-
|
|
30
|
-
global.localStorage = {
|
|
31
|
-
getItem() {
|
|
32
|
-
return null
|
|
33
|
-
},
|
|
34
|
-
setItem() {
|
|
35
|
-
throw new Error('set fail')
|
|
36
|
-
},
|
|
37
|
-
removeItem() {
|
|
38
|
-
throw new Error('remove fail')
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
storage.set('k', 'v')
|
|
43
|
-
storage.remove('k')
|
|
44
|
-
assert.equal(errors.length >= 2, true)
|
|
45
|
-
|
|
46
|
-
console.error = originalError
|
|
47
|
-
})
|