@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.
Files changed (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -112
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -98
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +8 -11
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +0 -1
  70. package/src/machine/game_v2_1.js +39 -126
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -459
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -80
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -133
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -155
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -133
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -603
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,215 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import authFactory from '../src/machine/auth.js'
5
- import { createLocalStorageMock } from './helpers.js'
6
-
7
- function createRequestStub({ deviceTokenExists = true, getDeviceTokenWithRetry } = {}) {
8
- const calls = []
9
- return {
10
- calls,
11
- request: {
12
- hosts: ['https://fnapi1.example.com'],
13
- config: {
14
- appSecret: 'secret',
15
- clientId: 'client',
16
- fpToken: 'fp-token',
17
- defaultChannel: 'default-channel',
18
- defaultSubchannel: 'default-sub',
19
- fullURL: 'https://member.example.com',
20
- sentry: {
21
- captureMessage: () => {},
22
- setUser: () => {},
23
- captureException: () => {},
24
- },
25
- getDeviceTokenWithRetry,
26
- },
27
- send: async (req) => {
28
- calls.push(req)
29
- if (req.url === 'appLogin') return { token: 'app-token' }
30
- if (req.url === 'login') return { token: 'login-token' }
31
- if (req.url === 'guestLogin') return { token: 'guest-token' }
32
- if (req.url === 'logout') return { ok: true }
33
- if (req.url === 'self') return { uid_site: 'U100', rank: 1 }
34
- if (req.url === 'checkDt') return { exist: deviceTokenExists }
35
- if (req.url === 'updateDt') return { ok: true }
36
- if (req.url === 'getConfig') {
37
- const raw = JSON.stringify({
38
- loginMethods: { local: true, phone: false },
39
- registerMethods: { local: true, email: false },
40
- dtVerify: true,
41
- })
42
- return { config: Buffer.from(raw, 'binary').toString('base64') }
43
- }
44
- return {}
45
- },
46
- },
47
- }
48
- }
49
-
50
- test('auth actions: account/token/redirect/user/play paths are covered', async () => {
51
- global.localStorage = createLocalStorageMock()
52
- global.window = {
53
- location: {
54
- href: 'https://member.example.com/current',
55
- protocol: 'https:',
56
- host: 'member.example.com',
57
- },
58
- atob: (v) => Buffer.from(v, 'base64').toString('binary'),
59
- }
60
-
61
- const { request } = createRequestStub()
62
- const machine = authFactory(request)
63
- const actions = machine.options.actions
64
- const delays = machine.options.delays
65
- const guards = machine.options.guards
66
-
67
- storageSet('cuora_client', 'token-from-storage')
68
- assert.equal(actions.fetchToken.assignment(machine.initialState.context, {}).token, 'token-from-storage')
69
-
70
- assert.equal(actions.setToken.assignment(machine.initialState.context, { data: 'token-1' }).token, 'token-1')
71
- assert.equal(actions.extendToken.assignment(machine.initialState.context, {}).token, 'token-1')
72
- assert.equal(actions.removeToken.assignment(machine.initialState.context, {}).token, null)
73
-
74
- actions.setAccount.assignment(
75
- {
76
- ...machine.initialState.context,
77
- loginData: { username: 'alice' },
78
- },
79
- {}
80
- )
81
- assert.equal(storageGet('account_username'), 'alice')
82
-
83
- actions.setAccount.assignment(
84
- {
85
- ...machine.initialState.context,
86
- loginData: { phone: '0800000000', countryCode: '66' },
87
- countryAbbr: 'TH',
88
- },
89
- {}
90
- )
91
- assert.equal(storageGet('account_phone'), '0800000000')
92
- assert.equal(storageGet('phone_countrycode'), 'TH_66')
93
-
94
- actions.setAccount.assignment(
95
- {
96
- ...machine.initialState.context,
97
- loginData: { email: 'a@example.com' },
98
- },
99
- {}
100
- )
101
- assert.equal(storageGet('account_email'), 'a@example.com')
102
-
103
- storageSet('ac', 'AFF')
104
- storageSet('nk', 'Nick')
105
- storageSet('channel', 'stored-channel')
106
- storageSet('subchannel', 'stored-sub')
107
- await actions.redirectTo3Party(
108
- {
109
- ...machine.initialState.context,
110
- base: '/entry',
111
- siteConfig: { dtVerify: false },
112
- },
113
- { data: { provider: 'google', channel: 'ev-channel', subchannel: 'ev-sub', fc: 'FC1' } }
114
- )
115
- assert.equal(window.location.href.includes('/login?'), true)
116
- assert.equal(window.location.href.includes('provider=google'), true)
117
- assert.equal(window.location.href.includes('ac=AFF'), true)
118
-
119
- const userInfoPatch = actions.setUserInfo.assignment(machine.initialState.context, { data: { uid_site: 'U100', rank: 1 } })
120
- assert.equal(userInfoPatch.userInfo.uid_site, 'U100')
121
- assert.equal(actions.setPlay.assignment(machine.initialState.context, { data: true }).isPlaying, true)
122
-
123
- const setSiteConfig = actions.setSiteConfig.assignment(machine.initialState.context, {
124
- data: {
125
- loginMethods: { local: true, phone: false },
126
- registerMethods: { local: true, email: false },
127
- },
128
- })
129
- assert.deepEqual(setSiteConfig.siteConfig.loginMethods, { local: true })
130
- assert.deepEqual(setSiteConfig.siteConfig.registerMethods, { local: true })
131
-
132
- assert.equal(delays.TIMEOUT({ tick: 2, isPlaying: false }, {}), 2)
133
- assert.equal(delays.TIMEOUT({ tick: 2, isPlaying: true }, {}), 10)
134
- assert.equal(guards.hasToken({ token: 't' }, {}), 't')
135
- assert.equal(guards.isInline({ userInfo: { rank: 0 } }, {}), true)
136
- assert.equal(guards.isNotInline({ userInfo: { rank: -1 } }, {}), true)
137
- })
138
-
139
- test('auth services: login/guest/app/logout/self/checkDt/getConfig', async () => {
140
- global.localStorage = createLocalStorageMock()
141
- global.window = {
142
- atob: (v) => Buffer.from(v, 'base64').toString('binary'),
143
- location: { href: 'https://member.example.com' },
144
- }
145
-
146
- const { request, calls } = createRequestStub()
147
- const machine = authFactory(request)
148
- const services = machine.options.services
149
-
150
- const appToken = await services.authenticateApp({}, { data: { provider: 'google', accessToken: 'at' } })
151
- assert.equal(appToken, 'app-token')
152
-
153
- const loginToken = await services.authenticate(
154
- {
155
- ...machine.initialState.context,
156
- loginData: { provider: 'local', username: 'alice', password: 'pw' },
157
- reCaptchaToken: 'captcha',
158
- },
159
- {}
160
- )
161
- assert.equal(loginToken, 'login-token')
162
-
163
- const guestToken = await services.authenticateGuest({}, {})
164
- assert.equal(guestToken, 'guest-token')
165
-
166
- const logoutRes = await services.logout({}, {})
167
- assert.equal(logoutRes.ok, true)
168
-
169
- const self = await services.fetchUserInfo({}, {})
170
- assert.equal(self.uid_site, 'U100')
171
-
172
- await services.checkDeviceToken({ siteConfig: { dtVerify: true } }, {})
173
- await services.checkDeviceToken({ siteConfig: { dtVerify: false } }, {})
174
-
175
- const cfg = await services.fetchSiteConfig({}, {})
176
- assert.equal(cfg.dtVerify, true)
177
- assert.deepEqual(cfg.loginMethods, { local: true, phone: false })
178
- assert.equal(
179
- calls.some((req) => req.url === 'checkDt'),
180
- true
181
- )
182
- assert.equal(
183
- calls.some((req) => req.url === 'getConfig'),
184
- true
185
- )
186
- })
187
-
188
- test('auth checkDeviceToken updates dt when checkDt says not exist', async () => {
189
- global.localStorage = createLocalStorageMock()
190
- global.window = {
191
- atob: (v) => Buffer.from(v, 'base64').toString('binary'),
192
- location: { href: 'https://member.example.com' },
193
- }
194
-
195
- const { request, calls } = createRequestStub({
196
- deviceTokenExists: false,
197
- getDeviceTokenWithRetry: async () => 'dt-123',
198
- })
199
- const machine = authFactory(request)
200
- const services = machine.options.services
201
-
202
- await services.checkDeviceToken({ siteConfig: { dtVerify: true } }, {})
203
- assert.equal(
204
- calls.some((req) => req.url === 'updateDt' && req.params.dt === 'dt-123'),
205
- true
206
- )
207
- })
208
-
209
- function storageGet(key) {
210
- return JSON.parse(localStorage.getItem(key)).value
211
- }
212
-
213
- function storageSet(key, value) {
214
- localStorage.setItem(key, JSON.stringify({ value }))
215
- }
@@ -1,143 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import bankBindingFactory from '../src/machine/bank_binding.js'
5
-
6
- function createRequestStub() {
7
- const calls = []
8
- return {
9
- calls,
10
- request: {
11
- config: { appSecret: 'secret' },
12
- send: async (req) => {
13
- calls.push(req)
14
- return { data: {} }
15
- },
16
- },
17
- }
18
- }
19
-
20
- test('bank_binding action: setBanks maps initial binding data', () => {
21
- const { request } = createRequestStub()
22
- const machine = bankBindingFactory(request)
23
- const setBanks = machine.options.actions.setBanks.assignment
24
-
25
- const context = { ...machine.initialState.context, currency: 'PKR' }
26
- const next = setBanks(context, {
27
- data: {
28
- paymentList: { bankList: [{ bankCode: 'B1' }] },
29
- paymentInfo: {
30
- bankInfo: [
31
- { bindingType: 'BANK', holderName: 'A', ifscCode: 'IFSC001', firstNameLocale: 'F', lastNameLocale: 'L' },
32
- { bindingType: 'CRYPTO', holderName: 'B' },
33
- ],
34
- },
35
- },
36
- })
37
-
38
- assert.equal(next.hasAnyAccount, true)
39
- assert.equal(next.hasAnyBankAccount, true)
40
- assert.equal(next.holderName, 'A')
41
- assert.equal(next.ifscCode, 'IFSC001')
42
- assert.equal(next.bank, null)
43
- })
44
-
45
- test('bank_binding guard: isBindable covers CRYPTO/EWALLET/BANK branches', () => {
46
- const { request } = createRequestStub()
47
- const machine = bankBindingFactory(request)
48
- const isBindable = machine.options.guards.isBindable
49
-
50
- assert.ok(
51
- isBindable(
52
- {
53
- bindingType: 'CRYPTO',
54
- crypto: { symbol: 'USDT' },
55
- network: { label: 'TRC20' },
56
- cryptoAddress: 'addr',
57
- holderName: 'A',
58
- },
59
- {}
60
- )
61
- )
62
- assert.ok(
63
- isBindable(
64
- {
65
- bindingType: 'EWALLET',
66
- walletCode: { bankCode: 'W1' },
67
- accountNumber: '123',
68
- firstNameLocale: 'F',
69
- lastNameLocale: 'L',
70
- },
71
- {}
72
- )
73
- )
74
- assert.ok(
75
- isBindable(
76
- {
77
- bindingType: 'BANK',
78
- currency: 'INR',
79
- bank: { bankCode: 'B1' },
80
- ifscCode: 'IFSC',
81
- accountNumber: '123',
82
- branch: 'BR',
83
- holderName: 'A',
84
- },
85
- {}
86
- )
87
- )
88
- assert.ok(
89
- isBindable(
90
- {
91
- bindingType: 'BANK',
92
- currency: 'THB',
93
- bank: { bankCode: 'B1' },
94
- accountNumber: '123',
95
- branch: 'BR',
96
- firstNameLocale: 'F',
97
- lastNameLocale: 'L',
98
- },
99
- {}
100
- )
101
- )
102
- })
103
-
104
- test('bank_binding services: fetchInitData and updatePaymentInfo build requests', async () => {
105
- const { request, calls } = createRequestStub()
106
- const machine = bankBindingFactory(request)
107
-
108
- const fetchInitData = machine.options.services.fetchInitData
109
- const updatePaymentInfo = machine.options.services.updatePaymentInfo
110
-
111
- await fetchInitData({}, {})
112
- assert.equal(calls.length, 2)
113
- assert.equal(calls[0].url.endsWith('getBindingPaymentList'), true)
114
- assert.equal(calls[1].url.endsWith('paymentInfo'), true)
115
-
116
- calls.length = 0
117
- await updatePaymentInfo(
118
- {
119
- bindingType: 'BANK',
120
- bank: { bankCode: 'B001' },
121
- ifscCode: 'IFSC',
122
- crypto: { symbol: 'USDT' },
123
- network: { label: 'TRC20' },
124
- cryptoAddress: 'ADDR',
125
- walletCode: { bankCode: 'W01' },
126
- branch: 'BLANK',
127
- branchCode: '001',
128
- accountNumber: '123456',
129
- holderName: 'Holder',
130
- firstNameLocale: 'First',
131
- lastNameLocale: 'Last',
132
- pixType: 'CPF',
133
- },
134
- {}
135
- )
136
-
137
- assert.equal(calls.length, 1)
138
- assert.equal(calls[0].url.endsWith('updatePaymentInfo'), true)
139
- assert.equal(calls[0].params.bankCode, 'B001')
140
- assert.equal(calls[0].params.branch, '')
141
- assert.equal(calls[0].params.cryptoCurrency, 'USDT')
142
- assert.equal(calls[0].params.walletCode, 'W01')
143
- })
@@ -1,223 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { interpret, State } from 'xstate'
4
-
5
- import bankBindingFactory from '../src/machine/bank_binding.js'
6
- import authOtpV2Factory from '../src/machine/auth_otp_v2.js'
7
- import krwayFactory from '../src/machine/deposit/krway.js'
8
-
9
- function waitForMatch(service, matcher, timeout = 1200) {
10
- return new Promise((resolve, reject) => {
11
- if (matcher(service.state)) {
12
- resolve(service.state)
13
- return
14
- }
15
-
16
- const timer = setTimeout(() => {
17
- sub.unsubscribe()
18
- reject(new Error('timeout waiting for state match'))
19
- }, timeout)
20
-
21
- const sub = service.subscribe((state) => {
22
- if (matcher(state)) {
23
- clearTimeout(timer)
24
- sub.unsubscribe()
25
- resolve(state)
26
- }
27
- })
28
- })
29
- }
30
-
31
- test('bank_binding idle event assignments and bind transition guards are covered', async () => {
32
- const sent = []
33
- const request = {
34
- config: { appSecret: 'secret' },
35
- send: async (req) => {
36
- sent.push(req)
37
- if (req.url?.includes('getBindingPaymentList')) return { bankList: [{ bankCode: 'B1' }] }
38
- if (req.url?.includes('paymentInfo')) return { bankInfo: [{ bindingType: 'BANK', holderName: 'H' }] }
39
- return { ok: true }
40
- },
41
- }
42
-
43
- const machine = bankBindingFactory(request)
44
-
45
- let state = State.from('idle', { ...machine.initialState.context, currency: 'INR' })
46
- state = machine.transition(state, { type: 'SET_BIND_TYPE', data: 'BANK' })
47
- state = machine.transition(state, { type: 'SET_BANK_CODE', data: { bankCode: 'B1' } })
48
- state = machine.transition(state, { type: 'SET_IFSC_CODE', data: 'IFSC' })
49
- state = machine.transition(state, { type: 'SET_BRANCH', data: 'BR' })
50
- state = machine.transition(state, { type: 'SET_ACCOUNT_NUMBER', data: '123' })
51
- state = machine.transition(state, { type: 'SET_HOLDER_NAME', data: 'Name' })
52
- state = machine.transition(state, { type: 'SET_FIRST_NAME', data: 'First' })
53
- state = machine.transition(state, { type: 'SET_LAST_NAME', data: 'Last' })
54
- state = machine.transition(state, { type: 'SET_PIX_TYPE', data: 'CPF' })
55
- state = machine.transition(state, { type: 'SET_CRYPTO_CODE', data: { symbol: 'USDT' } })
56
- state = machine.transition(state, { type: 'SET_NETWORK_CODE', data: { label: 'TRC20' } })
57
- state = machine.transition(state, { type: 'SET_CRYPTO_ADDRESS', data: 'addr' })
58
- state = machine.transition(state, { type: 'SET_WALLET_CODE', data: { bankCode: 'W1' } })
59
- state = machine.transition(state, { type: 'SET_BRANCH_CODE', data: '001' })
60
- assert.equal(state.context.bank.bankCode, 'B1')
61
- assert.equal(state.context.walletCode.bankCode, 'W1')
62
- assert.equal(state.context.branchCode, '001')
63
-
64
- const resetState = machine.transition(state, { type: 'RESET_FORM' })
65
- assert.equal(resetState.context.bank, null)
66
- assert.equal(resetState.context.lastNameLocale, null)
67
-
68
- const bindableState = State.from('idle', {
69
- ...machine.initialState.context,
70
- bindingType: 'BANK',
71
- currency: 'THB',
72
- bank: { bankCode: 'B1' },
73
- accountNumber: '123',
74
- branch: 'BR',
75
- holderName: 'Name',
76
- })
77
- const toBinding = machine.transition(bindableState, { type: 'BIND_BANK' })
78
- assert.equal(toBinding.value, 'binding')
79
-
80
- const notBindableState = State.from('idle', {
81
- ...machine.initialState.context,
82
- bindingType: 'BANK',
83
- currency: 'THB',
84
- bank: { bankCode: '' },
85
- })
86
- const stayIdle = machine.transition(notBindableState, { type: 'BIND_BANK' })
87
- assert.equal(stayIdle.value, 'idle')
88
-
89
- await machine.options.services.updatePaymentInfo(bindableState.context, {})
90
- assert.equal(
91
- sent.some((req) => req.url?.includes('updatePaymentInfo')),
92
- true
93
- )
94
- })
95
-
96
- test('auth_otp_v2 actions/services and conditional transitions are covered', async () => {
97
- const sent = []
98
- const request = {
99
- send: async (req) => {
100
- sent.push(req)
101
- if (req.url === '/verify/v2/initiate') {
102
- if (req.params.strategy === 'phone') return { status: 'success-verified', requestId: 'R1', ttl: 2, target: { phone: true } }
103
- return { status: 'otp-sent', requestId: 'R2', ttl: 2, target: { email: true } }
104
- }
105
- if (req.url === '/otpsso/reset') return { requestId: 'R3', ttl: 1, target: { email: true } }
106
- if (req.url === '/otpsso/acknowledge') {
107
- if (req.params.code === 'BAD') {
108
- const err = new Error('bad code')
109
- err.code = 'ERR_A108'
110
- throw err
111
- }
112
- if (req.params.code === 'WRONG') {
113
- const err = new Error('wrong code')
114
- err.code = 'ERR_X'
115
- throw err
116
- }
117
- return { requestId: 'R4', ttl: 9, target: { email: true } }
118
- }
119
- return {}
120
- },
121
- }
122
-
123
- const machine = authOtpV2Factory(request)
124
- const actions = machine.options.actions
125
- const services = machine.options.services
126
-
127
- assert.equal(actions.setStrategyPhone.assignment(machine.initialState.context, {}).strategy, 'phone')
128
- assert.equal(actions.setStrategyEmail.assignment(machine.initialState.context, {}).strategy, 'email')
129
- assert.equal(actions.setOtpResult.assignment(machine.initialState.context, { data: { requestId: 'A', ttl: 3, target: {} } }).ttl, 3)
130
- assert.equal(actions.decreaseTtl.assignment({ ttl: 1 }, {}).ttl, 0)
131
- assert.equal(actions.setAcknowledgeResult.assignment(machine.initialState.context, { data: { ttl: 7 } }).acknowledgeTtl, 7)
132
- assert.equal(actions.decreaseAcknowledgeTtl.assignment({ acknowledgeTtl: 1 }, {}).acknowledgeTtl, 0)
133
-
134
- const sentOtp = await services.sendOtp({ strategy: 'email' }, {})
135
- assert.equal(sentOtp.status, 'otp-sent')
136
- const resetOtp = await services.resetOtp({ requestId: 'R2', target: { email: true } }, {})
137
- assert.equal(resetOtp.requestId, 'R3')
138
- const ackOtp = await services.acknowledge({ requestId: 'R2', target: { email: true } }, { data: '123456' })
139
- assert.equal(ackOtp.requestId, 'R4')
140
-
141
- const s1 = interpret(machine).start()
142
- s1.send({ type: 'SEND_OTP_PHONE' })
143
- await waitForMatch(s1, (s) => s.matches('acknowledged'))
144
- s1.stop()
145
-
146
- const s2 = interpret(machine).start()
147
- s2.send({ type: 'SEND_OTP_EMAIL' })
148
- await waitForMatch(s2, (s) => s.matches('otp'))
149
- s2.send({ type: 'ACKNOWLEDGE', data: 'BAD' })
150
- await waitForMatch(s2, (s) => s.matches('idle'))
151
- s2.stop()
152
-
153
- const s3 = interpret(machine).start()
154
- s3.send({ type: 'SEND_OTP_EMAIL' })
155
- await waitForMatch(s3, (s) => s.matches('otp'))
156
- s3.send({ type: 'ACKNOWLEDGE', data: 'WRONG' })
157
- await waitForMatch(s3, (s) => s.matches('otp'))
158
- s3.stop()
159
-
160
- assert.equal(
161
- sent.some((req) => req.url === '/verify/v2/initiate'),
162
- true
163
- )
164
- })
165
-
166
- test('deposit krway actions/guards/services and checking transitions are covered', async () => {
167
- const sent = []
168
- const request = {
169
- send: async (req) => {
170
- sent.push(req)
171
- if (req.url === 'payment/v2/paymentDetail') {
172
- return [
173
- { category: 'other', optional: [], processing: [] },
174
- { category: 'krway', method: 'krway', optional: [{ id: 'opt' }], processing: [{ applyId: 8 }] },
175
- ]
176
- }
177
- if (req.url === 'mailbox/sendMessage') return { ok: true }
178
- if (req.url === 'payment/v2/krway/transaction') return { applyId: 9, amount: 30 }
179
- return {}
180
- },
181
- }
182
-
183
- const machine = krwayFactory(request)
184
- const { actions, guards, services } = machine.options
185
-
186
- const pd = actions.setPaymentDetail.assignment(machine.initialState.context, {
187
- data: [
188
- { category: 'other', optional: [], processing: [] },
189
- { category: 'krway', method: 'krway', optional: [{ id: 'opt' }], processing: [{ applyId: 1 }] },
190
- ],
191
- })
192
- assert.equal(pd.currentPayment.method, 'krway')
193
- assert.equal(pd.options.length, 1)
194
- assert.equal(pd.processing.applyId, 1)
195
-
196
- assert.equal(actions.addAmount.assignment({ ...machine.initialState.context, amount: 10 }, { data: 5 }).amount, 15)
197
- assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: '20' }).amount, 20)
198
- assert.equal(actions.clearAmount.assignment(machine.initialState.context, {}).amount, null)
199
- assert.equal(actions.setProcessing.assignment(machine.initialState.context, { data: { applyId: 7 } }).processing.applyId, 7)
200
- assert.equal(guards.isProcessing({ processing: null }), null)
201
-
202
- const toProcessing = machine.transition(State.from('checking', { ...machine.initialState.context, processing: { applyId: 1 } }), {
203
- type: 'xstate.init',
204
- })
205
- assert.equal(toProcessing.value, 'processing')
206
- const toIdle = machine.transition(State.from('checking', { ...machine.initialState.context, processing: null }), { type: 'xstate.init' })
207
- assert.equal(toIdle.value, 'idle')
208
-
209
- const details = await services.fetchPaymentDetail({}, {})
210
- assert.equal(details.length, 2)
211
- await services.accountInquiry({}, { data: { from: 'u1', title: 't', content: 'c' } })
212
- const submit = await services.submitDeposit({ currentPayment: { method: 'krway' }, amount: 30 }, {})
213
- assert.equal(submit.applyId, 9)
214
-
215
- assert.equal(
216
- sent.some((req) => req.url === 'mailbox/sendMessage'),
217
- true
218
- )
219
- assert.equal(
220
- sent.some((req) => req.url === 'payment/v2/krway/transaction'),
221
- true
222
- )
223
- })
@@ -1,50 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import machine from '../src/machine/index.js'
5
- import { createLocalStorageMock } from './helpers.js'
6
-
7
- const requestStub = {
8
- config: {
9
- apiURL: 'https://api.example.com',
10
- apiVersion: 'v1',
11
- clientId: 'client',
12
- appSecret: 'secret',
13
- platform: 'web',
14
- version: '1.0.0',
15
- fpToken: 'fp-token',
16
- sentry: {
17
- captureException: () => {},
18
- setTag: () => {},
19
- },
20
- defaultChannel: 'web',
21
- defaultSubchannel: 'home',
22
- socketURL: 'wss://socket.example.com',
23
- bucketName: 'bucket',
24
- },
25
- send: async () => ({}),
26
- }
27
-
28
- global.localStorage = createLocalStorageMock()
29
- global.window = {
30
- location: {
31
- search: '',
32
- href: 'https://example.com/path',
33
- origin: 'https://example.com',
34
- protocol: 'https:',
35
- host: 'example.com',
36
- },
37
- atob: (value) => Buffer.from(value, 'base64').toString('binary'),
38
- CC_JSB: false,
39
- }
40
- global.document = { cookie: '' }
41
-
42
- for (const [machineName, machineFactory] of Object.entries(machine)) {
43
- test(`machine contract: ${machineName} can be created`, () => {
44
- assert.equal(typeof machineFactory, 'function', `${machineName} should be a function`)
45
- const machineInstance = machineFactory(requestStub, {})
46
- assert.equal(typeof machineInstance.transition, 'function', `${machineName} should expose transition`)
47
- assert.ok(machineInstance.id, `${machineName} should have machine id`)
48
- assert.equal(typeof machineInstance.states, 'object', `${machineName} should expose states map`)
49
- })
50
- }