@@ -3,7 +3,6 @@ import { BuyTradeResponse } from 'invity-api';
3
3
4
4
import { configureMockStore , extraDependenciesMock } from '@suite-common/test-utils' ;
5
5
import { Account } from '@suite-common/wallet-types' ;
6
- import { analytics } from '@trezor/suite-analytics' ;
7
6
8
7
import { MIN_MAX_QUOTES_OK } from '../../../__fixtures__/buyUtils' ;
9
8
import { invityAPI } from '../../../invityAPI' ;
@@ -46,7 +45,7 @@ describe('confirmTradeThunk', () => {
46
45
} ) ;
47
46
48
47
const mockProcessResponseData = jest . fn ( ) ;
49
- const mockAnalyticsReport = jest . spyOn ( analytics , 'report' ) ;
48
+ const mocktriggerAnalyticsTradeConfirmation = jest . fn ( ) ;
50
49
51
50
const tradeForm = {
52
51
form : {
@@ -62,13 +61,13 @@ describe('confirmTradeThunk', () => {
62
61
return {
63
62
store,
64
63
mockProcessResponseData,
65
- mockAnalyticsReport ,
64
+ mocktriggerAnalyticsTradeConfirmation ,
66
65
tradeForm,
67
66
} ;
68
67
} ;
69
68
70
69
it ( 'should not trigger any action if selectedQuote is not set' , async ( ) => {
71
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( {
70
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = getMocks ( {
72
71
selectedQuote : undefined ,
73
72
} ) ;
74
73
@@ -82,19 +81,21 @@ describe('confirmTradeThunk', () => {
82
81
descriptor : 'desc' ,
83
82
index : 1 ,
84
83
} as Account ,
84
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
85
85
processResponseData : mockProcessResponseData ,
86
86
} ) ,
87
87
) ;
88
88
89
89
expect ( store . getActions ( ) . length ) . toEqual ( 2 ) ;
90
90
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
91
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 0 ) ;
91
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 0 ) ;
92
92
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
93
93
} ) ;
94
94
95
95
describe ( 'should show error toast' , ( ) => {
96
96
it ( 'if there is no response' , async ( ) => {
97
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
97
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
98
+ getMocks ( ) ;
98
99
99
100
invityAPI . doBuyTrade = ( ) => Promise . resolve ( undefined as unknown as BuyTradeResponse ) ;
100
101
@@ -108,6 +109,7 @@ describe('confirmTradeThunk', () => {
108
109
descriptor : 'desc' ,
109
110
index : 1 ,
110
111
} as Account ,
112
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
111
113
processResponseData : mockProcessResponseData ,
112
114
} ) ,
113
115
) ;
@@ -116,15 +118,16 @@ describe('confirmTradeThunk', () => {
116
118
. getActions ( )
117
119
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
118
120
119
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
121
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 1 ) ;
120
122
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
121
123
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
122
124
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
123
125
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
124
126
} ) ;
125
127
126
128
it ( 'if there is no trade in response' , async ( ) => {
127
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
129
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
130
+ getMocks ( ) ;
128
131
129
132
invityAPI . doBuyTrade = ( ) => Promise . resolve ( { } as BuyTradeResponse ) ;
130
133
@@ -138,6 +141,7 @@ describe('confirmTradeThunk', () => {
138
141
descriptor : 'desc' ,
139
142
index : 1 ,
140
143
} as Account ,
144
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
141
145
processResponseData : mockProcessResponseData ,
142
146
} ) ,
143
147
) ;
@@ -146,15 +150,16 @@ describe('confirmTradeThunk', () => {
146
150
. getActions ( )
147
151
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
148
152
149
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
153
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 1 ) ;
150
154
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
151
155
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
152
156
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
153
157
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
154
158
} ) ;
155
159
156
160
it ( 'if there is no response trade payment id' , async ( ) => {
157
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
161
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
162
+ getMocks ( ) ;
158
163
159
164
invityAPI . doBuyTrade = ( ) =>
160
165
Promise . resolve ( {
@@ -174,6 +179,7 @@ describe('confirmTradeThunk', () => {
174
179
descriptor : 'desc' ,
175
180
index : 1 ,
176
181
} as Account ,
182
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
177
183
processResponseData : mockProcessResponseData ,
178
184
} ) ,
179
185
) ;
@@ -182,15 +188,16 @@ describe('confirmTradeThunk', () => {
182
188
. getActions ( )
183
189
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
184
190
185
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
191
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 1 ) ;
186
192
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
187
193
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
188
194
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
189
195
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
190
196
} ) ;
191
197
192
198
it ( 'if there is trade error' , async ( ) => {
193
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
199
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
200
+ getMocks ( ) ;
194
201
const error = 'Error message from API' ;
195
202
196
203
invityAPI . doBuyTrade = ( ) =>
@@ -211,14 +218,15 @@ describe('confirmTradeThunk', () => {
211
218
descriptor : 'desc' ,
212
219
index : 1 ,
213
220
} as Account ,
221
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
214
222
processResponseData : mockProcessResponseData ,
215
223
} ) ,
216
224
) ;
217
225
218
226
const toastAction = store
219
227
. getActions ( )
220
228
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
221
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
229
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 1 ) ;
222
230
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
223
231
expect ( toastAction ?. payload . error ) . toEqual ( error ) ;
224
232
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -227,7 +235,8 @@ describe('confirmTradeThunk', () => {
227
235
} ) ;
228
236
229
237
it ( 'should call processResponseData with response and save trade' , async ( ) => {
230
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
238
+ const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
239
+ getMocks ( ) ;
231
240
232
241
const dateString = new Date ( ) . toISOString ( ) ;
233
242
jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( ( ) => dateString ) ;
@@ -249,13 +258,14 @@ describe('confirmTradeThunk', () => {
249
258
descriptor : 'desc' ,
250
259
index : 1 ,
251
260
} as Account ,
261
+ triggerAnalyticsTradeConfirmation : mocktriggerAnalyticsTradeConfirmation ,
252
262
processResponseData : mockProcessResponseData ,
253
263
} ) ,
254
264
) ;
255
265
256
266
const { trades } = store . getState ( ) . wallet . trading ;
257
267
258
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
268
+ expect ( mocktriggerAnalyticsTradeConfirmation ) . toHaveBeenCalledTimes ( 1 ) ;
259
269
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 1 ) ;
260
270
expect ( trades . length ) . toEqual ( 1 ) ;
261
271
expect ( trades [ 0 ] ) . toEqual ( {
0 commit comments