@jetthai/cuora 2.0.0-beta.1 → 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 -113
- package/src/machine/auth_otp_v3.js +11 -8
- package/src/machine/bank_binding.js +2 -3
- package/src/machine/common.js +14 -112
- 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 +18 -28
- 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 +2 -13
- package/src/machine/game_v2_1.js +42 -166
- 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 -463
- 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 -91
- package/src/machine/game_replay.js +0 -47
- package/src/machine/game_search_v2.js +0 -402
- package/src/machine/honor_board.js +0 -144
- 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 -195
- 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 -148
- 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 -629
- 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
package/test/config.test.js
DELETED
|
@@ -1,27 +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
|
-
|
|
6
|
-
test('config builds fullURL and supports setApiURL', () => {
|
|
7
|
-
const config = new Config({
|
|
8
|
-
apiURL: 'https://api.example.com',
|
|
9
|
-
apiVersion: 'v2',
|
|
10
|
-
clientId: 'cid',
|
|
11
|
-
appSecret: 'secret',
|
|
12
|
-
platform: 'web',
|
|
13
|
-
version: '1.0.0',
|
|
14
|
-
fpToken: 'fp-token',
|
|
15
|
-
sentry: null,
|
|
16
|
-
defaultChannel: 'ch',
|
|
17
|
-
defaultSubchannel: 'sub',
|
|
18
|
-
socketURL: 'wss://socket.example.com',
|
|
19
|
-
bucketName: 'bucket',
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
assert.equal(config.fullURL, 'https://api.example.com/v2/cid')
|
|
23
|
-
|
|
24
|
-
config.setApiURL('https://api2.example.com/root')
|
|
25
|
-
assert.equal(config.apiURL, 'https://api2.example.com/root')
|
|
26
|
-
assert.equal(config.fullURL, 'https://api2.example.com/root/v2/cid')
|
|
27
|
-
})
|
package/test/deviceToken.test.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { getDeviceToken, getDeviceTokenWithRetry } from '../src/util/deviceToken.js'
|
|
5
|
-
|
|
6
|
-
test('getDeviceToken returns undefined when disabled', async () => {
|
|
7
|
-
const result = await getDeviceToken({
|
|
8
|
-
enable: false,
|
|
9
|
-
fpToken: 'fp',
|
|
10
|
-
hosts: ['https://fnapi1.example.com'],
|
|
11
|
-
})
|
|
12
|
-
assert.equal(result, undefined)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('getDeviceToken handles host/input errors and reports to sentry', async () => {
|
|
16
|
-
const sentryCalls = []
|
|
17
|
-
const sentry = {
|
|
18
|
-
setTag: (...args) => sentryCalls.push(['setTag', ...args]),
|
|
19
|
-
captureException: (...args) => sentryCalls.push(['captureException', ...args]),
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const result = await getDeviceToken({
|
|
23
|
-
enable: true,
|
|
24
|
-
fpToken: 'fp',
|
|
25
|
-
hosts: null,
|
|
26
|
-
sentry,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
assert.equal(result, undefined)
|
|
30
|
-
assert.equal(
|
|
31
|
-
sentryCalls.some((entry) => entry[0] === 'captureException'),
|
|
32
|
-
true
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('getDeviceTokenWithRetry returns undefined when disabled', async () => {
|
|
37
|
-
const result = await getDeviceTokenWithRetry({
|
|
38
|
-
enable: false,
|
|
39
|
-
fpToken: 'fp',
|
|
40
|
-
hosts: ['https://fnapi1.example.com'],
|
|
41
|
-
maxRetries: 2,
|
|
42
|
-
intervalMs: 1,
|
|
43
|
-
})
|
|
44
|
-
assert.equal(result, undefined)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('getDeviceTokenWithRetry retries and throws after maxRetries', async () => {
|
|
48
|
-
await assert.rejects(
|
|
49
|
-
getDeviceTokenWithRetry({
|
|
50
|
-
enable: true,
|
|
51
|
-
fpToken: 'fp',
|
|
52
|
-
hosts: [],
|
|
53
|
-
maxRetries: 2,
|
|
54
|
-
intervalMs: 1,
|
|
55
|
-
})
|
|
56
|
-
)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test('getDeviceToken returns visitorId when loader succeeds', async () => {
|
|
60
|
-
const sentryCalls = []
|
|
61
|
-
const sentry = {
|
|
62
|
-
setTag: (...args) => sentryCalls.push(['setTag', ...args]),
|
|
63
|
-
captureException: (...args) => sentryCalls.push(['captureException', ...args]),
|
|
64
|
-
}
|
|
65
|
-
const loader = async () => ({
|
|
66
|
-
get: async () => ({ visitorId: 'dt-ok' }),
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const result = await getDeviceToken({
|
|
70
|
-
enable: true,
|
|
71
|
-
fpToken: 'fp',
|
|
72
|
-
hosts: ['https://fnapi1.example.com'],
|
|
73
|
-
sentry,
|
|
74
|
-
loader,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
assert.equal(result, 'dt-ok')
|
|
78
|
-
assert.equal(
|
|
79
|
-
sentryCalls.some((entry) => entry[0] === 'setTag' && entry[1] === 'dt' && entry[2] === 'dt-ok'),
|
|
80
|
-
true
|
|
81
|
-
)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('getDeviceTokenWithRetry returns token when loader eventually succeeds', async () => {
|
|
85
|
-
let count = 0
|
|
86
|
-
const loader = async () => ({
|
|
87
|
-
get: async () => {
|
|
88
|
-
count += 1
|
|
89
|
-
return { visitorId: count >= 2 ? 'dt-retry' : null }
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const result = await getDeviceTokenWithRetry({
|
|
94
|
-
enable: true,
|
|
95
|
-
fpToken: 'fp',
|
|
96
|
-
hosts: ['https://fnapi1.example.com'],
|
|
97
|
-
maxRetries: 3,
|
|
98
|
-
intervalMs: 1,
|
|
99
|
-
loader,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
assert.equal(result, 'dt-retry')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test('getDeviceToken normalizes and deduplicates hosts before loader', async () => {
|
|
106
|
-
let capturedEndpoints = null
|
|
107
|
-
const loader = async ({ endpoint }) => {
|
|
108
|
-
capturedEndpoints = endpoint
|
|
109
|
-
return { get: async () => ({ visitorId: 'dt-hosts' }) }
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const result = await getDeviceToken({
|
|
113
|
-
enable: true,
|
|
114
|
-
fpToken: 'fp',
|
|
115
|
-
hosts: ['https://fnapi1.example.com', 'https://fnapi2.example.com'],
|
|
116
|
-
loader,
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
assert.equal(result, 'dt-hosts')
|
|
120
|
-
assert.equal(Array.isArray(capturedEndpoints), true)
|
|
121
|
-
// fnapi* should be normalized to fp and then deduplicated into one host plus default endpoint
|
|
122
|
-
assert.equal(
|
|
123
|
-
capturedEndpoints.some((url) => String(url).includes('fp.example.com')),
|
|
124
|
-
true
|
|
125
|
-
)
|
|
126
|
-
assert.equal(capturedEndpoints.length >= 2, true)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test('getDeviceTokenWithRetry returns undefined when maxRetries is zero', async () => {
|
|
130
|
-
const result = await getDeviceTokenWithRetry({
|
|
131
|
-
enable: true,
|
|
132
|
-
fpToken: 'fp',
|
|
133
|
-
hosts: ['https://fnapi1.example.com'],
|
|
134
|
-
maxRetries: 0,
|
|
135
|
-
intervalMs: 1,
|
|
136
|
-
loader: async () => ({ get: async () => ({ visitorId: 'never-used' }) }),
|
|
137
|
-
})
|
|
138
|
-
assert.equal(result, undefined)
|
|
139
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { callWithFallback } from './helpers.js'
|
|
5
|
-
|
|
6
|
-
test('callWithFallback throws default error when no candidate returns object', () => {
|
|
7
|
-
assert.throws(
|
|
8
|
-
() => callWithFallback(() => null),
|
|
9
|
-
(error) => error instanceof Error && error.message.includes('Function did not return an object')
|
|
10
|
-
)
|
|
11
|
-
})
|
package/test/helpers.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
export function createLocalStorageMock() {
|
|
2
|
-
const store = new Map()
|
|
3
|
-
return {
|
|
4
|
-
getItem(key) {
|
|
5
|
-
return store.has(key) ? store.get(key) : null
|
|
6
|
-
},
|
|
7
|
-
setItem(key, value) {
|
|
8
|
-
store.set(key, String(value))
|
|
9
|
-
},
|
|
10
|
-
removeItem(key) {
|
|
11
|
-
store.delete(key)
|
|
12
|
-
},
|
|
13
|
-
clear() {
|
|
14
|
-
store.clear()
|
|
15
|
-
},
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function callWithFallback(fn) {
|
|
20
|
-
const candidates = [
|
|
21
|
-
[],
|
|
22
|
-
[{}],
|
|
23
|
-
[
|
|
24
|
-
{
|
|
25
|
-
appSecret: 'app-secret',
|
|
26
|
-
method: 'manual',
|
|
27
|
-
paymentMethod: 'manual',
|
|
28
|
-
provider: 'google',
|
|
29
|
-
username: 'user',
|
|
30
|
-
password: 'pwd',
|
|
31
|
-
channel: 'channel',
|
|
32
|
-
subchannel: 'subchannel',
|
|
33
|
-
payload: { amount: 1 },
|
|
34
|
-
type: 'DEPOSIT',
|
|
35
|
-
amount: 100,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
['manual'],
|
|
39
|
-
[1],
|
|
40
|
-
[undefined],
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
let lastError
|
|
44
|
-
for (const args of candidates) {
|
|
45
|
-
try {
|
|
46
|
-
const result = fn(...args)
|
|
47
|
-
if (result && typeof result === 'object') {
|
|
48
|
-
return result
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
lastError = error
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
throw lastError || new Error('Function did not return an object with fallback arguments')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function createAxiosMock() {
|
|
59
|
-
const handlers = {
|
|
60
|
-
requestSuccess: null,
|
|
61
|
-
responseSuccess: null,
|
|
62
|
-
responseError: null,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
handlers,
|
|
67
|
-
axios: {
|
|
68
|
-
defaults: {},
|
|
69
|
-
CancelToken: {
|
|
70
|
-
source: () => ({
|
|
71
|
-
token: { id: Math.random().toString(16).slice(2) },
|
|
72
|
-
cancel: () => {},
|
|
73
|
-
}),
|
|
74
|
-
},
|
|
75
|
-
interceptors: {
|
|
76
|
-
request: {
|
|
77
|
-
use: (success) => {
|
|
78
|
-
handlers.requestSuccess = success
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
response: {
|
|
82
|
-
use: (success, error) => {
|
|
83
|
-
handlers.responseSuccess = success
|
|
84
|
-
handlers.responseError = error
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
request: async (config) => ({ data: { ok: true }, config }),
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import * as cuora from '../src/index.js'
|
|
5
|
-
|
|
6
|
-
test('index exports core modules', () => {
|
|
7
|
-
assert.ok(cuora.api)
|
|
8
|
-
assert.ok(cuora.machine)
|
|
9
|
-
assert.ok(cuora.Request)
|
|
10
|
-
assert.ok(cuora.Config)
|
|
11
|
-
assert.ok(cuora.util)
|
|
12
|
-
assert.ok(cuora.constant)
|
|
13
|
-
assert.ok(cuora.storage)
|
|
14
|
-
})
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import activityFactory from '../src/machine/activity/activity.js'
|
|
5
|
-
import activityCashFactory from '../src/machine/activity/activity_cash.js'
|
|
6
|
-
import signInActivityFactory from '../src/machine/activity/sign_in_activity.js'
|
|
7
|
-
import { createLocalStorageMock } from './helpers.js'
|
|
8
|
-
|
|
9
|
-
test('activity machine covers unread, guards, delays and services', async () => {
|
|
10
|
-
global.localStorage = createLocalStorageMock()
|
|
11
|
-
|
|
12
|
-
const calls = []
|
|
13
|
-
let token = 't'
|
|
14
|
-
const request = {
|
|
15
|
-
config: { appSecret: 'secret' },
|
|
16
|
-
getToken: () => token,
|
|
17
|
-
send: async (req) => {
|
|
18
|
-
calls.push(req)
|
|
19
|
-
if (req.url === 'activities/list' || req.url === 'all-activities/list') {
|
|
20
|
-
return {
|
|
21
|
-
data: [
|
|
22
|
-
{ activityNo: 1, activityType: 1, tournament: 0 },
|
|
23
|
-
{ activityNo: 2, activityType: 2, tournament: 1 },
|
|
24
|
-
{ activityNo: 4, activityType: 4, tournament: 1 },
|
|
25
|
-
],
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (req.url === 'payment/v2/bankWallet/promotions') return [{ promotionsNo: 'P1' }]
|
|
29
|
-
if (req.url === 'activities') return { data: { activityNo: req.params.activityNo, detail: true } }
|
|
30
|
-
return {}
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
const machine = activityFactory(request)
|
|
34
|
-
const actions = machine.options.actions
|
|
35
|
-
const guards = machine.options.guards
|
|
36
|
-
const delays = machine.options.delays
|
|
37
|
-
const services = machine.options.services
|
|
38
|
-
|
|
39
|
-
assert.deepEqual(actions.setSiteConifg.assignment(machine.initialState.context, { data: { dt: true } }), {
|
|
40
|
-
siteConfig: { dt: true },
|
|
41
|
-
})
|
|
42
|
-
assert.equal(
|
|
43
|
-
actions.setTournamentList.assignment(machine.initialState.context, {
|
|
44
|
-
data: { activityList: [{ tournament: 1 }, { tournament: 0 }, { tournament: 1 }] },
|
|
45
|
-
}).tournamentList.length,
|
|
46
|
-
2
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
localStorage.setItem('unread_1_u1', 'false')
|
|
50
|
-
const listPatch = actions.setActivityList.assignment(
|
|
51
|
-
{ ...machine.initialState.context, uidSite: 'u1' },
|
|
52
|
-
{
|
|
53
|
-
data: {
|
|
54
|
-
activityList: [
|
|
55
|
-
{ activityNo: 1, activityType: 1 },
|
|
56
|
-
{ activityNo: 2, activityType: 2 },
|
|
57
|
-
{ activityNo: 9, activityType: 9 },
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
assert.equal(listPatch.activityList[0].unread, false)
|
|
63
|
-
assert.equal(listPatch.activityList[1].unread, false)
|
|
64
|
-
assert.equal(listPatch.activityList[2].unread, true)
|
|
65
|
-
assert.deepEqual(
|
|
66
|
-
actions.setActivityList.assignment({ ...machine.initialState.context, uidSite: 'u1' }, { data: { activityList: null } }).activityList,
|
|
67
|
-
[]
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
assert.deepEqual(actions.setPromotionList.assignment(machine.initialState.context, { data: { promotionList: [{ id: 1 }] } }), {
|
|
71
|
-
promotionList: [{ id: 1 }],
|
|
72
|
-
})
|
|
73
|
-
assert.equal(
|
|
74
|
-
actions.setActivitiesDetailList.assignment(machine.initialState.context, { data: [{ data: { a: 1 } }, { data: { b: 2 } }] }).activitiesDetailList
|
|
75
|
-
.length,
|
|
76
|
-
2
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
const unreadPatched = actions.setUnread.assignment(
|
|
80
|
-
{
|
|
81
|
-
...machine.initialState.context,
|
|
82
|
-
activityList: [
|
|
83
|
-
{ activityNo: 10, unread: true },
|
|
84
|
-
{ activityNo: 11, unread: true },
|
|
85
|
-
],
|
|
86
|
-
},
|
|
87
|
-
{ data: { uidSite: 'u2', activityNo: 10, unread: false } }
|
|
88
|
-
)
|
|
89
|
-
assert.equal(unreadPatched.activityList[0].unread, false)
|
|
90
|
-
assert.equal(unreadPatched.activityList[1].unread, true)
|
|
91
|
-
assert.equal(unreadPatched.uidSite, 'u2')
|
|
92
|
-
|
|
93
|
-
assert.equal(actions.resetActivities.assignment(machine.initialState.context, {}).isPlaying, true)
|
|
94
|
-
assert.equal(actions.leaveGame.assignment({ ...machine.initialState.context, isPlaying: true }, {}).isPlaying, false)
|
|
95
|
-
|
|
96
|
-
assert.equal(guards.hasSpecifyActivities({ activityList: [{ activityType: 4 }], specifyActivities: [4] }), true)
|
|
97
|
-
assert.equal(guards.hasSpecifyActivities({ activityList: [{ activityType: 1 }], specifyActivities: [4] }), false)
|
|
98
|
-
assert.equal(guards.isInGame({ isPlaying: true }), true)
|
|
99
|
-
assert.equal(guards.isNotInGame({ isPlaying: true }), false)
|
|
100
|
-
assert.equal(delays.TIMEOUT({ tick: 3 }, {}), 30)
|
|
101
|
-
|
|
102
|
-
token = 'token'
|
|
103
|
-
const listWithPromo = await services.fetchList({ ...machine.initialState.context, isPlaying: false }, {})
|
|
104
|
-
assert.equal(listWithPromo.activityList.length, 3)
|
|
105
|
-
assert.equal(listWithPromo.promotionList.length, 1)
|
|
106
|
-
|
|
107
|
-
const listInGame = await services.fetchList({ ...machine.initialState.context, isPlaying: true }, {})
|
|
108
|
-
assert.deepEqual(listInGame.promotionList, [])
|
|
109
|
-
|
|
110
|
-
token = null
|
|
111
|
-
const listNoToken = await services.fetchList({ ...machine.initialState.context, isPlaying: false }, {})
|
|
112
|
-
assert.equal(listNoToken.activityList.length, 3)
|
|
113
|
-
assert.deepEqual(listNoToken.promotionList, [])
|
|
114
|
-
|
|
115
|
-
const originalSetTimeout = global.setTimeout
|
|
116
|
-
global.setTimeout = (fn) => {
|
|
117
|
-
fn()
|
|
118
|
-
return 0
|
|
119
|
-
}
|
|
120
|
-
const details = await services.fetchActivitiesDetail(
|
|
121
|
-
{
|
|
122
|
-
activityList: [
|
|
123
|
-
{ activityNo: 4, activityType: 4 },
|
|
124
|
-
{ activityNo: 1, activityType: 1 },
|
|
125
|
-
],
|
|
126
|
-
specifyActivities: [4],
|
|
127
|
-
},
|
|
128
|
-
{}
|
|
129
|
-
)
|
|
130
|
-
global.setTimeout = originalSetTimeout
|
|
131
|
-
assert.equal(details.length, 1)
|
|
132
|
-
assert.equal(details[0].data.activityNo, 4)
|
|
133
|
-
assert.equal(calls.length > 0, true)
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test('activity_cash machine covers list/detail branches and fetch behavior', async () => {
|
|
137
|
-
global.localStorage = createLocalStorageMock()
|
|
138
|
-
const calls = []
|
|
139
|
-
let token = 't'
|
|
140
|
-
const request = {
|
|
141
|
-
config: { appSecret: 'secret' },
|
|
142
|
-
getToken: () => token,
|
|
143
|
-
send: async (req) => {
|
|
144
|
-
calls.push(req)
|
|
145
|
-
if (req.url === 'activities/list' || req.url === 'all-activities/list') {
|
|
146
|
-
return {
|
|
147
|
-
data: [
|
|
148
|
-
{ activityNo: 4, activityType: 4, tournament: 1 },
|
|
149
|
-
{ activityNo: 1, activityType: 1, tournament: 0 },
|
|
150
|
-
],
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (req.url === 'payment/v2/bankWallet/promotions') return [{ id: 'promo' }]
|
|
154
|
-
if (req.url === 'activities') return { data: { activityNo: req.params.activityNo } }
|
|
155
|
-
return {}
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
const machine = activityCashFactory(request)
|
|
159
|
-
const actions = machine.options.actions
|
|
160
|
-
const guards = machine.options.guards
|
|
161
|
-
const delays = machine.options.delays
|
|
162
|
-
const services = machine.options.services
|
|
163
|
-
|
|
164
|
-
localStorage.setItem('unread_1_u3', 'false')
|
|
165
|
-
const listPatch = actions.setActivityList.assignment(
|
|
166
|
-
{ ...machine.initialState.context, uidSite: 'u3' },
|
|
167
|
-
{
|
|
168
|
-
data: {
|
|
169
|
-
activityList: [
|
|
170
|
-
{ activityNo: 1, activityType: 1 },
|
|
171
|
-
{ activityNo: 2, activityType: 2 },
|
|
172
|
-
{ activityNo: 3, activityType: 3 },
|
|
173
|
-
],
|
|
174
|
-
},
|
|
175
|
-
}
|
|
176
|
-
)
|
|
177
|
-
assert.equal(listPatch.activityList[0].unread, false)
|
|
178
|
-
assert.equal(listPatch.activityList[1].unread, false)
|
|
179
|
-
assert.equal(listPatch.activityList[2].unread, true)
|
|
180
|
-
assert.deepEqual(
|
|
181
|
-
actions.setActivityList.assignment({ ...machine.initialState.context, uidSite: 'u3' }, { data: { activityList: null } }).activityList,
|
|
182
|
-
[]
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
assert.equal(
|
|
186
|
-
actions.setTournamentList.assignment(machine.initialState.context, { data: { activityList: [{ tournament: 1 }, { tournament: 0 }] } })
|
|
187
|
-
.tournamentList.length,
|
|
188
|
-
1
|
|
189
|
-
)
|
|
190
|
-
assert.deepEqual(actions.setPromotionList.assignment(machine.initialState.context, { data: { promotionList: [{ id: 1 }] } }), {
|
|
191
|
-
promotionList: [{ id: 1 }],
|
|
192
|
-
})
|
|
193
|
-
assert.equal(
|
|
194
|
-
actions.setUnread.assignment(
|
|
195
|
-
{
|
|
196
|
-
...machine.initialState.context,
|
|
197
|
-
activityList: [
|
|
198
|
-
{ activityNo: 9, unread: true },
|
|
199
|
-
{ activityNo: 10, unread: true },
|
|
200
|
-
],
|
|
201
|
-
},
|
|
202
|
-
{ data: { uidSite: 'u4', activityNo: 9, unread: false } }
|
|
203
|
-
).activityList[0].unread,
|
|
204
|
-
false
|
|
205
|
-
)
|
|
206
|
-
assert.equal(
|
|
207
|
-
actions.setUnread.assignment(
|
|
208
|
-
{
|
|
209
|
-
...machine.initialState.context,
|
|
210
|
-
activityList: [
|
|
211
|
-
{ activityNo: 9, unread: true },
|
|
212
|
-
{ activityNo: 10, unread: true },
|
|
213
|
-
],
|
|
214
|
-
},
|
|
215
|
-
{ data: { uidSite: 'u4', activityNo: 9, unread: false } }
|
|
216
|
-
).activityList[1].unread,
|
|
217
|
-
true
|
|
218
|
-
)
|
|
219
|
-
assert.equal(actions.setActivityDetailList.assignment(machine.initialState.context, { data: [{ data: { x: 1 } }] }).activityDetailList.length, 1)
|
|
220
|
-
assert.equal(actions.resetActivities.assignment(machine.initialState.context, {}).isPlaying, true)
|
|
221
|
-
assert.equal(actions.leaveGame.assignment({ ...machine.initialState.context, isPlaying: true }, {}).isPlaying, false)
|
|
222
|
-
|
|
223
|
-
assert.equal(guards.needFetchingDetail({ activityList: [{ activityType: 4 }], detailNeededActivityTypes: [4] }), true)
|
|
224
|
-
assert.equal(guards.needFetchingDetail({ activityList: [{ activityType: 1 }], detailNeededActivityTypes: [4] }), false)
|
|
225
|
-
assert.equal(guards.isInGame({ isPlaying: true }), true)
|
|
226
|
-
assert.equal(guards.isNotInGame({ isPlaying: false }), true)
|
|
227
|
-
assert.equal(delays.TIMEOUT({ tick: 2 }, {}), 20)
|
|
228
|
-
|
|
229
|
-
token = 'token'
|
|
230
|
-
const withToken = await services.fetchList(machine.initialState.context, {})
|
|
231
|
-
assert.equal(withToken.promotionList.length, 1)
|
|
232
|
-
token = null
|
|
233
|
-
const withoutToken = await services.fetchList(machine.initialState.context, {})
|
|
234
|
-
assert.deepEqual(withoutToken.promotionList, [])
|
|
235
|
-
|
|
236
|
-
const originalSetTimeout = global.setTimeout
|
|
237
|
-
global.setTimeout = (fn) => {
|
|
238
|
-
fn()
|
|
239
|
-
return 0
|
|
240
|
-
}
|
|
241
|
-
token = 'token'
|
|
242
|
-
const detailWithToken = await services.fetchActivityDetailList(
|
|
243
|
-
{
|
|
244
|
-
activityList: [
|
|
245
|
-
{ activityNo: 4, activityType: 4 },
|
|
246
|
-
{ activityNo: 1, activityType: 1 },
|
|
247
|
-
],
|
|
248
|
-
detailNeededActivityTypes: [4],
|
|
249
|
-
},
|
|
250
|
-
{}
|
|
251
|
-
)
|
|
252
|
-
token = null
|
|
253
|
-
const detailWithoutToken = await services.fetchActivityDetailList(
|
|
254
|
-
{ activityList: [{ activityNo: 4, activityType: 4 }], detailNeededActivityTypes: [4] },
|
|
255
|
-
{}
|
|
256
|
-
)
|
|
257
|
-
global.setTimeout = originalSetTimeout
|
|
258
|
-
assert.equal(detailWithToken.length, 1)
|
|
259
|
-
assert.deepEqual(detailWithoutToken, [])
|
|
260
|
-
assert.equal(calls.length > 0, true)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('sign_in_activity actions/guards/services cover receive and progress branches', async () => {
|
|
264
|
-
const calls = []
|
|
265
|
-
const request = {
|
|
266
|
-
config: { appSecret: 'secret' },
|
|
267
|
-
send: async (req) => {
|
|
268
|
-
calls.push(req)
|
|
269
|
-
if (req.url === 'activities') {
|
|
270
|
-
return {
|
|
271
|
-
data: {
|
|
272
|
-
activityNo: 'A1',
|
|
273
|
-
receiveNo: '2',
|
|
274
|
-
receiveStatus: 2,
|
|
275
|
-
achieve: true,
|
|
276
|
-
awards: [{ id: 1 }],
|
|
277
|
-
target: '100',
|
|
278
|
-
turnover: '75',
|
|
279
|
-
dayOfTheWeek: 5,
|
|
280
|
-
policy: 'SIGN_IN',
|
|
281
|
-
},
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (req.url === 'activities/rewards') return { data: { ok: true } }
|
|
285
|
-
return {}
|
|
286
|
-
},
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const machine = signInActivityFactory(request, { activityNo: 'A1' })
|
|
290
|
-
const actions = machine.options.actions
|
|
291
|
-
const guards = machine.options.guards
|
|
292
|
-
const services = machine.options.services
|
|
293
|
-
const receivedEntry = machine.config.states.received.entry.assignment
|
|
294
|
-
|
|
295
|
-
assert.equal(actions.setActivityNo.assignment(machine.initialState.context, { data: 'A2' }).activityNo, 'A2')
|
|
296
|
-
const detail = actions.setActivityDetail.assignment(machine.initialState.context, {
|
|
297
|
-
data: {
|
|
298
|
-
receiveNo: 1,
|
|
299
|
-
receiveStatus: 2,
|
|
300
|
-
achieve: true,
|
|
301
|
-
awards: [{ id: 1 }],
|
|
302
|
-
target: '100',
|
|
303
|
-
turnover: '26',
|
|
304
|
-
dayOfTheWeek: 3,
|
|
305
|
-
policy: 'SIGN_IN',
|
|
306
|
-
},
|
|
307
|
-
})
|
|
308
|
-
assert.equal(detail.receiveStatus, 2)
|
|
309
|
-
assert.equal(detail.rewardType, 'SIGN_IN')
|
|
310
|
-
|
|
311
|
-
assert.equal(actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: '0', target: '100' }, {}).progressStatus, 0)
|
|
312
|
-
assert.equal(actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: '25', target: '100' }, {}).progressStatus, 25)
|
|
313
|
-
assert.equal(actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: '50', target: '100' }, {}).progressStatus, 50)
|
|
314
|
-
assert.equal(actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: '75', target: '100' }, {}).progressStatus, 75)
|
|
315
|
-
assert.equal(actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: '100', target: '100' }, {}).progressStatus, 100)
|
|
316
|
-
assert.equal(
|
|
317
|
-
actions.setProgressStatus.assignment({ ...machine.initialState.context, turnover: undefined, target: undefined }, {}).progressStatus,
|
|
318
|
-
0
|
|
319
|
-
)
|
|
320
|
-
assert.equal(receivedEntry(machine.initialState.context, {}).progressStatus, 100)
|
|
321
|
-
|
|
322
|
-
let count = 0
|
|
323
|
-
const callbackPatch = actions.setCallback.assignment(machine.initialState.context, { data: { callback: () => count++ } })
|
|
324
|
-
actions.doCallback({ callback: callbackPatch.callback }, {})
|
|
325
|
-
assert.equal(count, 1)
|
|
326
|
-
|
|
327
|
-
assert.equal(guards.isReceived({ receiveStatus: 1 }), true)
|
|
328
|
-
assert.equal(guards.isReceiveable({ receiveStatus: 2 }), true)
|
|
329
|
-
|
|
330
|
-
const fetched = await services.fetchActivityDetail({ activityNo: 'A1' }, {})
|
|
331
|
-
assert.equal(fetched.activityNo, 'A1')
|
|
332
|
-
await services.receiveReward({ activityNo: 'A1', receiveNo: '2' }, {})
|
|
333
|
-
await services.receiveReward({ activityNo: 'A1', receiveNo: '0' }, {})
|
|
334
|
-
const rewardCalls = calls.filter((item) => item.url === 'activities/rewards')
|
|
335
|
-
assert.equal(rewardCalls[0].params.receiveNo, 2)
|
|
336
|
-
assert.equal(rewardCalls[1].params.receiveNo, undefined)
|
|
337
|
-
})
|