@@ -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 mockAnalyticsTriggerConfirm = 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
+ mockAnalyticsTriggerConfirm ,
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, mockAnalyticsTriggerConfirm } = getMocks ( {
72
71
selectedQuote : undefined ,
73
72
} ) ;
74
73
@@ -82,19 +81,20 @@ describe('confirmTradeThunk', () => {
82
81
descriptor : 'desc' ,
83
82
index : 1 ,
84
83
} as Account ,
84
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
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 ( mockAnalyticsTriggerConfirm ) . 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, mockAnalyticsTriggerConfirm } = getMocks ( ) ;
98
98
99
99
invityAPI . doBuyTrade = ( ) => Promise . resolve ( undefined as unknown as BuyTradeResponse ) ;
100
100
@@ -108,6 +108,7 @@ describe('confirmTradeThunk', () => {
108
108
descriptor : 'desc' ,
109
109
index : 1 ,
110
110
} as Account ,
111
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
111
112
processResponseData : mockProcessResponseData ,
112
113
} ) ,
113
114
) ;
@@ -116,15 +117,15 @@ describe('confirmTradeThunk', () => {
116
117
. getActions ( )
117
118
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
118
119
119
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
120
+ expect ( mockAnalyticsTriggerConfirm ) . toHaveBeenCalledTimes ( 1 ) ;
120
121
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
121
122
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
122
123
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
123
124
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
124
125
} ) ;
125
126
126
127
it ( 'if there is no trade in response' , async ( ) => {
127
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
128
+ const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks ( ) ;
128
129
129
130
invityAPI . doBuyTrade = ( ) => Promise . resolve ( { } as BuyTradeResponse ) ;
130
131
@@ -138,6 +139,7 @@ describe('confirmTradeThunk', () => {
138
139
descriptor : 'desc' ,
139
140
index : 1 ,
140
141
} as Account ,
142
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
141
143
processResponseData : mockProcessResponseData ,
142
144
} ) ,
143
145
) ;
@@ -146,15 +148,15 @@ describe('confirmTradeThunk', () => {
146
148
. getActions ( )
147
149
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
148
150
149
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
151
+ expect ( mockAnalyticsTriggerConfirm ) . toHaveBeenCalledTimes ( 1 ) ;
150
152
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
151
153
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
152
154
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
153
155
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
154
156
} ) ;
155
157
156
158
it ( 'if there is no response trade payment id' , async ( ) => {
157
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
159
+ const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks ( ) ;
158
160
159
161
invityAPI . doBuyTrade = ( ) =>
160
162
Promise . resolve ( {
@@ -174,6 +176,7 @@ describe('confirmTradeThunk', () => {
174
176
descriptor : 'desc' ,
175
177
index : 1 ,
176
178
} as Account ,
179
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
177
180
processResponseData : mockProcessResponseData ,
178
181
} ) ,
179
182
) ;
@@ -182,15 +185,15 @@ describe('confirmTradeThunk', () => {
182
185
. getActions ( )
183
186
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
184
187
185
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
188
+ expect ( mockAnalyticsTriggerConfirm ) . toHaveBeenCalledTimes ( 1 ) ;
186
189
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
187
190
expect ( toastAction ?. payload . error ) . toEqual ( 'No response from the server' ) ;
188
191
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
189
192
expect ( store . getState ( ) . wallet . trading . buy . isLoading ) . toBeFalsy ( ) ;
190
193
} ) ;
191
194
192
195
it ( 'if there is trade error' , async ( ) => {
193
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
196
+ const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks ( ) ;
194
197
const error = 'Error message from API' ;
195
198
196
199
invityAPI . doBuyTrade = ( ) =>
@@ -211,14 +214,15 @@ describe('confirmTradeThunk', () => {
211
214
descriptor : 'desc' ,
212
215
index : 1 ,
213
216
} as Account ,
217
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
214
218
processResponseData : mockProcessResponseData ,
215
219
} ) ,
216
220
) ;
217
221
218
222
const toastAction = store
219
223
. getActions ( )
220
224
. find ( action => action . type === '@common/in-app-notifications/addToast' ) ;
221
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
225
+ expect ( mockAnalyticsTriggerConfirm ) . toHaveBeenCalledTimes ( 1 ) ;
222
226
expect ( toastAction ?. payload . type ) . toEqual ( 'error' ) ;
223
227
expect ( toastAction ?. payload . error ) . toEqual ( error ) ;
224
228
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -227,7 +231,7 @@ describe('confirmTradeThunk', () => {
227
231
} ) ;
228
232
229
233
it ( 'should call processResponseData with response and save trade' , async ( ) => {
230
- const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks ( ) ;
234
+ const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks ( ) ;
231
235
232
236
const dateString = new Date ( ) . toISOString ( ) ;
233
237
jest . spyOn ( Date . prototype , 'toISOString' ) . mockImplementation ( ( ) => dateString ) ;
@@ -249,13 +253,14 @@ describe('confirmTradeThunk', () => {
249
253
descriptor : 'desc' ,
250
254
index : 1 ,
251
255
} as Account ,
256
+ analyticsTriggerConfirm : mockAnalyticsTriggerConfirm ,
252
257
processResponseData : mockProcessResponseData ,
253
258
} ) ,
254
259
) ;
255
260
256
261
const { trades } = store . getState ( ) . wallet . trading ;
257
262
258
- expect ( mockAnalyticsReport ) . toHaveBeenCalledTimes ( 1 ) ;
263
+ expect ( mockAnalyticsTriggerConfirm ) . toHaveBeenCalledTimes ( 1 ) ;
259
264
expect ( mockProcessResponseData ) . toHaveBeenCalledTimes ( 1 ) ;
260
265
expect ( trades . length ) . toEqual ( 1 ) ;
261
266
expect ( trades [ 0 ] ) . toEqual ( {
0 commit comments