@jetthai/cuora 1.2.0 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +36 -0
- package/package.json +5 -2
- package/resetGitBranch.sh +16 -16
- package/src/api/account.js +8 -0
- package/src/api/auth.js +1 -1
- package/src/api/common.js +6 -1
- package/src/api/index.js +3 -1
- package/src/api/otp.js +5 -0
- package/src/api/user.js +1 -0
- package/src/machine/activity/activity.js +23 -19
- package/src/machine/activity/activity_cash.js +27 -22
- package/src/machine/activity/cash_rain_activity.js +1 -0
- package/src/machine/activity/continue_deposit_activity.js +1 -0
- package/src/machine/activity/deposit_activity.js +1 -0
- package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
- package/src/machine/activity/fafafa_activity.js +1 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +1 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +1 -0
- package/src/machine/activity/otp_verified_activity.js +1 -0
- package/src/machine/activity/ranking_activity.js +1 -0
- package/src/machine/activity/return_bonus_activity.js +3 -1
- package/src/machine/activity/roulette_activity_v2.js +6 -0
- package/src/machine/activity/sign_in_activity.js +1 -0
- package/src/machine/activity/sign_in_monthly_activity.js +2 -1
- package/src/machine/activity/specify_bets_activity.js +1 -0
- package/src/machine/activity/specify_turnover_activity.js +1 -0
- package/src/machine/activity/time_bomb_activity.js +1 -0
- package/src/machine/activity/vip_card_activity.js +1 -0
- package/src/machine/auth.js +21 -8
- package/src/machine/auth_otp_v2.js +1 -0
- package/src/machine/auth_otp_v3.js +48 -11
- package/src/machine/bank_binding.js +1 -0
- package/src/machine/bank_binding_amb.js +1 -0
- package/src/machine/bonus.js +1 -0
- package/src/machine/common.js +41 -7
- package/src/machine/deposit/amb.js +1 -0
- package/src/machine/deposit/crypto_bank.js +20 -5
- package/src/machine/deposit/crypto_bank_cash.js +35 -9
- package/src/machine/deposit/crypto_qrcode.js +11 -1
- package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
- package/src/machine/deposit/crypto_way.js +11 -5
- package/src/machine/deposit/crypto_way_cash.js +15 -6
- package/src/machine/deposit/deposit_fc.js +1 -0
- package/src/machine/deposit/direct.js +1 -0
- package/src/machine/deposit/direct_cash.js +1 -0
- package/src/machine/deposit/float.js +1 -0
- package/src/machine/deposit/krway.js +1 -0
- package/src/machine/deposit/loadcard_cash.js +2 -1
- package/src/machine/deposit/loadcard_vn.js +1 -0
- package/src/machine/deposit/manual_cash.js +18 -10
- package/src/machine/deposit/manual_vn.js +10 -5
- package/src/machine/deposit/qrcode_cash.js +6 -5
- package/src/machine/deposit/qrcode_v2.js +1 -0
- package/src/machine/deposit/usdt.js +23 -4
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +11 -9
- package/src/machine/deposit/virtual_bank_vn.js +1 -0
- package/src/machine/deposit/vpay.js +7 -0
- package/src/machine/error.js +1 -0
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +14 -2
- package/src/machine/game_info.js +5 -0
- package/src/machine/game_replay.js +1 -0
- package/src/machine/game_search_cash.js +13 -2
- package/src/machine/game_search_v2.js +1 -0
- package/src/machine/game_v2_1.js +129 -50
- package/src/machine/honor_board.js +19 -7
- package/src/machine/honor_board_cash.js +11 -8
- package/src/machine/inbox.js +93 -43
- package/src/machine/leaderboard.js +1 -0
- package/src/machine/merge.js +1 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +1 -0
- package/src/machine/promotions.js +11 -18
- package/src/machine/ranking.js +5 -2
- package/src/machine/reward.js +1 -0
- package/src/machine/reward_cash.js +1 -0
- package/src/machine/reward_fc.js +1 -0
- package/src/machine/roulette_v2.js +18 -26
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +10 -4
- package/src/machine/side_cash.js +1 -0
- package/src/machine/side_v2.js +38 -24
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +5 -2
- package/src/machine/user_sign_up.js +1 -0
- package/src/machine/vip_table.js +1 -0
- package/src/machine/websocket.js +42 -14
- package/src/machine/welcome.js +1 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
- package/src/machine/withdraw/withdraw_krway.js +1 -0
- package/src/machine/withdraw/withdraw_manual.js +16 -8
- package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
- package/src/request/request.js +34 -30
- package/src/util/deviceToken.js +7 -6
- package/src/util/storage.js +4 -3
- package/test/api.behavior.test.js +69 -0
- package/test/api.contract.test.js +18 -0
- package/test/config.test.js +27 -0
- package/test/deviceToken.test.js +139 -0
- package/test/helpers.coverage.test.js +11 -0
- package/test/helpers.js +91 -0
- package/test/index.exports.test.js +14 -0
- package/test/machine.activity.core.coverage.test.js +337 -0
- package/test/machine.activity.gap.coverage.test.js +252 -0
- package/test/machine.activity.more.coverage.test.js +180 -0
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
- package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
- package/test/machine.activity_welcome.low.coverage.test.js +211 -0
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
- package/test/machine.auth.coverage.test.js +215 -0
- package/test/machine.bank_binding.test.js +143 -0
- package/test/machine.binding_otp_krway.coverage.test.js +223 -0
- package/test/machine.contract.test.js +50 -0
- package/test/machine.crypto_bank.coverage.test.js +270 -0
- package/test/machine.crypto_way.coverage.test.js +108 -0
- package/test/machine.crypto_way_cash.coverage.test.js +114 -0
- package/test/machine.definition.test.js +137 -0
- package/test/machine.deposit.manual.coverage.test.js +365 -0
- package/test/machine.deposit_fc.coverage.test.js +126 -0
- package/test/machine.direct.coverage.test.js +96 -0
- package/test/machine.direct_cash.coverage.test.js +108 -0
- package/test/machine.error.coverage.test.js +37 -0
- package/test/machine.events.test.js +126 -0
- package/test/machine.favorite_jackpot.coverage.test.js +82 -0
- package/test/machine.float.coverage.test.js +136 -0
- package/test/machine.flow.test.js +226 -0
- package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
- package/test/machine.game_search_cash.coverage.test.js +195 -0
- package/test/machine.game_search_v2.test.js +199 -0
- package/test/machine.game_user_profile.coverage.test.js +100 -0
- package/test/machine.honor_board.test.js +148 -0
- package/test/machine.inbox.common.coverage.test.js +304 -0
- package/test/machine.loadcard_cash.coverage.test.js +101 -0
- package/test/machine.loadcard_vn.coverage.test.js +122 -0
- package/test/machine.misc.coverage.test.js +361 -0
- package/test/machine.more2.coverage.test.js +261 -0
- package/test/machine.options.execution.test.js +272 -0
- package/test/machine.priority.coverage.test.js +629 -0
- package/test/machine.qrcode_cash.coverage.test.js +107 -0
- package/test/machine.qrcode_v2.coverage.test.js +121 -0
- package/test/machine.regression.test.js +82 -0
- package/test/machine.roulette_v2.test.js +142 -0
- package/test/machine.side_reward_reset.coverage.test.js +220 -0
- package/test/machine.targeted.coverage.test.js +313 -0
- package/test/machine.usdt.coverage.test.js +95 -0
- package/test/machine.usdt_cash.coverage.test.js +73 -0
- package/test/machine.vip_card_activity.test.js +114 -0
- package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
- package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
- package/test/machine.vpay.coverage.test.js +142 -0
- package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
- package/test/machine.withdraw_krway.coverage.test.js +123 -0
- package/test/machine.withdraw_manual.coverage.test.js +185 -0
- package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
- package/test/request.test.js +325 -0
- package/test/util.storage.errors.test.js +47 -0
- package/test/util.test.js +41 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import qrcodeCashFactory from '../src/machine/deposit/qrcode_cash.js'
|
|
5
|
+
|
|
6
|
+
test('qrcode_cash covers actions, guard and services branches', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
send: async (req) => {
|
|
10
|
+
sent.push(req)
|
|
11
|
+
if (req.url === 'payment/v2/qrcode_cash/expected/result') {
|
|
12
|
+
return { data: { bonus: 5 } }
|
|
13
|
+
}
|
|
14
|
+
if (req.url === 'payment/v2/qrcode_cash/transaction') {
|
|
15
|
+
return { applyId: 'Q-1' }
|
|
16
|
+
}
|
|
17
|
+
return {}
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const machine = qrcodeCashFactory(request, {
|
|
22
|
+
paymentDetail: [
|
|
23
|
+
{
|
|
24
|
+
category: 'qrcode',
|
|
25
|
+
transferType: 'deposit',
|
|
26
|
+
method: 'qrcode_cash',
|
|
27
|
+
optional: [100, 200],
|
|
28
|
+
minimum: 50,
|
|
29
|
+
maximum: 500,
|
|
30
|
+
grandTotalEnable: 1,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
category: 'qrcode',
|
|
34
|
+
transferType: 'deposit',
|
|
35
|
+
method: 'qrcode_cash_2',
|
|
36
|
+
optional: [300],
|
|
37
|
+
minimum: 80,
|
|
38
|
+
maximum: 800,
|
|
39
|
+
grandTotalEnable: 0,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
promotion: { minimumAmount: 120, promotionsNo: 'P-1' },
|
|
43
|
+
selectedAmount: 10,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const { actions, guards, services } = machine.options
|
|
47
|
+
const debounceCond = machine.config.states.debouncing.after[1000][0].cond
|
|
48
|
+
const initial = machine.initialState.context
|
|
49
|
+
|
|
50
|
+
const init = actions.setInitData.assignment(initial, {})
|
|
51
|
+
assert.equal(init.qrcodes.length, 2)
|
|
52
|
+
assert.equal(init.selectedQrcode.method, 'qrcode_cash')
|
|
53
|
+
assert.equal(init.options.length, 2)
|
|
54
|
+
assert.equal(init.selectedAmount, 120)
|
|
55
|
+
|
|
56
|
+
const promo = actions.setPromotion.assignment(init, { data: { minimumAmount: 200, promotionsNo: 'P-2' } })
|
|
57
|
+
assert.equal(promo.selectedAmount, 200)
|
|
58
|
+
assert.equal(promo.calculation, null)
|
|
59
|
+
|
|
60
|
+
const promoNoArray = actions.setPromotion.assignment({ qrcodes: null, selectedAmount: 30 }, { data: { minimumAmount: 40, promotionsNo: 'P-3' } })
|
|
61
|
+
assert.deepEqual(promoNoArray.qrcodes, [])
|
|
62
|
+
assert.equal(promoNoArray.selectedQrcode, undefined)
|
|
63
|
+
|
|
64
|
+
const selectedQrcode = actions.setQrcode.assignment(
|
|
65
|
+
{ promotion: { minimumAmount: 150 }, selectedAmount: 20 },
|
|
66
|
+
{ data: { method: 'qrcode_cash_2', optional: [300], grandTotalEnable: 0 } }
|
|
67
|
+
)
|
|
68
|
+
assert.equal(selectedQrcode.selectedQrcode.method, 'qrcode_cash_2')
|
|
69
|
+
assert.equal(selectedQrcode.options[0], 300)
|
|
70
|
+
assert.equal(selectedQrcode.selectedAmount, 150)
|
|
71
|
+
|
|
72
|
+
assert.equal(actions.setAmount.assignment({ selectedQrcode: { grandTotalEnable: 1 }, selectedAmount: '10.5' }, { data: '0.5' }).selectedAmount, 11)
|
|
73
|
+
assert.equal(actions.setAmount.assignment({ selectedQrcode: { grandTotalEnable: 0 } }, { data: '99' }).selectedAmount, '99')
|
|
74
|
+
assert.equal(actions.inputAmount.assignment(initial, { data: '88' }).selectedAmount, '88')
|
|
75
|
+
assert.equal(debounceCond({ selectedQrcode: { minimum: 50, maximum: 500 }, selectedAmount: 100 }, {}), true)
|
|
76
|
+
assert.equal(debounceCond({ selectedQrcode: null, selectedAmount: 10 }, {}), false)
|
|
77
|
+
|
|
78
|
+
assert.equal(actions.setCalculation.assignment(initial, { data: { data: { x: 1 } } }).calculation.x, 1)
|
|
79
|
+
assert.equal(actions.setCalculation.assignment(initial, { data: { y: 2 } }).calculation.y, 2)
|
|
80
|
+
assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
|
|
81
|
+
assert.equal(actions.setResult.assignment(initial, { data: { applyId: 'Q-2' } }).result.applyId, 'Q-2')
|
|
82
|
+
|
|
83
|
+
assert.equal(guards.hasQrcodeMethods({ paymentDetail: [{ category: 'qrcode' }], currentCategory: 'qrcode' }), true)
|
|
84
|
+
assert.equal(guards.hasQrcodeMethods({ paymentDetail: [{ category: 'direct' }], currentCategory: 'qrcode' }), false)
|
|
85
|
+
|
|
86
|
+
const calcResult = await services.fetchCalculation({
|
|
87
|
+
selectedQrcode: { method: 'qrcode_cash' },
|
|
88
|
+
selectedAmount: '321',
|
|
89
|
+
promotion: { promotionsNo: 'P-4' },
|
|
90
|
+
})
|
|
91
|
+
assert.equal(calcResult.data.bonus, 5)
|
|
92
|
+
|
|
93
|
+
const submitResult = await services.submitDeposit({
|
|
94
|
+
selectedQrcode: { method: 'qrcode_cash' },
|
|
95
|
+
selectedAmount: 456,
|
|
96
|
+
promotion: { promotionsNo: 'P-5' },
|
|
97
|
+
})
|
|
98
|
+
assert.equal(submitResult.applyId, 'Q-1')
|
|
99
|
+
|
|
100
|
+
const calcReq = sent.find((entry) => entry.url === 'payment/v2/qrcode_cash/expected/result')
|
|
101
|
+
assert.equal(calcReq.params.amount, 321)
|
|
102
|
+
assert.equal(calcReq.params.promotionsNo, 'P-4')
|
|
103
|
+
|
|
104
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/qrcode_cash/transaction')
|
|
105
|
+
assert.equal(submitReq.params.amount, 456)
|
|
106
|
+
assert.equal(submitReq.params.promotionsNo, 'P-5')
|
|
107
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import qrcodeV2Factory from '../src/machine/deposit/qrcode_v2.js'
|
|
5
|
+
|
|
6
|
+
test('qrcode_v2 covers actions, guards, inline conds and services', async () => {
|
|
7
|
+
const sent = []
|
|
8
|
+
const request = {
|
|
9
|
+
config: { appSecret: 'secret' },
|
|
10
|
+
send: async (req) => {
|
|
11
|
+
sent.push(req)
|
|
12
|
+
if (req.url === 'getConfig') {
|
|
13
|
+
return { config: Buffer.from(JSON.stringify({ bonusPreviewEnable: true }), 'utf8').toString('base64') }
|
|
14
|
+
}
|
|
15
|
+
if (req.url === 'payment/v2/paymentDetail') {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
category: 'qrcode',
|
|
19
|
+
method: 'qrcode_v2',
|
|
20
|
+
optional: [100, 200],
|
|
21
|
+
grandTotalEnable: 1,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
category: 'qrcode',
|
|
25
|
+
method: 'qrcode_v2_b',
|
|
26
|
+
optional: [300],
|
|
27
|
+
grandTotalEnable: 0,
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
if (req.url === 'payment/v2/qrcode_v2/bonus/preview') {
|
|
32
|
+
return [{ bonus: 7 }]
|
|
33
|
+
}
|
|
34
|
+
if (req.url === 'payment/v2/qrcode_v2/expected/result') {
|
|
35
|
+
return { data: { expectedAmount: 123 } }
|
|
36
|
+
}
|
|
37
|
+
if (req.url === 'payment/v2/qrcode_v2/transaction') {
|
|
38
|
+
return { applyId: 'Q2-1' }
|
|
39
|
+
}
|
|
40
|
+
return {}
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
global.window = { atob: (v) => Buffer.from(v, 'base64').toString('utf8') }
|
|
45
|
+
|
|
46
|
+
const machine = qrcodeV2Factory(request)
|
|
47
|
+
const { actions, guards, services } = machine.options
|
|
48
|
+
const initial = machine.initialState.context
|
|
49
|
+
|
|
50
|
+
const checkingCond = machine.config.states.checking.always[0].cond
|
|
51
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' }, selectedQrcode: { method: 'm' } }), true)
|
|
52
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: false }, promotion: { activityNo: 'A1' }, selectedQrcode: { method: 'm' } }), false)
|
|
53
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'none' }, selectedQrcode: { method: 'm' } }), false)
|
|
54
|
+
assert.equal(checkingCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' }, selectedQrcode: null }), false)
|
|
55
|
+
|
|
56
|
+
const loadedSelectCond = machine.config.states.loaded.on.SELECT_QRCODE[0].cond
|
|
57
|
+
assert.equal(loadedSelectCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' } }), true)
|
|
58
|
+
assert.equal(loadedSelectCond({ siteConfig: { bonusPreviewEnable: false }, promotion: { activityNo: 'A1' } }), false)
|
|
59
|
+
|
|
60
|
+
const submittedSelectCond = machine.config.states.submitted.on.SELECT_QRCODE[0].cond
|
|
61
|
+
assert.equal(submittedSelectCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'A1' } }), true)
|
|
62
|
+
assert.equal(submittedSelectCond({ siteConfig: { bonusPreviewEnable: true }, promotion: { activityNo: 'none' } }), false)
|
|
63
|
+
|
|
64
|
+
const initData = await services.fetchInitData(initial)
|
|
65
|
+
assert.equal(initData.siteConfig.bonusPreviewEnable, true)
|
|
66
|
+
assert.equal(initData.paymentDetail.length, 2)
|
|
67
|
+
|
|
68
|
+
const setInitData = actions.setInitData.assignment(initial, { data: initData })
|
|
69
|
+
assert.equal(setInitData.qrcodes.length, 2)
|
|
70
|
+
assert.equal(setInitData.selectedQrcode.method, 'qrcode_v2')
|
|
71
|
+
assert.equal(setInitData.currentMethod, 'qrcode_v2')
|
|
72
|
+
assert.equal(setInitData.options[0], 100)
|
|
73
|
+
assert.equal(setInitData.grandTotalEnable, 1)
|
|
74
|
+
|
|
75
|
+
const reset = actions.reset.assignment({ selectedAmount: 99, calculation: { ok: 1 }, result: { applyId: 1 } }, {})
|
|
76
|
+
assert.equal(reset.selectedAmount, null)
|
|
77
|
+
assert.equal(reset.calculation, null)
|
|
78
|
+
assert.equal(reset.result, null)
|
|
79
|
+
|
|
80
|
+
assert.equal(actions.setBonusPreview.assignment(initial, { data: [{ bonus: 1 }] }).bonusPreviewData[0].bonus, 1)
|
|
81
|
+
|
|
82
|
+
const setQrcode = actions.setQrcode.assignment(initial, { data: { method: 'qrcode_v2_b', optional: [300], grandTotalEnable: 0 } })
|
|
83
|
+
assert.equal(setQrcode.currentMethod, 'qrcode_v2_b')
|
|
84
|
+
assert.equal(setQrcode.options[0], 300)
|
|
85
|
+
assert.equal(setQrcode.grandTotalEnable, 0)
|
|
86
|
+
|
|
87
|
+
assert.equal(actions.addAmount.assignment({ selectedAmount: 20 }, { data: 30 }).selectedAmount, 50)
|
|
88
|
+
assert.equal(actions.setAmount.assignment(initial, { data: 222 }).selectedAmount, 222)
|
|
89
|
+
|
|
90
|
+
assert.equal(actions.setCalculation.assignment(initial, { data: { data: { expectedAmount: 9 } } }).calculation.expectedAmount, 9)
|
|
91
|
+
assert.equal(actions.setCalculation.assignment(initial, { data: { expectedAmount: 8 } }).calculation.expectedAmount, 8)
|
|
92
|
+
assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
|
|
93
|
+
assert.equal(actions.setResult.assignment(initial, { data: { applyId: 'Q2-2' } }).result.applyId, 'Q2-2')
|
|
94
|
+
assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'P-1' } }).promotion.activityNo, 'P-1')
|
|
95
|
+
|
|
96
|
+
assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 1 }), true)
|
|
97
|
+
assert.equal(guards.isGrandTotalEnable({ grandTotalEnable: 0 }), false)
|
|
98
|
+
|
|
99
|
+
const bonus = await services.fetchBonusPreview({ currentMethod: 'qrcode_v2', promotion: { activityNo: 'ACT1' } })
|
|
100
|
+
assert.equal(bonus[0].bonus, 7)
|
|
101
|
+
|
|
102
|
+
const calc = await services.fetchCalculation({ currentMethod: 'qrcode_v2', selectedAmount: '456', promotion: { activityNo: 'ACT2' } })
|
|
103
|
+
assert.equal(calc.data.expectedAmount, 123)
|
|
104
|
+
|
|
105
|
+
const submit = await services.submitDeposit({ currentMethod: 'qrcode_v2', selectedAmount: 500, promotion: { activityNo: 'ACT3' } })
|
|
106
|
+
assert.equal(submit.applyId, 'Q2-1')
|
|
107
|
+
|
|
108
|
+
const detailReq = sent.find((entry) => entry.url === 'payment/v2/paymentDetail')
|
|
109
|
+
assert.equal(detailReq.params.transferType, 'DEPOSIT')
|
|
110
|
+
|
|
111
|
+
const bonusReq = sent.find((entry) => entry.url === 'payment/v2/qrcode_v2/bonus/preview')
|
|
112
|
+
assert.equal(bonusReq.params.promotionsNo, 'ACT1')
|
|
113
|
+
|
|
114
|
+
const calcReq = sent.find((entry) => entry.url === 'payment/v2/qrcode_v2/expected/result')
|
|
115
|
+
assert.equal(calcReq.params.amount, 456)
|
|
116
|
+
assert.equal(calcReq.params.promotionsNo, 'ACT2')
|
|
117
|
+
|
|
118
|
+
const submitReq = sent.find((entry) => entry.url === 'payment/v2/qrcode_v2/transaction')
|
|
119
|
+
assert.equal(submitReq.params.amount, 500)
|
|
120
|
+
assert.equal(submitReq.params.promotionsNo, 'ACT3')
|
|
121
|
+
})
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import usdtFactory from '../src/machine/deposit/usdt.js'
|
|
5
|
+
import virtualBankCashFactory from '../src/machine/deposit/virtual_bank_cash.js'
|
|
6
|
+
import cryptoBankCashFactory from '../src/machine/deposit/crypto_bank_cash.js'
|
|
7
|
+
|
|
8
|
+
function createRequestStub() {
|
|
9
|
+
return {
|
|
10
|
+
config: {
|
|
11
|
+
appSecret: 'secret',
|
|
12
|
+
},
|
|
13
|
+
send: async () => ({}),
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('usdt actions: setPayment handles empty payload safely', () => {
|
|
18
|
+
const machine = usdtFactory(createRequestStub())
|
|
19
|
+
const setPayment = machine.options.actions.setPayment.assignment
|
|
20
|
+
const next = setPayment(machine.initialState.context, { data: [] })
|
|
21
|
+
|
|
22
|
+
assert.deepEqual(next, {
|
|
23
|
+
networks: [],
|
|
24
|
+
selectedNetwork: null,
|
|
25
|
+
currentPayment: null,
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('usdt actions/guards: selectedNetwork null does not throw', () => {
|
|
30
|
+
const machine = usdtFactory(createRequestStub())
|
|
31
|
+
const setResultFromLocal = machine.options.actions.setResultFromLocal.assignment
|
|
32
|
+
const isFound = machine.options.guards.isFound
|
|
33
|
+
|
|
34
|
+
const context = {
|
|
35
|
+
...machine.initialState.context,
|
|
36
|
+
selectedNetwork: null,
|
|
37
|
+
resultMap: {},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
assert.deepEqual(setResultFromLocal(context, {}), {})
|
|
41
|
+
assert.equal(isFound(context, {}), false)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('virtual_bank_cash guards/actions: missing currentPayment is handled', () => {
|
|
45
|
+
const machine = virtualBankCashFactory(createRequestStub(), { paymentDetail: [] })
|
|
46
|
+
const setInitData = machine.options.actions.setInitData.assignment
|
|
47
|
+
const isCalculable = machine.options.guards.isCalculable
|
|
48
|
+
|
|
49
|
+
const init = setInitData(machine.initialState.context, { data: { currentPayment: null } })
|
|
50
|
+
assert.equal(init.method, null)
|
|
51
|
+
assert.equal(init.processing, null)
|
|
52
|
+
assert.equal(init.virtualBanks, null)
|
|
53
|
+
|
|
54
|
+
const context = {
|
|
55
|
+
...machine.initialState.context,
|
|
56
|
+
selectedAmount: 100,
|
|
57
|
+
currentPayment: null,
|
|
58
|
+
}
|
|
59
|
+
assert.equal(isCalculable(context, {}), false)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('crypto_bank_cash init: empty banks keep safe defaults', () => {
|
|
63
|
+
const machine = cryptoBankCashFactory(createRequestStub(), {
|
|
64
|
+
paymentDetail: [
|
|
65
|
+
{
|
|
66
|
+
transferType: 'deposit',
|
|
67
|
+
category: 'cryptoBank',
|
|
68
|
+
method: 'crypto_bank',
|
|
69
|
+
banks: [],
|
|
70
|
+
optional: null,
|
|
71
|
+
minimum: 10,
|
|
72
|
+
maximum: 1000,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const state = machine.initialState
|
|
78
|
+
assert.equal(state.context.selectedCrypto, null)
|
|
79
|
+
assert.equal(state.context.selectedAddress, null)
|
|
80
|
+
assert.deepEqual(state.context.addresses, [])
|
|
81
|
+
assert.deepEqual(state.context.options, [])
|
|
82
|
+
})
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import rouletteFactory from '../src/machine/roulette_v2.js'
|
|
5
|
+
|
|
6
|
+
test('roulette_v2 actions/guards/services cover spin and collect branches', async () => {
|
|
7
|
+
const calls = []
|
|
8
|
+
const request = {
|
|
9
|
+
config: { appSecret: 'secret' },
|
|
10
|
+
send: async (req) => {
|
|
11
|
+
calls.push(req)
|
|
12
|
+
return {
|
|
13
|
+
data: {
|
|
14
|
+
activityNo: 'A100',
|
|
15
|
+
periodEndTime: `${Math.floor(Date.now() / 1000) + 120}`,
|
|
16
|
+
rewardList: [
|
|
17
|
+
{ rewardType: 'A', reward: 1 },
|
|
18
|
+
{ rewardType: 'B', reward: 2 },
|
|
19
|
+
{ rewardType: 'C', reward: 3 },
|
|
20
|
+
{ rewardType: 'D', reward: 4 },
|
|
21
|
+
{ rewardType: 'E', reward: 5 },
|
|
22
|
+
],
|
|
23
|
+
unCollectRewards: [
|
|
24
|
+
{ rewardType: 'POINTS', reward: '2' },
|
|
25
|
+
{ rewardType: 'FREE', reward: '3' },
|
|
26
|
+
{ rewardType: 'CASH', reward: '4' },
|
|
27
|
+
{ rewardType: 'PRIZE', reward: 'x' },
|
|
28
|
+
],
|
|
29
|
+
latestSpinLeft: 3,
|
|
30
|
+
spinLeft: 2,
|
|
31
|
+
rouletteV2ExchangeAward: [{ id: 1 }],
|
|
32
|
+
newSpinRewards: [],
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const machine = rouletteFactory(request)
|
|
39
|
+
|
|
40
|
+
const setActivityNo = machine.options.actions.setActivityNo.assignment
|
|
41
|
+
const setDefaultActivity = machine.options.actions.setDefaultActivity.assignment
|
|
42
|
+
const setInitData = machine.options.actions.setInitData.assignment
|
|
43
|
+
const setUncollectRewardData = machine.options.actions.setUncollectRewardData.assignment
|
|
44
|
+
const setDuration = machine.options.actions.setDuration.assignment
|
|
45
|
+
const setSpinCount = machine.options.actions.setSpinCount.assignment
|
|
46
|
+
const setSpinResult = machine.options.actions.setSpinResult.assignment
|
|
47
|
+
const setCollectResult = machine.options.actions.setCollectResult.assignment
|
|
48
|
+
|
|
49
|
+
const isExpired = machine.options.guards.isExpired
|
|
50
|
+
const fetchActivityDetail = machine.options.services.fetchActivityDetail
|
|
51
|
+
const exchange = machine.options.services.exchange
|
|
52
|
+
const collect = machine.options.services.collect
|
|
53
|
+
|
|
54
|
+
assert.equal(setActivityNo(machine.initialState.context, { data: 'A100' }).activityNo, 'A100')
|
|
55
|
+
assert.deepEqual(setDefaultActivity(machine.initialState.context, { detail: { activityNo: 'cached' } }), {
|
|
56
|
+
activityDetail: { activityNo: 'cached' },
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const init = setInitData(machine.initialState.context, {
|
|
60
|
+
data: {
|
|
61
|
+
periodEndTime: `${Math.floor(Date.now() / 1000) + 60}`,
|
|
62
|
+
rewardList: [{ rewardType: 'A' }, { rewardType: 'B' }, { rewardType: 'C' }, { rewardType: 'D' }, { rewardType: 'E' }],
|
|
63
|
+
unCollectRewards: [{ rewardType: 'POINTS', reward: '2' }],
|
|
64
|
+
latestSpinLeft: 5,
|
|
65
|
+
spinLeft: 4,
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
assert.equal(init.rewardList[4].rewardType, 'Spin All')
|
|
69
|
+
assert.equal(init.rewardList[5].rewardType, 'E')
|
|
70
|
+
assert.equal(init.latestSpinLeft, 5)
|
|
71
|
+
assert.equal(init.spinLeft, 4)
|
|
72
|
+
|
|
73
|
+
const summarized = setUncollectRewardData(
|
|
74
|
+
{
|
|
75
|
+
...machine.initialState.context,
|
|
76
|
+
unCollectRewards: [
|
|
77
|
+
{ rewardType: 'POINTS', reward: '2' },
|
|
78
|
+
{ rewardType: 'FREE', reward: '3' },
|
|
79
|
+
{ rewardType: 'CASH', reward: '4' },
|
|
80
|
+
{ rewardType: 'PRIZE', reward: 'gift' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{}
|
|
84
|
+
)
|
|
85
|
+
assert.equal(summarized.unCollectPoints, 2)
|
|
86
|
+
assert.equal(summarized.unCollectFree, 3)
|
|
87
|
+
assert.equal(summarized.unCollectCash, 4)
|
|
88
|
+
assert.equal(summarized.unCollectPrize, 1)
|
|
89
|
+
|
|
90
|
+
const durationPatch = setDuration({ ...machine.initialState.context, activityDetail: { periodEndTime: Math.floor(Date.now() / 1000) + 10 } }, {})
|
|
91
|
+
assert.equal(typeof durationPatch.duration, 'number')
|
|
92
|
+
|
|
93
|
+
assert.equal(setSpinCount(machine.initialState.context, { data: 3 }).spinCount, 3)
|
|
94
|
+
|
|
95
|
+
const spinResult = setSpinResult(machine.initialState.context, {
|
|
96
|
+
data: {
|
|
97
|
+
unCollectRewards: [{ rewardType: 'POINTS', reward: 1 }],
|
|
98
|
+
newSpinRewards: [
|
|
99
|
+
{ rewardType: 'POINTS', reward: 10 },
|
|
100
|
+
{ rewardType: 'POINTS', reward: 10 },
|
|
101
|
+
{ rewardType: 'FREE', reward: 2 },
|
|
102
|
+
],
|
|
103
|
+
spinLeft: 1,
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
assert.equal(spinResult.calculatedNewSpinRewards.length, 2)
|
|
107
|
+
assert.equal(spinResult.calculatedNewSpinRewards[0].count >= 1, true)
|
|
108
|
+
assert.equal(spinResult.spinLeft, 1)
|
|
109
|
+
|
|
110
|
+
const collectResult = setCollectResult(machine.initialState.context, {
|
|
111
|
+
data: { rouletteV2ExchangeAward: [{ id: 9 }] },
|
|
112
|
+
})
|
|
113
|
+
assert.deepEqual(collectResult.rouletteV2ExchangeAward, [{ id: 9 }])
|
|
114
|
+
assert.deepEqual(collectResult.unCollectRewards, [])
|
|
115
|
+
|
|
116
|
+
assert.equal(isExpired({ duration: 0 }, {}), true)
|
|
117
|
+
assert.equal(isExpired({ duration: 1 }, {}), false)
|
|
118
|
+
|
|
119
|
+
const cachedData = await fetchActivityDetail(
|
|
120
|
+
{
|
|
121
|
+
...machine.initialState.context,
|
|
122
|
+
activityNo: 'A100',
|
|
123
|
+
activityDetail: { activityNo: 'CACHED' },
|
|
124
|
+
},
|
|
125
|
+
{}
|
|
126
|
+
)
|
|
127
|
+
assert.equal(cachedData.activityNo, 'CACHED')
|
|
128
|
+
|
|
129
|
+
const fetchedData = await fetchActivityDetail(
|
|
130
|
+
{
|
|
131
|
+
...machine.initialState.context,
|
|
132
|
+
activityNo: 'A100',
|
|
133
|
+
activityDetail: {},
|
|
134
|
+
},
|
|
135
|
+
{}
|
|
136
|
+
)
|
|
137
|
+
assert.equal(fetchedData.activityNo, 'A100')
|
|
138
|
+
|
|
139
|
+
await exchange({ ...machine.initialState.context, activityNo: 'A100', spinCount: 2 }, {})
|
|
140
|
+
await collect(machine.initialState.context, {})
|
|
141
|
+
assert.equal(calls.length >= 3, true)
|
|
142
|
+
})
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import userResetPasswordFactory from '../src/machine/user_reset_password.js'
|
|
5
|
+
import sideFactory from '../src/machine/side.js'
|
|
6
|
+
import rewardFactory from '../src/machine/reward.js'
|
|
7
|
+
import rewardCashFactory from '../src/machine/reward_cash.js'
|
|
8
|
+
|
|
9
|
+
test('user_reset_password actions and services are wired correctly', async () => {
|
|
10
|
+
const sent = []
|
|
11
|
+
const request = {
|
|
12
|
+
config: { appSecret: 'secret' },
|
|
13
|
+
send: async (req) => {
|
|
14
|
+
sent.push(req)
|
|
15
|
+
return { ok: true, req }
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
const machine = userResetPasswordFactory(request)
|
|
19
|
+
const actions = machine.options.actions
|
|
20
|
+
const services = machine.options.services
|
|
21
|
+
const ctx = machine.initialState.context
|
|
22
|
+
|
|
23
|
+
assert.equal(actions.setOtpParamsPhone.assignment(ctx, { data: { countryCode: '66', phone: '0800' } }).otpParams.provider, 'phone')
|
|
24
|
+
assert.equal(actions.setOtpParamsLocal.assignment(ctx, { data: { username: 'u1' } }).otpParams.provider, 'local')
|
|
25
|
+
assert.equal(actions.setOtpParamsEmail.assignment(ctx, { data: { email: 'x@y.com' } }).otpParams.provider, 'email')
|
|
26
|
+
|
|
27
|
+
const otpResult = actions.setOtpResult.assignment(ctx, { data: { requestId: 'r1', ttl: 3000, target: { mask: '***' } } })
|
|
28
|
+
assert.equal(otpResult.requestId, 'r1')
|
|
29
|
+
assert.equal(actions.decreaseTtl.assignment({ ...ctx, ttl: 500 }, {}).ttl, 0)
|
|
30
|
+
assert.equal(actions.setAcknowledgeResult.assignment(ctx, { data: { ttl: 2000 } }).acknowledgeTtl, 2000)
|
|
31
|
+
assert.equal(actions.decreaseAcknowledgeTtl.assignment({ ...ctx, acknowledgeTtl: 500 }, {}).acknowledgeTtl, 0)
|
|
32
|
+
assert.equal(actions.setNewPassword.assignment(ctx, { data: 'new-pass' }).newPassword, 'new-pass')
|
|
33
|
+
const otpCond = machine.config.states.otp.after[1000][0].cond
|
|
34
|
+
const ackCond = machine.config.states.acknowledged.after[1000][0].cond
|
|
35
|
+
const ackErrCond = machine.config.states.acknowledging.invoke.onError[0].cond
|
|
36
|
+
const changeErrCond = machine.config.states.changing.invoke.onError[0].cond
|
|
37
|
+
assert.equal(otpCond({ ...ctx, ttl: 1000 }), true)
|
|
38
|
+
assert.equal(ackCond({ ...ctx, acknowledgeTtl: 1000 }), true)
|
|
39
|
+
assert.equal(ackErrCond(ctx, { data: { code: 'ERR_A108' } }), true)
|
|
40
|
+
assert.equal(changeErrCond(ctx, { data: { code: 'ERR_A108' } }), true)
|
|
41
|
+
|
|
42
|
+
await services.sendOtp({ ...ctx, otpParams: { provider: 'email', email: 'x@y.com' } }, {})
|
|
43
|
+
await services.resetOtp({ ...ctx, requestId: 'rid', target: { email: 'x@y.com' } }, {})
|
|
44
|
+
await services.acknowledge({ ...ctx, requestId: 'rid', target: { email: 'x@y.com' } }, { data: '1234' })
|
|
45
|
+
await services.change({ ...ctx, requestId: 'rid', target: { email: 'x@y.com' }, newPassword: 'new-pass' }, {})
|
|
46
|
+
|
|
47
|
+
assert.equal(sent.length, 4)
|
|
48
|
+
assert.equal(sent[0].url, 'recovery/v2/initiate')
|
|
49
|
+
assert.equal(sent[1].url, 'recovery/v2/reset')
|
|
50
|
+
assert.equal(sent[2].url, 'recovery/v2/acknowledge')
|
|
51
|
+
assert.equal(sent[3].url, 'recovery/v2/changePassword')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('side machine menu and room history actions cover branches', async () => {
|
|
55
|
+
const request = {
|
|
56
|
+
send: async () => ({ list: [] }),
|
|
57
|
+
}
|
|
58
|
+
const machine = sideFactory(request)
|
|
59
|
+
const actions = machine.options.actions
|
|
60
|
+
const ctx = machine.initialState.context
|
|
61
|
+
|
|
62
|
+
const menu = actions.makeMenu.assignment(ctx, {
|
|
63
|
+
data: {
|
|
64
|
+
list: [
|
|
65
|
+
{ id: 1, category: 'SYSTEM_INDEX_LIST' },
|
|
66
|
+
{ id: 2, category: 'SYSTEM_MY_FAVORITE' },
|
|
67
|
+
{ id: 3, category: 'SYSTEM_TOP_GAME' },
|
|
68
|
+
{ id: 4, category: 'SYSTEM_NEW_GAME' },
|
|
69
|
+
{ id: 5, category: 'SYSTEM_BIG_CATEGORY_SLOT' },
|
|
70
|
+
{ id: 6, category: 'SYSTEM_BIG_CATEGORY_FISHING' },
|
|
71
|
+
{ id: 7, category: 'SYSTEM_BIG_CATEGORY_ARCADE' },
|
|
72
|
+
{ id: 8, category: 'SYSTEM_BIG_CATEGORY_TABLECARD' },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
assert.equal(menu.menu.home.id, 1)
|
|
77
|
+
assert.equal(menu.menu.favorite.id, 2)
|
|
78
|
+
|
|
79
|
+
const moved = actions.forwardRoom.assignment({ ...ctx, room: { id: 1 }, roomHistory: [] }, { data: { id: 2 } })
|
|
80
|
+
assert.equal(moved.room.id, 2)
|
|
81
|
+
assert.equal(moved.roomHistory.length, 1)
|
|
82
|
+
|
|
83
|
+
const back = actions.backwardRoom.assignment({ ...ctx, roomHistory: [{ id: 1 }, { id: 2 }] }, {})
|
|
84
|
+
assert.equal(back.room.id, 2)
|
|
85
|
+
assert.equal(back.roomHistory.length, 1)
|
|
86
|
+
assert.deepEqual(actions.resetRoomHistory.assignment({ ...ctx, roomHistory: [{ id: 1 }] }, {}), { roomHistory: [] })
|
|
87
|
+
|
|
88
|
+
const fetched = await machine.options.services.getRoomItems({ ...ctx, room: { id: 99 } }, {})
|
|
89
|
+
assert.deepEqual(fetched, { list: [] })
|
|
90
|
+
|
|
91
|
+
const homeEntry = machine.config.states.room.states.home.entry.assignment
|
|
92
|
+
const nextRoom = homeEntry({ ...ctx, menu: { home: { id: 10 } }, roomHistory: [] }, {})
|
|
93
|
+
assert.deepEqual(nextRoom, { room: { id: 10 } })
|
|
94
|
+
const ignored = homeEntry({ ...ctx, menu: { home: { id: 10 } }, roomHistory: [{ id: 10 }] }, {})
|
|
95
|
+
assert.equal(ignored, undefined)
|
|
96
|
+
const missingMenu = homeEntry({ ...ctx, menu: {}, roomHistory: [] }, {})
|
|
97
|
+
assert.equal(missingMenu, undefined)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('reward machine actions, guards, and services cover fallback paths', async () => {
|
|
101
|
+
let callbackCount = 0
|
|
102
|
+
const request = {
|
|
103
|
+
config: { appSecret: 'secret' },
|
|
104
|
+
send: async (req) => {
|
|
105
|
+
if (req.url === 'activities/rewards' && req.method === 'get') return { data: [{ id: 1 }] }
|
|
106
|
+
if (req.url === 'payment/v2/bankWallet/promotion/preview') return { enableWithdraw: true }
|
|
107
|
+
if (req.url === 'activities/rewards' && req.method === 'post') return { ok: true, receiveNo: req.params.receiveNo }
|
|
108
|
+
if (req.url === 'activities/collect') return { ok: true }
|
|
109
|
+
return { data: [] }
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
const machine = rewardFactory(request, { locale: 'zh-TW' })
|
|
113
|
+
const actions = machine.options.actions
|
|
114
|
+
const guards = machine.options.guards
|
|
115
|
+
const services = machine.options.services
|
|
116
|
+
const timerPendingCond = machine.config.states.timer.states.pending.after[20000][0].cond
|
|
117
|
+
const receivePrizeCond = machine.config.states.reward.states.receiving.invoke.onDone[0].cond
|
|
118
|
+
const ctx = machine.initialState.context
|
|
119
|
+
|
|
120
|
+
assert.equal(actions.setRewardList.assignment(ctx, { data: [{ data: [1] }, { data: [2] }, { data: [3] }] }).rewardList[0], 3)
|
|
121
|
+
const rewardListFallback = actions.setRewardList.assignment(ctx, { data: [] })
|
|
122
|
+
assert.deepEqual(rewardListFallback.otherRewardList, [])
|
|
123
|
+
assert.deepEqual(rewardListFallback.pointsRewardList, [])
|
|
124
|
+
assert.deepEqual(rewardListFallback.rewardList, [])
|
|
125
|
+
assert.equal(actions.setOtherRewardList.assignment(ctx, { data: [{ data: [4] }] }).otherRewardList[0], 4)
|
|
126
|
+
assert.equal(actions.setOtherRewardList.assignment(ctx, { data: [] }).otherRewardList, undefined)
|
|
127
|
+
assert.equal(actions.setRewardData.assignment(ctx, { data: { activityNo: 8, receiveNo: 9 } }).receiveNo, 9)
|
|
128
|
+
const cbAction = actions.setCallback.assignment(ctx, { data: { callback: () => callbackCount++ } })
|
|
129
|
+
cbAction.callback()
|
|
130
|
+
assert.equal(callbackCount, 1)
|
|
131
|
+
assert.equal(actions.setOrderColumn.assignment(ctx, { data: {} }).orderColumn, 'createTime')
|
|
132
|
+
assert.equal(actions.setOrderColumn.assignment(ctx, { data: { orderColumn: 'status' } }).orderColumn, 'status')
|
|
133
|
+
assert.equal(actions.setRewardType.assignment(ctx, { data: { rewardType: 'PRIZE' } }).rewardType, 'PRIZE')
|
|
134
|
+
actions.doCallback({ ...ctx, callback: () => callbackCount++ }, {})
|
|
135
|
+
assert.equal(callbackCount, 2)
|
|
136
|
+
assert.equal(actions.setWithdrawRulePreview.assignment(ctx, { data: { a: 1 } }).withdrawRule.a, 1)
|
|
137
|
+
assert.equal(actions.setIsPlaying.assignment(ctx, { data: true }).isPlaying, true)
|
|
138
|
+
assert.equal(actions.setLang.assignment({ ...ctx, lang: null }, { data: {} }).lang, 'en-US')
|
|
139
|
+
assert.equal(actions.setLang.assignment(ctx, { data: { locale: 'ja-JP' } }).lang, 'ja-JP')
|
|
140
|
+
|
|
141
|
+
assert.equal(guards.isPrize({ ...ctx, rewardType: 'PRIZE' }, {}), true)
|
|
142
|
+
assert.equal(guards.isNotInGame({ ...ctx, isPlaying: false }, {}), true)
|
|
143
|
+
assert.equal(timerPendingCond, 'isNotInGame')
|
|
144
|
+
assert.equal(guards.isNotInGame({ ...ctx, isPlaying: false }, {}), true)
|
|
145
|
+
assert.equal(guards.isNotInGame({ ...ctx, isPlaying: true }, {}), false)
|
|
146
|
+
assert.equal(receivePrizeCond, 'isPrize')
|
|
147
|
+
assert.equal(guards.isPrize({ ...ctx, rewardType: 'PRIZE' }, {}), true)
|
|
148
|
+
assert.equal(guards.isPrize({ ...ctx, rewardType: 'POINTS' }, {}), false)
|
|
149
|
+
|
|
150
|
+
const rewardList = await services.fetchRewardList({ ...ctx, orderColumn: 'createTime', lang: 'zh-TW' }, {})
|
|
151
|
+
assert.equal(rewardList.length, 3)
|
|
152
|
+
const other = await services.fetchOtherRewardList({ ...ctx, orderColumn: 'createTime', lang: 'zh-TW' }, {})
|
|
153
|
+
assert.equal(other.length, 1)
|
|
154
|
+
const preview = await services.fetchWithdrawRulePreview({ ...ctx, receiveNo: 777 }, {})
|
|
155
|
+
assert.equal(preview.enableWithdraw, true)
|
|
156
|
+
const reward = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: ' ', attended: true } })
|
|
157
|
+
assert.equal(reward.receiveNo, undefined)
|
|
158
|
+
const all = await services.receiveAllPoints(ctx, {})
|
|
159
|
+
assert.equal(all.ok, true)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('reward_cash actions and services cover auth and receiveNo validation', async () => {
|
|
163
|
+
const sent = []
|
|
164
|
+
const request = {
|
|
165
|
+
config: { appSecret: 'secret' },
|
|
166
|
+
send: async (req) => {
|
|
167
|
+
sent.push(req)
|
|
168
|
+
if (req.url === 'activities/rewards' && req.method === 'get') return { data: [{ id: 'x' }] }
|
|
169
|
+
if (req.url === 'payment/v2/bankWallet/promotion/preview') return { rule: 1 }
|
|
170
|
+
if (req.url === 'activities/rewards' && req.method === 'post') return { receiveNo: req.params.receiveNo }
|
|
171
|
+
if (req.url === 'activities/collect') return { ok: true }
|
|
172
|
+
return { data: [] }
|
|
173
|
+
},
|
|
174
|
+
}
|
|
175
|
+
const machine = rewardCashFactory(request, { locale: 'th-TH' })
|
|
176
|
+
const actions = machine.options.actions
|
|
177
|
+
const services = machine.options.services
|
|
178
|
+
const ctx = machine.initialState.context
|
|
179
|
+
|
|
180
|
+
assert.equal(actions.setAuth.assignment(ctx, { data: 1 }).auth, true)
|
|
181
|
+
assert.equal(actions.setRewardList.assignment(ctx, { data: [{ data: [1] }, { data: [2] }, { data: [3] }] }).otherRewardList[0], 1)
|
|
182
|
+
const rewardListFallback = actions.setRewardList.assignment(ctx, { data: [] })
|
|
183
|
+
assert.deepEqual(rewardListFallback.otherRewardList, [])
|
|
184
|
+
assert.deepEqual(rewardListFallback.pointsRewardList, [])
|
|
185
|
+
assert.deepEqual(rewardListFallback.rewardList, [])
|
|
186
|
+
assert.equal(actions.setOtherRewardList.assignment(ctx, { data: [{ data: [4] }] }).otherRewardList[0], 4)
|
|
187
|
+
assert.equal(actions.setOtherRewardList.assignment(ctx, { data: [] }).otherRewardList, undefined)
|
|
188
|
+
assert.equal(actions.setRewardData.assignment(ctx, { data: { activityNo: 1, receiveNo: 2 } }).activityNo, 1)
|
|
189
|
+
assert.equal(typeof actions.setCallback.assignment(ctx, { data: {} }).callback, 'function')
|
|
190
|
+
assert.equal(typeof actions.setCallback.assignment(ctx, { data: { callback: () => 1 } }).callback, 'function')
|
|
191
|
+
assert.equal(actions.setOrderColumn.assignment(ctx, { data: {} }).orderColumn, 'createTime')
|
|
192
|
+
assert.equal(actions.setOrderColumn.assignment(ctx, { data: { orderColumn: 'status' } }).orderColumn, 'status')
|
|
193
|
+
actions.doCallback({ ...ctx, callback: () => {} }, {})
|
|
194
|
+
assert.equal(actions.setWithdrawRulePreview.assignment(ctx, { data: { rule: 1 } }).withdrawRule.rule, 1)
|
|
195
|
+
assert.equal(actions.setLang.assignment({ ...ctx, lang: null }, { data: {} }).lang, 'en-US')
|
|
196
|
+
assert.equal(actions.setLang.assignment(ctx, { data: { locale: 'vi-VN' } }).lang, 'vi-VN')
|
|
197
|
+
|
|
198
|
+
const cond = machine.config.on.SET_AUTH.cond
|
|
199
|
+
const timerPendingTarget = machine.config.states.timer.states.pending.after[20000].target
|
|
200
|
+
assert.equal(cond({ ...ctx, auth: false }, { data: true }), true)
|
|
201
|
+
assert.equal(cond({ ...ctx, auth: true }, { data: 1 }), false)
|
|
202
|
+
assert.equal(timerPendingTarget, 'loading')
|
|
203
|
+
const timerCheckingCond = machine.config.states.timer.states.checking.always[0].cond
|
|
204
|
+
assert.equal(timerCheckingCond({ ...ctx, auth: true }, {}), true)
|
|
205
|
+
assert.equal(timerCheckingCond({ ...ctx, auth: false }, {}), false)
|
|
206
|
+
|
|
207
|
+
const rewardList = await services.fetchRewardList({ ...ctx, orderColumn: 'createTime', lang: 'th-TH' }, {})
|
|
208
|
+
assert.equal(rewardList.length, 3)
|
|
209
|
+
const other = await services.fetchOtherRewardList({ ...ctx, orderColumn: 'createTime', lang: 'th-TH' }, {})
|
|
210
|
+
assert.equal(other.length, 1)
|
|
211
|
+
const preview = await services.fetchWithdrawRulePreview({ ...ctx, receiveNo: 999 }, {})
|
|
212
|
+
assert.equal(preview.rule, 1)
|
|
213
|
+
const reward = await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '0', attended: false } })
|
|
214
|
+
assert.equal(reward.receiveNo, undefined)
|
|
215
|
+
await services.receiveReward(ctx, { data: { activityNo: 1, receiveNo: '2', attended: false } })
|
|
216
|
+
const rewardReq = sent.filter((req) => req.url === 'activities/rewards' && req.method === 'post').slice(-1)[0]
|
|
217
|
+
assert.equal(rewardReq.params.receiveNo, 2)
|
|
218
|
+
const all = await services.receiveAllPoints(ctx, {})
|
|
219
|
+
assert.equal(all.ok, true)
|
|
220
|
+
})
|