@jetthai/cuora 1.2.0 → 2.0.0-beta.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 (166) hide show
  1. package/BREAKING_CHANGES.md +9 -0
  2. package/CHANGELOG.md +36 -0
  3. package/package.json +5 -2
  4. package/resetGitBranch.sh +16 -16
  5. package/src/api/account.js +8 -0
  6. package/src/api/auth.js +1 -1
  7. package/src/api/common.js +6 -1
  8. package/src/api/index.js +3 -1
  9. package/src/api/otp.js +5 -0
  10. package/src/api/user.js +1 -0
  11. package/src/machine/activity/activity.js +23 -19
  12. package/src/machine/activity/activity_cash.js +27 -22
  13. package/src/machine/activity/cash_rain_activity.js +1 -0
  14. package/src/machine/activity/continue_deposit_activity.js +1 -0
  15. package/src/machine/activity/deposit_activity.js +1 -0
  16. package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
  17. package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
  19. package/src/machine/activity/fafafa_activity.js +1 -0
  20. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  21. package/src/machine/activity/instant_rebate_activity.js +1 -0
  22. package/src/machine/activity/invite_friends_activity.js +1 -0
  23. package/src/machine/activity/jackpot.js +1 -0
  24. package/src/machine/activity/mini_game_activity.js +1 -0
  25. package/src/machine/activity/otp_verified_activity.js +1 -0
  26. package/src/machine/activity/ranking_activity.js +1 -0
  27. package/src/machine/activity/return_bonus_activity.js +3 -1
  28. package/src/machine/activity/roulette_activity_v2.js +6 -0
  29. package/src/machine/activity/sign_in_activity.js +1 -0
  30. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  31. package/src/machine/activity/specify_bets_activity.js +1 -0
  32. package/src/machine/activity/specify_turnover_activity.js +1 -0
  33. package/src/machine/activity/time_bomb_activity.js +1 -0
  34. package/src/machine/activity/vip_card_activity.js +1 -0
  35. package/src/machine/auth.js +18 -6
  36. package/src/machine/auth_otp_v2.js +1 -0
  37. package/src/machine/auth_otp_v3.js +48 -11
  38. package/src/machine/bank_binding.js +1 -0
  39. package/src/machine/bank_binding_amb.js +1 -0
  40. package/src/machine/bonus.js +1 -0
  41. package/src/machine/common.js +24 -4
  42. package/src/machine/deposit/amb.js +1 -0
  43. package/src/machine/deposit/crypto_bank.js +20 -5
  44. package/src/machine/deposit/crypto_bank_cash.js +35 -9
  45. package/src/machine/deposit/crypto_qrcode.js +11 -1
  46. package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
  47. package/src/machine/deposit/crypto_way.js +11 -5
  48. package/src/machine/deposit/crypto_way_cash.js +15 -6
  49. package/src/machine/deposit/deposit_fc.js +1 -0
  50. package/src/machine/deposit/direct.js +1 -0
  51. package/src/machine/deposit/direct_cash.js +1 -0
  52. package/src/machine/deposit/float.js +1 -0
  53. package/src/machine/deposit/krway.js +1 -0
  54. package/src/machine/deposit/loadcard_cash.js +2 -1
  55. package/src/machine/deposit/loadcard_vn.js +1 -0
  56. package/src/machine/deposit/manual_cash.js +1 -0
  57. package/src/machine/deposit/manual_vn.js +1 -0
  58. package/src/machine/deposit/qrcode_cash.js +6 -5
  59. package/src/machine/deposit/qrcode_v2.js +1 -0
  60. package/src/machine/deposit/usdt.js +23 -4
  61. package/src/machine/deposit/usdt_cash.js +15 -1
  62. package/src/machine/deposit/virtual_bank_cash.js +11 -9
  63. package/src/machine/deposit/virtual_bank_vn.js +1 -0
  64. package/src/machine/deposit/vpay.js +7 -0
  65. package/src/machine/error.js +1 -0
  66. package/src/machine/game_betslip.js +1 -0
  67. package/src/machine/game_favorite_v2.js +1 -0
  68. package/src/machine/game_hot_new.js +1 -0
  69. package/src/machine/game_info.js +5 -0
  70. package/src/machine/game_replay.js +1 -0
  71. package/src/machine/game_search_cash.js +1 -0
  72. package/src/machine/game_search_v2.js +1 -0
  73. package/src/machine/game_v2_1.js +88 -46
  74. package/src/machine/honor_board.js +1 -0
  75. package/src/machine/honor_board_cash.js +11 -8
  76. package/src/machine/inbox.js +93 -43
  77. package/src/machine/leaderboard.js +1 -0
  78. package/src/machine/merge.js +1 -0
  79. package/src/machine/navbar.js +3 -1
  80. package/src/machine/payment_data.js +1 -0
  81. package/src/machine/promotions.js +11 -18
  82. package/src/machine/ranking.js +5 -2
  83. package/src/machine/reward.js +1 -0
  84. package/src/machine/reward_cash.js +1 -0
  85. package/src/machine/reward_fc.js +1 -0
  86. package/src/machine/roulette_v2.js +18 -26
  87. package/src/machine/setting.js +1 -0
  88. package/src/machine/side.js +10 -4
  89. package/src/machine/side_cash.js +1 -0
  90. package/src/machine/side_v2.js +38 -24
  91. package/src/machine/user_info.js +1 -0
  92. package/src/machine/user_photo.js +1 -0
  93. package/src/machine/user_reset_password.js +5 -2
  94. package/src/machine/user_sign_up.js +1 -0
  95. package/src/machine/vip_table.js +1 -0
  96. package/src/machine/websocket.js +42 -14
  97. package/src/machine/welcome.js +1 -0
  98. package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
  99. package/src/machine/withdraw/withdraw_krway.js +1 -0
  100. package/src/machine/withdraw/withdraw_manual.js +16 -8
  101. package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
  102. package/src/request/request.js +34 -30
  103. package/src/util/deviceToken.js +7 -6
  104. package/src/util/storage.js +4 -3
  105. package/test/api.behavior.test.js +69 -0
  106. package/test/api.contract.test.js +18 -0
  107. package/test/config.test.js +27 -0
  108. package/test/deviceToken.test.js +139 -0
  109. package/test/helpers.coverage.test.js +11 -0
  110. package/test/helpers.js +91 -0
  111. package/test/index.exports.test.js +14 -0
  112. package/test/machine.activity.core.coverage.test.js +337 -0
  113. package/test/machine.activity.gap.coverage.test.js +252 -0
  114. package/test/machine.activity.more.coverage.test.js +180 -0
  115. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  116. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  117. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  118. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  119. package/test/machine.auth.coverage.test.js +215 -0
  120. package/test/machine.bank_binding.test.js +143 -0
  121. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  122. package/test/machine.contract.test.js +50 -0
  123. package/test/machine.crypto_bank.coverage.test.js +270 -0
  124. package/test/machine.crypto_way.coverage.test.js +108 -0
  125. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  126. package/test/machine.definition.test.js +137 -0
  127. package/test/machine.deposit.manual.coverage.test.js +365 -0
  128. package/test/machine.deposit_fc.coverage.test.js +126 -0
  129. package/test/machine.direct.coverage.test.js +96 -0
  130. package/test/machine.direct_cash.coverage.test.js +108 -0
  131. package/test/machine.error.coverage.test.js +37 -0
  132. package/test/machine.events.test.js +126 -0
  133. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  134. package/test/machine.float.coverage.test.js +136 -0
  135. package/test/machine.flow.test.js +226 -0
  136. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  137. package/test/machine.game_search_cash.coverage.test.js +155 -0
  138. package/test/machine.game_search_v2.test.js +199 -0
  139. package/test/machine.game_user_profile.coverage.test.js +100 -0
  140. package/test/machine.honor_board.test.js +133 -0
  141. package/test/machine.inbox.common.coverage.test.js +304 -0
  142. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  143. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  144. package/test/machine.misc.coverage.test.js +361 -0
  145. package/test/machine.more2.coverage.test.js +261 -0
  146. package/test/machine.options.execution.test.js +272 -0
  147. package/test/machine.priority.coverage.test.js +603 -0
  148. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  149. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  150. package/test/machine.regression.test.js +82 -0
  151. package/test/machine.roulette_v2.test.js +142 -0
  152. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  153. package/test/machine.targeted.coverage.test.js +313 -0
  154. package/test/machine.usdt.coverage.test.js +95 -0
  155. package/test/machine.usdt_cash.coverage.test.js +73 -0
  156. package/test/machine.vip_card_activity.test.js +114 -0
  157. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  158. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  159. package/test/machine.vpay.coverage.test.js +142 -0
  160. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  161. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  162. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  163. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  164. package/test/request.test.js +325 -0
  165. package/test/util.storage.errors.test.js +47 -0
  166. package/test/util.test.js +41 -0
@@ -0,0 +1,91 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ })
@@ -0,0 +1,337 @@
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
+ })
@@ -0,0 +1,252 @@
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
+ })