@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,252 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import friendInviteFriendsFactory from '../src/machine/activity/friend_invite_friends_activity.js'
|
|
5
|
-
import instantRebateFactory from '../src/machine/activity/instant_rebate_activity.js'
|
|
6
|
-
import diamondShopFcFactory from '../src/machine/activity/diamond_shop_activity_fc.js'
|
|
7
|
-
|
|
8
|
-
test('friend_invite_friends_activity actions/guards/services cover list merge and bind flow', async () => {
|
|
9
|
-
const calls = []
|
|
10
|
-
const request = {
|
|
11
|
-
config: { appSecret: 'secret' },
|
|
12
|
-
send: async (req) => {
|
|
13
|
-
calls.push(req)
|
|
14
|
-
if (req.url === 'friends') {
|
|
15
|
-
if (req.method === 'get') return { friendCode: 'F001', bindFriendLimitDaysAfterRegistered: 7 }
|
|
16
|
-
return { ok: true }
|
|
17
|
-
}
|
|
18
|
-
if (req.url === 'friends/home') return { commission: 11, downLine: 22, activeDownLine: 3 }
|
|
19
|
-
if (req.url === 'friends/dashboard') return { levelTable: [{ level: 1 }], pastTable: [{ level: 0 }] }
|
|
20
|
-
if (req.url === 'activities/sentAward') return { data: { awarded: true } }
|
|
21
|
-
if (req.url === 'friends/dashboard/list') {
|
|
22
|
-
if (req.params.page === 1) return { data: [{ uid: 'a' }], page: { current: 1, total: 2 } }
|
|
23
|
-
return { data: [{ uid: 'b' }], page: { current: 2, total: 2 } }
|
|
24
|
-
}
|
|
25
|
-
if (req.url === 'friends/reward-list') {
|
|
26
|
-
if (req.params.page === 1)
|
|
27
|
-
return { data: { list: [{ id: 1 }], rewardsDetail: { receivedCounts: 1, allDownLineCounts: 9 }, page: { current: 1, total: 2 } } }
|
|
28
|
-
return { data: { list: [{ id: 2 }], rewardsDetail: { receivedCounts: 2, allDownLineCounts: 10 }, page: { current: 2, total: 2 } } }
|
|
29
|
-
}
|
|
30
|
-
return {}
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const machine = friendInviteFriendsFactory(request)
|
|
35
|
-
const { actions, guards, services } = machine.options
|
|
36
|
-
|
|
37
|
-
assert.equal(
|
|
38
|
-
actions.setFriendsCode.assignment(machine.initialState.context, { data: { friendCode: 'FC', bindFriendLimitDaysAfterRegistered: 5 } }).friendCode,
|
|
39
|
-
'FC'
|
|
40
|
-
)
|
|
41
|
-
assert.equal(actions.setFriendsCode.assignment(machine.initialState.context, { data: null }).friendCode, '')
|
|
42
|
-
|
|
43
|
-
const initialData = actions.setInitialData.assignment(machine.initialState.context, {
|
|
44
|
-
data: [
|
|
45
|
-
{ commission: 1, downLine: 2, activeDownLine: 3 },
|
|
46
|
-
{ levelTable: [{ level: 1 }], pastTable: [{ level: 0 }] },
|
|
47
|
-
],
|
|
48
|
-
})
|
|
49
|
-
assert.equal(initialData.commission, 1)
|
|
50
|
-
assert.equal(initialData.levelTable.length, 1)
|
|
51
|
-
|
|
52
|
-
assert.equal(actions.setBindingCode.assignment(machine.initialState.context, { data: { bindingCode: 'BC' } }).bindingCode, 'BC')
|
|
53
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: { activityNo: 'A1' } }).activityNo, 'A1')
|
|
54
|
-
assert.equal(actions.setUidSite.assignment(machine.initialState.context, { data: { uidSite: 'U1' } }).uidSite, 'U1')
|
|
55
|
-
assert.equal(actions.setLevelSearch.assignment(machine.initialState.context, { data: { level: 9 } }).currentLevel, 9)
|
|
56
|
-
assert.equal(actions.setTypeSearch.assignment(machine.initialState.context, { data: { type: 'RECEIVED' } }).currentType, 'RECEIVED')
|
|
57
|
-
assert.equal(actions.reset.assignment(machine.initialState.context, {}).page, 1)
|
|
58
|
-
assert.equal(actions.resetList.assignment(machine.initialState.context, {}).listPage, 1)
|
|
59
|
-
assert.equal(actions.setPage.assignment({ ...machine.initialState.context, page: 2 }, {}).page, 3)
|
|
60
|
-
assert.equal(actions.setListPage.assignment({ ...machine.initialState.context, listPage: 4 }, {}).listPage, 5)
|
|
61
|
-
assert.equal(actions.setLevelDownLineList.assignment(machine.initialState.context, { data: { x: 1 } }).levelDownLine.x, 1)
|
|
62
|
-
|
|
63
|
-
const friendListPatch = actions.setFriendsList.assignment(machine.initialState.context, {
|
|
64
|
-
data: { list: [{ id: 1 }], rewardsDetail: { receivedCounts: 3, allDownLineCounts: 7 } },
|
|
65
|
-
})
|
|
66
|
-
assert.equal(friendListPatch.receivedCounts, 3)
|
|
67
|
-
assert.equal(friendListPatch.allDownLineCounts, 7)
|
|
68
|
-
|
|
69
|
-
assert.equal(guards.isNotEnd({ levelDownLine: { page: { current: 1, total: 2 } } }), true)
|
|
70
|
-
assert.equal(guards.isListNotEnd({ friendsList: { page: { current: 2, total: 2 } } }), false)
|
|
71
|
-
assert.equal(guards.isFriendsEnable({ friendsEnable: true }), true)
|
|
72
|
-
|
|
73
|
-
const code = await services.fetchFriendCode({}, {})
|
|
74
|
-
assert.equal(code.friendCode, 'F001')
|
|
75
|
-
|
|
76
|
-
const data = await services.fetchFriendsData({}, {})
|
|
77
|
-
assert.equal(data[0].commission, 11)
|
|
78
|
-
assert.equal(data[1].levelTable.length, 1)
|
|
79
|
-
|
|
80
|
-
await services.postFriends({ bindingCode: 'BINDX' }, {})
|
|
81
|
-
const award = await services.awardPrize({ activityNo: 'A1', uidSite: 'U1', bindingCode: 'BINDX' }, {})
|
|
82
|
-
assert.equal(award.awarded, true)
|
|
83
|
-
|
|
84
|
-
const levelPage1 = await services.fetchLevelDownLineList({ currentLevel: 1, page: 1, levelDownLine: {} }, {})
|
|
85
|
-
const levelPage2 = await services.fetchLevelDownLineList({ currentLevel: 1, page: 2, levelDownLine: levelPage1 }, {})
|
|
86
|
-
assert.equal(levelPage1.data.length, 1)
|
|
87
|
-
assert.equal(levelPage2.data.length, 2)
|
|
88
|
-
|
|
89
|
-
const rewardsPage1 = await services.fetchFriendsList({ currentType: 'ALL', listPage: 1, friendsList: {} }, {})
|
|
90
|
-
const rewardsPage2 = await services.fetchFriendsList({ currentType: 'ALL', listPage: 2, friendsList: rewardsPage1 }, {})
|
|
91
|
-
assert.equal(rewardsPage1.list.length, 1)
|
|
92
|
-
assert.equal(rewardsPage2.list.length, 2)
|
|
93
|
-
|
|
94
|
-
assert.equal(
|
|
95
|
-
calls.some((req) => req.url === 'activities/sentAward'),
|
|
96
|
-
true
|
|
97
|
-
)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
test('instant_rebate_activity actions/guards/services cover estimate and claim status', async () => {
|
|
101
|
-
const request = {
|
|
102
|
-
send: async (req) => {
|
|
103
|
-
if (req.url === 'activities/rebate/estimate') {
|
|
104
|
-
return {
|
|
105
|
-
data: {
|
|
106
|
-
rebateCycle: 'daily',
|
|
107
|
-
showColletButton: true,
|
|
108
|
-
estimateStartTime: 10,
|
|
109
|
-
estimateEndTime: 20,
|
|
110
|
-
lastCollectTime: 9,
|
|
111
|
-
collectAvailable: true,
|
|
112
|
-
cumulativeValidTurnover: '1,000',
|
|
113
|
-
weekCumulativeValidTurnover: '2,000',
|
|
114
|
-
cumulativeRebateAmount: '100',
|
|
115
|
-
weekCumulativeRebateAmount: '200',
|
|
116
|
-
actualRebateAmount: '150',
|
|
117
|
-
rewardType: 'cash',
|
|
118
|
-
singleMinimumAmountReceive: '100',
|
|
119
|
-
dailyMaximumAmountReceive: '999',
|
|
120
|
-
remainingCount: 1,
|
|
121
|
-
dailyRedemptionLimit: 5,
|
|
122
|
-
reachedAmountLimit: false,
|
|
123
|
-
rebateDistributionTime: 111,
|
|
124
|
-
},
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (req.url === 'activities/rebate/collect') return { data: { result: 'success', amount: '150' } }
|
|
128
|
-
return { data: {} }
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const machine = instantRebateFactory(request)
|
|
133
|
-
const { actions, guards, services } = machine.options
|
|
134
|
-
|
|
135
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A1' }).activityNo, 'A1')
|
|
136
|
-
|
|
137
|
-
const estimatePatch = actions.setEstimateResult.assignment(machine.initialState.context, {
|
|
138
|
-
data: {
|
|
139
|
-
collectAvailable: false,
|
|
140
|
-
actualRebateAmount: '80',
|
|
141
|
-
singleMinimumAmountReceive: '100',
|
|
142
|
-
remainingCount: 5,
|
|
143
|
-
dailyRedemptionLimit: 5,
|
|
144
|
-
reachedAmountLimit: true,
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
assert.equal(estimatePatch.collectAvailable, false)
|
|
148
|
-
assert.equal(estimatePatch.reachedAmountLimit, true)
|
|
149
|
-
|
|
150
|
-
const claimPatch = actions.setClaimesult.assignment(machine.initialState.context, { data: { result: 'success' } })
|
|
151
|
-
assert.equal(claimPatch.claimResultData.result, 'success')
|
|
152
|
-
|
|
153
|
-
assert.equal(guards.isClaimAmountLimitReached({ collectAvailable: false, reachedAmountLimit: true }), true)
|
|
154
|
-
assert.equal(guards.isClaimExhausted({ collectAvailable: false, remainingCount: '5', dailyRedemptionLimit: '5' }), true)
|
|
155
|
-
assert.equal(guards.isInsufficientAmount({ collectAvailable: false, singleMinimumAmountReceive: '1,000', actualRebateAmount: '999' }), true)
|
|
156
|
-
assert.equal(
|
|
157
|
-
guards.isClaimEnable({
|
|
158
|
-
collectAvailable: true,
|
|
159
|
-
remainingCount: 1,
|
|
160
|
-
dailyRedemptionLimit: 2,
|
|
161
|
-
actualRebateAmount: '1,000',
|
|
162
|
-
singleMinimumAmountReceive: '999',
|
|
163
|
-
}),
|
|
164
|
-
true
|
|
165
|
-
)
|
|
166
|
-
assert.equal(guards.isClaimSuccess({ claimResultData: { result: 'success' } }), true)
|
|
167
|
-
|
|
168
|
-
const estimated = await services.estimate({}, {})
|
|
169
|
-
assert.equal(estimated.rebateCycle, 'daily')
|
|
170
|
-
const claimed = await services.claimRebateAmount({}, {})
|
|
171
|
-
assert.equal(claimed.result, 'success')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('diamond_shop_activity_fc actions/guards/services cover loading, exchange and collect branches', async () => {
|
|
175
|
-
const calls = []
|
|
176
|
-
const request = {
|
|
177
|
-
config: { appSecret: 'secret' },
|
|
178
|
-
send: async (req) => {
|
|
179
|
-
calls.push(req)
|
|
180
|
-
if (req.url === 'activities/list') {
|
|
181
|
-
return {
|
|
182
|
-
data: [
|
|
183
|
-
{ activityType: 90, activityNo: 'X' },
|
|
184
|
-
{ activityType: 91, activityNo: 'A91' },
|
|
185
|
-
],
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (req.url === 'activities') {
|
|
189
|
-
return { data: { activityNo: 'A91', awards: [{ award: 10, points: 3 }], unclaimedReward: [{ id: 1 }] } }
|
|
190
|
-
}
|
|
191
|
-
if (req.url === 'activities/exchange') return { ok: true }
|
|
192
|
-
if (req.url === 'activities/collect') return { ok: true }
|
|
193
|
-
return {}
|
|
194
|
-
},
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const machine = diamondShopFcFactory(request)
|
|
198
|
-
const { actions, guards, services } = machine.options
|
|
199
|
-
|
|
200
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A100' }).activityNo, 'A100')
|
|
201
|
-
|
|
202
|
-
const listPatch = actions.setDiamondShopActivities.assignment(machine.initialState.context, {
|
|
203
|
-
data: [
|
|
204
|
-
{ activityType: 90, activityNo: 'X' },
|
|
205
|
-
{ activityType: 91, activityNo: 'A91' },
|
|
206
|
-
],
|
|
207
|
-
})
|
|
208
|
-
assert.equal(listPatch.rankActivities.length, 1)
|
|
209
|
-
assert.equal(listPatch.activityNo, 'A91')
|
|
210
|
-
|
|
211
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { a: 1 } }).activityDetail.a, 1)
|
|
212
|
-
assert.equal(actions.setAwardList.assignment(machine.initialState.context, { data: { awards: [{ id: 1 }] } }).awardList.length, 1)
|
|
213
|
-
|
|
214
|
-
const added = actions.addProduct.assignment(
|
|
215
|
-
{ ...machine.initialState.context, exchangeList: [{ award: 1, points: 2 }] },
|
|
216
|
-
{ data: { award: 10, points: 5 } }
|
|
217
|
-
)
|
|
218
|
-
assert.equal(added.exchangeList.length, 2)
|
|
219
|
-
assert.equal(actions.clearCart.assignment({ ...machine.initialState.context, exchangeList: [{ award: 1, points: 2 }] }, {}).exchangeList.length, 0)
|
|
220
|
-
|
|
221
|
-
const counted = actions.count.assignment(
|
|
222
|
-
{
|
|
223
|
-
...machine.initialState.context,
|
|
224
|
-
exchangeList: [
|
|
225
|
-
{ award: 2, points: 3 },
|
|
226
|
-
{ award: 5, points: 7 },
|
|
227
|
-
],
|
|
228
|
-
},
|
|
229
|
-
{}
|
|
230
|
-
)
|
|
231
|
-
assert.equal(counted.exchangeAward, 7)
|
|
232
|
-
assert.equal(counted.exchangePoint, 10)
|
|
233
|
-
|
|
234
|
-
assert.equal(guards.hasUnclaimedReward({ activityDetail: { unclaimedReward: [{ id: 1 }] } }), true)
|
|
235
|
-
assert.equal(guards.isExchangeable({ exchangeList: [] }), false)
|
|
236
|
-
assert.equal(guards.hasActivityNo({ activityNo: 'A91' }), true)
|
|
237
|
-
|
|
238
|
-
const activities = await services.fetchActivityList({}, {})
|
|
239
|
-
assert.equal(activities.length, 2)
|
|
240
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A91' }, {})
|
|
241
|
-
assert.equal(detail.activityNo, 'A91')
|
|
242
|
-
|
|
243
|
-
const exchangeRes = await services.exchange({ activityNo: 'A91', exchangeList: [{ award: 10 }, { award: 20 }] }, {})
|
|
244
|
-
assert.equal(exchangeRes.length, 2)
|
|
245
|
-
await services.collect({}, {})
|
|
246
|
-
|
|
247
|
-
assert.equal(calls.filter((req) => req.url === 'activities/exchange').length, 2)
|
|
248
|
-
assert.equal(
|
|
249
|
-
calls.some((req) => req.url === 'activities/collect'),
|
|
250
|
-
true
|
|
251
|
-
)
|
|
252
|
-
})
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import cashRainActivityFactory from '../src/machine/activity/cash_rain_activity.js'
|
|
5
|
-
import continueDepositActivityFactory from '../src/machine/activity/continue_deposit_activity.js'
|
|
6
|
-
import rankingActivityFactory from '../src/machine/activity/ranking_activity.js'
|
|
7
|
-
|
|
8
|
-
test('cash_rain_activity actions/guards/services cover award and duration branches', async () => {
|
|
9
|
-
const calls = []
|
|
10
|
-
const request = {
|
|
11
|
-
config: { appSecret: 'secret' },
|
|
12
|
-
send: async (req) => {
|
|
13
|
-
calls.push(req)
|
|
14
|
-
if (req.url === 'activities') return { data: { activityNo: 'A1', periodEndTime: Math.floor(Date.now() / 1000) + 30 } }
|
|
15
|
-
if (req.url === 'activities/cashRain') {
|
|
16
|
-
return {
|
|
17
|
-
data: {
|
|
18
|
-
amount: 100,
|
|
19
|
-
rewardType: 'CASH',
|
|
20
|
-
message: 'ok',
|
|
21
|
-
canReceiveQuantity: 2,
|
|
22
|
-
receivedQuantity: 1,
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return {}
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
const machine = cashRainActivityFactory(request, { activityNo: 'A1' })
|
|
30
|
-
const actions = machine.options.actions
|
|
31
|
-
const guards = machine.options.guards
|
|
32
|
-
const services = machine.options.services
|
|
33
|
-
|
|
34
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A2' }).activityNo, 'A2')
|
|
35
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { periodEndTime: 1 } }).activityDetail.periodEndTime, 1)
|
|
36
|
-
assert.equal(
|
|
37
|
-
typeof actions.setDuration.assignment(
|
|
38
|
-
{ ...machine.initialState.context, activityDetail: { periodEndTime: Math.floor(Date.now() / 1000) + 5 } },
|
|
39
|
-
{}
|
|
40
|
-
).duration,
|
|
41
|
-
'number'
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
const award = actions.setAward.assignment(machine.initialState.context, {
|
|
45
|
-
data: { amount: 9, rewardType: 'FREE', message: 'm', canReceiveQuantity: 3, receivedQuantity: 1 },
|
|
46
|
-
})
|
|
47
|
-
assert.equal(award.amount, 9)
|
|
48
|
-
assert.equal(award.rewardType, 'FREE')
|
|
49
|
-
assert.equal(award.canReceiveQuantity, 3)
|
|
50
|
-
|
|
51
|
-
const callbackPatch = actions.setCallback.assignment(machine.initialState.context, { data: { callback: () => {} } })
|
|
52
|
-
assert.equal(typeof callbackPatch.callback, 'function')
|
|
53
|
-
assert.deepEqual(actions.resetAward.assignment(machine.initialState.context, {}), { amount: null, rewardType: null, message: null })
|
|
54
|
-
|
|
55
|
-
assert.equal(guards.isExpired({ duration: 0 }), true)
|
|
56
|
-
assert.equal(guards.isExpired({ duration: 1 }), false)
|
|
57
|
-
|
|
58
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
59
|
-
const reward = await services.awardPrize({ activityNo: 'A1' }, {})
|
|
60
|
-
assert.equal(detail.activityNo, 'A1')
|
|
61
|
-
assert.equal(reward.rewardType, 'CASH')
|
|
62
|
-
assert.equal(calls.length, 2)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('continue_deposit_activity actions/guards/services cover stage and reward paths', async () => {
|
|
66
|
-
const calls = []
|
|
67
|
-
const request = {
|
|
68
|
-
config: { appSecret: 'secret' },
|
|
69
|
-
send: async (req) => {
|
|
70
|
-
calls.push(req)
|
|
71
|
-
if (req.url === 'activities') {
|
|
72
|
-
return {
|
|
73
|
-
data: {
|
|
74
|
-
receiveNo: '2',
|
|
75
|
-
receiveStatus: 2,
|
|
76
|
-
dayOfThePeriod: 2,
|
|
77
|
-
policy: 'CONTINUE_DEPOSIT',
|
|
78
|
-
progress: [
|
|
79
|
-
{ achieve: false, target: 100, deposit: 20 },
|
|
80
|
-
{ achieve: true, target: 200, deposit: 250 },
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (req.url === 'activities/rewards') return { data: { ok: true } }
|
|
86
|
-
return {}
|
|
87
|
-
},
|
|
88
|
-
}
|
|
89
|
-
const machine = continueDepositActivityFactory(request, { activityNo: 'A1' })
|
|
90
|
-
const actions = machine.options.actions
|
|
91
|
-
const guards = machine.options.guards
|
|
92
|
-
const services = machine.options.services
|
|
93
|
-
|
|
94
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A2' }).activityNo, 'A2')
|
|
95
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { x: 1 } }).activityDetail.x, 1)
|
|
96
|
-
|
|
97
|
-
const props = actions.setProperties.assignment(machine.initialState.context, {
|
|
98
|
-
data: {
|
|
99
|
-
dayOfThePeriod: 2,
|
|
100
|
-
policy: 'P',
|
|
101
|
-
progress: [
|
|
102
|
-
{ achieve: false, target: 100, deposit: 20.8 },
|
|
103
|
-
{ achieve: true, target: 200, deposit: 230 },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
assert.equal(props.stages[0].deposit, 20)
|
|
108
|
-
assert.equal(props.stages[0].percentage, 20)
|
|
109
|
-
assert.equal(props.stages[1].deposit, 200)
|
|
110
|
-
assert.equal(props.stages[1].percentage, 100)
|
|
111
|
-
assert.equal(props.currentStage.day, 2)
|
|
112
|
-
assert.equal(props.rewardType, 'P')
|
|
113
|
-
|
|
114
|
-
assert.equal(actions.setReceiveNo.assignment(machine.initialState.context, { data: { receiveNo: '9' } }).receiveNo, '9')
|
|
115
|
-
const cb = actions.setCallback.assignment(machine.initialState.context, { data: { callback: () => {} } })
|
|
116
|
-
assert.equal(typeof cb.callback, 'function')
|
|
117
|
-
|
|
118
|
-
let calledArg = null
|
|
119
|
-
actions.doCallback({ callback: (v) => (calledArg = v), rewardType: 'CONTINUE_DEPOSIT' }, {})
|
|
120
|
-
assert.equal(calledArg, 'CONTINUE_DEPOSIT')
|
|
121
|
-
|
|
122
|
-
assert.equal(guards.isReceivable({ activityDetail: { receiveNo: 1, receiveStatus: 2 } }), true)
|
|
123
|
-
assert.equal(guards.isReceivable({ activityDetail: { receiveNo: 0, receiveStatus: 2 } }), 0)
|
|
124
|
-
assert.equal(guards.isReceived({ activityDetail: { receiveStatus: 1 } }), true)
|
|
125
|
-
|
|
126
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
127
|
-
await services.receiveReward({ activityNo: 'A1', receiveNo: '2' }, {})
|
|
128
|
-
await services.receiveReward({ activityNo: 'A1', receiveNo: '0' }, {})
|
|
129
|
-
assert.equal(detail.receiveStatus, 2)
|
|
130
|
-
const rewardCalls = calls.filter((c) => c.url === 'activities/rewards')
|
|
131
|
-
assert.equal(rewardCalls[0].params.receiveNo, 2)
|
|
132
|
-
assert.equal(rewardCalls[1].params.receiveNo, undefined)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('ranking_activity actions/guards/service cover status transitions', async () => {
|
|
136
|
-
const calls = []
|
|
137
|
-
const request = {
|
|
138
|
-
config: { appSecret: 'secret' },
|
|
139
|
-
send: async (req) => {
|
|
140
|
-
calls.push(req)
|
|
141
|
-
return { data: { activityNo: 'A1', activityBeginTime: 1, activityEndTime: 2 } }
|
|
142
|
-
},
|
|
143
|
-
}
|
|
144
|
-
const machine = rankingActivityFactory(request, { activityNo: 'A1' })
|
|
145
|
-
const actions = machine.options.actions
|
|
146
|
-
const guards = machine.options.guards
|
|
147
|
-
const services = machine.options.services
|
|
148
|
-
|
|
149
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A2' }).activityNo, 'A2')
|
|
150
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { z: 1 } }).activityDetail.z, 1)
|
|
151
|
-
|
|
152
|
-
const now = Math.floor(Date.now() / 1000)
|
|
153
|
-
const finished = actions.setDuration.assignment(
|
|
154
|
-
{ ...machine.initialState.context, activityDetail: { activityBeginTime: now - 20, activityEndTime: now - 10 } },
|
|
155
|
-
{}
|
|
156
|
-
)
|
|
157
|
-
assert.equal(finished.status, 'finished')
|
|
158
|
-
assert.equal(finished.duration, 0)
|
|
159
|
-
|
|
160
|
-
const started = actions.setDuration.assignment(
|
|
161
|
-
{ ...machine.initialState.context, activityDetail: { activityBeginTime: now - 1, activityEndTime: now + 20 } },
|
|
162
|
-
{}
|
|
163
|
-
)
|
|
164
|
-
assert.equal(started.status, 'started')
|
|
165
|
-
assert.equal(started.duration > 0, true)
|
|
166
|
-
|
|
167
|
-
const notStarted = actions.setDuration.assignment(
|
|
168
|
-
{ ...machine.initialState.context, activityDetail: { activityBeginTime: now + 20, activityEndTime: now + 40 } },
|
|
169
|
-
{}
|
|
170
|
-
)
|
|
171
|
-
assert.equal(notStarted.status, 'not-started')
|
|
172
|
-
assert.equal(notStarted.duration > 0, true)
|
|
173
|
-
|
|
174
|
-
assert.equal(guards.isExpired({ duration: 0 }), true)
|
|
175
|
-
assert.equal(guards.isExpired({ duration: 1 }), false)
|
|
176
|
-
|
|
177
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
178
|
-
assert.equal(detail.activityNo, 'A1')
|
|
179
|
-
assert.equal(calls.length, 1)
|
|
180
|
-
})
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
import { interpret, State } from 'xstate'
|
|
4
|
-
|
|
5
|
-
import diamondShopVnFactory from '../src/machine/activity/diamond_shop_activity_vn.js'
|
|
6
|
-
import diamondShopCashFactory from '../src/machine/activity/diamond_shop_activity_cash.js'
|
|
7
|
-
import inviteFriendsFactory from '../src/machine/activity/invite_friends_activity.js'
|
|
8
|
-
import bankBindingAmbFactory from '../src/machine/bank_binding_amb.js'
|
|
9
|
-
|
|
10
|
-
test('diamond_shop_activity_vn actions/guards/services cover selection and settlement flow', async () => {
|
|
11
|
-
const sent = []
|
|
12
|
-
const request = {
|
|
13
|
-
config: { appSecret: 'secret' },
|
|
14
|
-
send: async (req) => {
|
|
15
|
-
sent.push(req)
|
|
16
|
-
if (req.url === 'activities/list') return { data: [{ activityType: 91, activityNo: 'A1' }] }
|
|
17
|
-
if (req.url === 'activities') return { data: { activityNo: 'A1', awards: [{ id: 1 }] } }
|
|
18
|
-
if (req.url === 'activities/exchange/diamond/max-amount') return { data: { addCash: 200, subtractDiamond: 20 } }
|
|
19
|
-
if (req.url === 'activities/exchange/diamond/settle') return { ok: true }
|
|
20
|
-
return {}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
const machine = diamondShopVnFactory(request)
|
|
24
|
-
const { actions, guards, services } = machine.options
|
|
25
|
-
|
|
26
|
-
assert.equal(
|
|
27
|
-
actions.setDiamondShopActivities.assignment(machine.initialState.context, { data: [{ activityType: 91, activityNo: 'A1' }] }).activityNo,
|
|
28
|
-
'A1'
|
|
29
|
-
)
|
|
30
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { x: 1 } }).activityDetail.x, 1)
|
|
31
|
-
assert.equal(actions.setAwardList.assignment(machine.initialState.context, { data: { awards: [{ id: 1 }] } }).awardList.length, 1)
|
|
32
|
-
|
|
33
|
-
const selected = actions.selectExchangeAmount.assignment(
|
|
34
|
-
{ ...machine.initialState.context, totalAmount: 10, subtractPoints: 2 },
|
|
35
|
-
{ data: { award: 3, points: 4 } }
|
|
36
|
-
)
|
|
37
|
-
assert.equal(selected.totalAmount, 13)
|
|
38
|
-
assert.equal(selected.subtractPoints, 6)
|
|
39
|
-
|
|
40
|
-
const maxed = actions.setMaxExchangeAmount.assignment(machine.initialState.context, { data: { addCash: 123, subtractDiamond: 45 } })
|
|
41
|
-
assert.equal(maxed.totalAmount, 123)
|
|
42
|
-
assert.equal(maxed.subtractPoints, 45)
|
|
43
|
-
assert.equal(actions.resetExchangeAmount.assignment(machine.initialState.context, {}).totalAmount, 0)
|
|
44
|
-
|
|
45
|
-
let called = 0
|
|
46
|
-
const cbPatch = actions.setCallback.assignment(machine.initialState.context, { data: { callback: () => called++ } })
|
|
47
|
-
actions.doCallback({ callback: cbPatch.callback }, {})
|
|
48
|
-
assert.equal(called, 1)
|
|
49
|
-
|
|
50
|
-
assert.equal(guards.settlable({ totalPoints: 10, totalAmount: 5, subtractPoints: 9 }), true)
|
|
51
|
-
assert.equal(guards.hasActivityNo({ activityNo: 'A1' }), true)
|
|
52
|
-
|
|
53
|
-
const list = await services.fetchActivityList({}, {})
|
|
54
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
55
|
-
const max = await services.fetchMaxExchangeAmount({ activityNo: 'A1' }, {})
|
|
56
|
-
await services.settleAmount({ activityNo: 'A1', totalAmount: 50 }, {})
|
|
57
|
-
assert.equal(list.length, 1)
|
|
58
|
-
assert.equal(detail.activityNo, 'A1')
|
|
59
|
-
assert.equal(max.addCash, 200)
|
|
60
|
-
assert.equal(
|
|
61
|
-
sent.some((req) => req.url === 'activities/exchange/diamond/settle'),
|
|
62
|
-
true
|
|
63
|
-
)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('diamond_shop_activity_cash actions/guards/services cover points and settle branches', async () => {
|
|
67
|
-
const sent = []
|
|
68
|
-
const request = {
|
|
69
|
-
config: { appSecret: 'secret' },
|
|
70
|
-
send: async (req) => {
|
|
71
|
-
sent.push(req)
|
|
72
|
-
if (req.url === 'activities/list') return { data: [{ activityType: 91, activityNo: 'A2' }] }
|
|
73
|
-
if (req.url === 'activities') return { data: { activityNo: 'A2', awards: [{ id: 2 }] } }
|
|
74
|
-
if (req.url === 'activities/exchange/diamond/max-amount') return { data: { addCash: 20, subtractDiamond: 2 } }
|
|
75
|
-
if (req.url === 'activities/exchange/diamond/settle') return { ok: true }
|
|
76
|
-
return {}
|
|
77
|
-
},
|
|
78
|
-
}
|
|
79
|
-
const machine = diamondShopCashFactory(request)
|
|
80
|
-
const { actions, guards, services } = machine.options
|
|
81
|
-
|
|
82
|
-
assert.equal(
|
|
83
|
-
actions.setDiamondShopActivities.assignment(machine.initialState.context, { data: [{ activityType: 91, activityNo: 'A2' }] }).activityNo,
|
|
84
|
-
'A2'
|
|
85
|
-
)
|
|
86
|
-
assert.equal(actions.setActivityDetail.assignment(machine.initialState.context, { data: { y: 1 } }).activityDetail.y, 1)
|
|
87
|
-
assert.equal(actions.setAwardList.assignment(machine.initialState.context, { data: { awards: [{ id: 2 }] } }).awardList.length, 1)
|
|
88
|
-
assert.equal(actions.setTotalPoints.assignment(machine.initialState.context, { data: 99 }).totalPoints, 99)
|
|
89
|
-
|
|
90
|
-
const selected = actions.selectExchangeAmount.assignment(
|
|
91
|
-
{ ...machine.initialState.context, totalAmount: 1, subtractPoints: 1 },
|
|
92
|
-
{ data: { award: 3, points: 4 } }
|
|
93
|
-
)
|
|
94
|
-
assert.equal(selected.totalAmount, 4)
|
|
95
|
-
assert.equal(selected.subtractPoints, 5)
|
|
96
|
-
|
|
97
|
-
const maxed = actions.setMaxExchangeAmount.assignment(machine.initialState.context, { data: { addCash: 30, subtractDiamond: 3 } })
|
|
98
|
-
assert.equal(maxed.totalAmount, 30)
|
|
99
|
-
assert.equal(maxed.subtractPoints, 3)
|
|
100
|
-
const resetExchange = actions.resetExchangeAmount.assignment({ ...machine.initialState.context, totalAmount: 99, subtractPoints: 9 }, {})
|
|
101
|
-
assert.equal(resetExchange.totalAmount, 0)
|
|
102
|
-
assert.equal(resetExchange.subtractPoints, 0)
|
|
103
|
-
|
|
104
|
-
const cbPatch = actions.setCallback.assignment(machine.initialState.context, { data: {} })
|
|
105
|
-
assert.equal(typeof cbPatch.callback, 'function')
|
|
106
|
-
|
|
107
|
-
assert.equal(guards.settlable({ totalPoints: 10, totalAmount: 5, subtractPoints: 11 }), false)
|
|
108
|
-
assert.equal(guards.hasActivityNo({ activityNo: null }), false)
|
|
109
|
-
|
|
110
|
-
const list = await services.fetchActivityList({}, {})
|
|
111
|
-
const detail = await services.fetchActivityDetail({ activityNo: 'A2' }, {})
|
|
112
|
-
const max = await services.fetchMaxExchangeAmount({ activityNo: 'A2' }, {})
|
|
113
|
-
await services.settleAmount({ activityNo: 'A2', totalAmount: 8 }, {})
|
|
114
|
-
assert.equal(list.length, 1)
|
|
115
|
-
assert.equal(detail.activityNo, 'A2')
|
|
116
|
-
assert.equal(max.addCash, 20)
|
|
117
|
-
assert.equal(
|
|
118
|
-
sent.some((req) => req.url === 'activities/exchange/diamond/settle'),
|
|
119
|
-
true
|
|
120
|
-
)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('invite_friends_activity actions/services cover fetch-bind-award branches', async () => {
|
|
124
|
-
const sent = []
|
|
125
|
-
const request = {
|
|
126
|
-
config: { appSecret: 'secret' },
|
|
127
|
-
send: async (req) => {
|
|
128
|
-
sent.push(req)
|
|
129
|
-
if (req.url === 'friends' && req.method === 'get') return { friendCode: 'F1', downlineCount: 12 }
|
|
130
|
-
if (req.url === 'friends' && req.method === 'post') return { ok: true }
|
|
131
|
-
if (req.url === 'activities/sentAward') return { data: { awarded: true } }
|
|
132
|
-
return {}
|
|
133
|
-
},
|
|
134
|
-
}
|
|
135
|
-
const machine = inviteFriendsFactory(request)
|
|
136
|
-
const { actions, services } = machine.options
|
|
137
|
-
|
|
138
|
-
assert.equal(actions.setFriendCode.assignment(machine.initialState.context, { data: { friendCode: 'F2', downlineCount: 4 } }).friendCode, 'F2')
|
|
139
|
-
assert.equal(actions.setBindingCode.assignment(machine.initialState.context, { data: { bindingCode: 'B1' } }).bindingCode, 'B1')
|
|
140
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: { activityNo: 'A1' } }).activityNo, 'A1')
|
|
141
|
-
assert.equal(actions.setUidSite.assignment(machine.initialState.context, { data: { uidSite: 'U1' } }).uidSite, 'U1')
|
|
142
|
-
|
|
143
|
-
const fetched = await services.fetchFriends({}, {})
|
|
144
|
-
assert.equal(fetched.friendCode, 'F1')
|
|
145
|
-
await services.postFriends({ bindingCode: 'B1' }, {})
|
|
146
|
-
const awarded = await services.awardPrize({ activityNo: 'A1', uidSite: 'U1', bindingCode: 'B1' }, {})
|
|
147
|
-
assert.equal(awarded.awarded, true)
|
|
148
|
-
|
|
149
|
-
const service = interpret(machine).start()
|
|
150
|
-
service.send({ type: 'FETCH_FRIEND_CODE' })
|
|
151
|
-
await new Promise((r) => setTimeout(r, 0))
|
|
152
|
-
assert.equal(service.state.value, 'idle')
|
|
153
|
-
service.send({ type: 'BIND_FRIEND_CODE', data: { activityNo: 'A1', bindingCode: 'B1', uidSite: 'U1' } })
|
|
154
|
-
await new Promise((r) => setTimeout(r, 0))
|
|
155
|
-
assert.equal(['awarding', 'bound', 'idle'].includes(String(service.state.value)), true)
|
|
156
|
-
service.stop()
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
test('bank_binding_amb actions/guards/services and BIND_BANK transition are covered', async () => {
|
|
160
|
-
const sent = []
|
|
161
|
-
const request = {
|
|
162
|
-
config: { appSecret: 'secret' },
|
|
163
|
-
send: async (req) => {
|
|
164
|
-
sent.push(req)
|
|
165
|
-
if (req.url?.includes('getBindingBankList')) return [{ bankCode: 'B1' }, { bankCode: 'B2' }]
|
|
166
|
-
if (req.url?.includes('paymentInfo')) return { bankInfo: [{ holderName: 'H1' }] }
|
|
167
|
-
return { ok: true }
|
|
168
|
-
},
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const machine = bankBindingAmbFactory(request)
|
|
172
|
-
const { actions, guards, services } = machine.options
|
|
173
|
-
|
|
174
|
-
const banks = actions.setBanks.assignment(machine.initialState.context, {
|
|
175
|
-
data: { bankList: [{ bankCode: 'B1' }], paymentInfo: { bankInfo: [{ holderName: 'H1' }] } },
|
|
176
|
-
})
|
|
177
|
-
assert.equal(banks.hasAnyAccount, true)
|
|
178
|
-
assert.equal(banks.bank.bankCode, 'B1')
|
|
179
|
-
|
|
180
|
-
assert.ok(guards.isBindable({ bank: { bankCode: 'B1' }, bankAccount: '123', firstNameTh: 'a', lastNameTh: 'b', firstNameEn: 'c', lastNameEn: 'd' }))
|
|
181
|
-
|
|
182
|
-
let state = State.from('idle', machine.initialState.context)
|
|
183
|
-
state = machine.transition(state, { type: 'SET_BANK_CODE', data: { bankCode: 'B1' } })
|
|
184
|
-
state = machine.transition(state, { type: 'SET_BANK_ACCOUNT', data: '123' })
|
|
185
|
-
state = machine.transition(state, { type: 'SET_FIRST_NAME_TH', data: 'aa' })
|
|
186
|
-
state = machine.transition(state, { type: 'SET_LAST_NAME_TH', data: 'bb' })
|
|
187
|
-
state = machine.transition(state, { type: 'SET_FIRST_NAME_EN', data: 'cc' })
|
|
188
|
-
state = machine.transition(state, { type: 'SET_LAST_NAME_EN', data: 'dd' })
|
|
189
|
-
const toBinding = machine.transition(state, { type: 'BIND_BANK' })
|
|
190
|
-
assert.equal(toBinding.value, 'binding')
|
|
191
|
-
|
|
192
|
-
await services.fetchInitData({}, {})
|
|
193
|
-
await services.updatePaymentInfo(
|
|
194
|
-
{ bank: { bankCode: 'B1' }, bankAccount: '123', firstNameTh: 'aa', lastNameTh: 'bb', firstNameEn: 'cc', lastNameEn: 'dd' },
|
|
195
|
-
{}
|
|
196
|
-
)
|
|
197
|
-
assert.equal(
|
|
198
|
-
sent.some((req) => req.url?.includes('updatePaymentInfo')),
|
|
199
|
-
true
|
|
200
|
-
)
|
|
201
|
-
})
|