@@ -3,7 +3,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
3
3
import { InternalServerErrorException } from '@nestjs/common' ;
4
4
import { mockRedisWrongTypeError , mockStandaloneDatabaseEntity } from 'src/__mocks__' ;
5
5
import { TelemetryEvents } from 'src/constants' ;
6
- import { ReplyError } from 'src/models' ;
6
+ import { AppTool , ReplyError } from 'src/models' ;
7
7
import { CliParsingError } from 'src/modules/cli/constants/errors' ;
8
8
import { ICliExecResultFromNode } from 'src/modules/cli/services/cli-tool/cli-tool.service' ;
9
9
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto' ;
@@ -42,21 +42,21 @@ describe('CliAnalyticsService', () => {
42
42
43
43
describe ( 'sendCliClientCreatedEvent' , ( ) => {
44
44
it ( 'should emit CliClientCreated event' , ( ) => {
45
- service . sendCliClientCreatedEvent ( instanceId , { data : 'Some data' } ) ;
45
+ service . sendClientCreatedEvent ( instanceId , AppTool . CLI , { data : 'Some data' } ) ;
46
46
47
47
expect ( sendEventMethod ) . toHaveBeenCalledWith (
48
- TelemetryEvents . CliClientCreated ,
48
+ `CLI_ ${ TelemetryEvents . ClientCreated } ` ,
49
49
{
50
50
databaseId : instanceId ,
51
51
data : 'Some data' ,
52
52
} ,
53
53
) ;
54
54
} ) ;
55
55
it ( 'should emit CliClientCreated event without additional data' , ( ) => {
56
- service . sendCliClientCreatedEvent ( instanceId ) ;
56
+ service . sendClientCreatedEvent ( instanceId , AppTool . CLI ) ;
57
57
58
58
expect ( sendEventMethod ) . toHaveBeenCalledWith (
59
- TelemetryEvents . CliClientCreated ,
59
+ `CLI_ ${ TelemetryEvents . ClientCreated } ` ,
60
60
{
61
61
databaseId : instanceId ,
62
62
} ,
@@ -66,10 +66,10 @@ describe('CliAnalyticsService', () => {
66
66
67
67
describe ( 'sendCliClientCreationFailedEvent' , ( ) => {
68
68
it ( 'should emit CliClientCreationFailed event' , ( ) => {
69
- service . sendCliClientCreationFailedEvent ( instanceId , httpException , { data : 'Some data' } ) ;
69
+ service . sendClientCreationFailedEvent ( instanceId , AppTool . CLI , httpException , { data : 'Some data' } ) ;
70
70
71
71
expect ( sendFailedEventMethod ) . toHaveBeenCalledWith (
72
- TelemetryEvents . CliClientCreationFailed ,
72
+ `CLI_ ${ TelemetryEvents . ClientCreationFailed } ` ,
73
73
httpException ,
74
74
{
75
75
databaseId : instanceId ,
@@ -78,10 +78,10 @@ describe('CliAnalyticsService', () => {
78
78
) ;
79
79
} ) ;
80
80
it ( 'should emit CliClientCreationFailed event without additional data' , ( ) => {
81
- service . sendCliClientCreationFailedEvent ( instanceId , httpException ) ;
81
+ service . sendClientCreationFailedEvent ( instanceId , AppTool . CLI , httpException ) ;
82
82
83
83
expect ( sendFailedEventMethod ) . toHaveBeenCalledWith (
84
- TelemetryEvents . CliClientCreationFailed ,
84
+ `CLI_ ${ TelemetryEvents . ClientCreationFailed } ` ,
85
85
httpException ,
86
86
{
87
87
databaseId : instanceId ,
@@ -92,21 +92,21 @@ describe('CliAnalyticsService', () => {
92
92
93
93
describe ( 'sendCliClientRecreatedEvent' , ( ) => {
94
94
it ( 'should emit CliClientRecreated event' , ( ) => {
95
- service . sendCliClientRecreatedEvent ( instanceId , { data : 'Some data' } ) ;
95
+ service . sendClientRecreatedEvent ( instanceId , AppTool . CLI , { data : 'Some data' } ) ;
96
96
97
97
expect ( sendEventMethod ) . toHaveBeenCalledWith (
98
- TelemetryEvents . CliClientRecreated ,
98
+ `CLI_ ${ TelemetryEvents . ClientRecreated } ` ,
99
99
{
100
100
databaseId : instanceId ,
101
101
data : 'Some data' ,
102
102
} ,
103
103
) ;
104
104
} ) ;
105
105
it ( 'should emit CliClientRecreated event without additional data' , ( ) => {
106
- service . sendCliClientRecreatedEvent ( instanceId ) ;
106
+ service . sendClientRecreatedEvent ( instanceId , AppTool . CLI ) ;
107
107
108
108
expect ( sendEventMethod ) . toHaveBeenCalledWith (
109
- TelemetryEvents . CliClientRecreated ,
109
+ `CLI_ ${ TelemetryEvents . ClientRecreated } ` ,
110
110
{
111
111
databaseId : instanceId ,
112
112
} ,
@@ -116,57 +116,89 @@ describe('CliAnalyticsService', () => {
116
116
117
117
describe ( 'sendCliClientDeletedEvent' , ( ) => {
118
118
it ( 'should emit CliClientDeleted event' , ( ) => {
119
- service . sendCliClientDeletedEvent ( 1 , instanceId , { data : 'Some data' } ) ;
119
+ service . sendClientDeletedEvent ( 1 , instanceId , AppTool . CLI , { data : 'Some data' } ) ;
120
120
121
121
expect ( sendEventMethod ) . toHaveBeenCalledWith (
122
- TelemetryEvents . CliClientDeleted ,
122
+ `CLI_ ${ TelemetryEvents . ClientDeleted } ` ,
123
123
{
124
124
databaseId : instanceId ,
125
125
data : 'Some data' ,
126
126
} ,
127
127
) ;
128
128
} ) ;
129
129
it ( 'should emit CliClientDeleted event without additional data' , ( ) => {
130
- service . sendCliClientDeletedEvent ( 1 , instanceId ) ;
130
+ service . sendClientDeletedEvent ( 1 , instanceId , AppTool . CLI ) ;
131
131
132
132
expect ( sendEventMethod ) . toHaveBeenCalledWith (
133
- TelemetryEvents . CliClientDeleted ,
133
+ `CLI_ ${ TelemetryEvents . ClientDeleted } ` ,
134
134
{
135
135
databaseId : instanceId ,
136
136
} ,
137
137
) ;
138
138
} ) ;
139
139
it ( 'should not emit event' , ( ) => {
140
- service . sendCliClientDeletedEvent ( 0 , instanceId ) ;
140
+ service . sendClientDeletedEvent ( 0 , instanceId , AppTool . CLI ) ;
141
141
142
142
expect ( sendEventMethod ) . not . toHaveBeenCalled ( ) ;
143
143
} ) ;
144
144
it ( 'should not emit event on invalid input values' , ( ) => {
145
145
const input : any = { } ;
146
- service . sendCliClientDeletedEvent ( input , instanceId ) ;
146
+ service . sendClientDeletedEvent ( input , instanceId , AppTool . CLI ) ;
147
147
148
- expect ( ( ) => service . sendCliClientDeletedEvent ( input , instanceId ) ) . not . toThrow ( ) ;
148
+ expect ( ( ) => service . sendClientDeletedEvent ( input , instanceId , AppTool . CLI ) ) . not . toThrow ( ) ;
149
149
expect ( sendEventMethod ) . not . toHaveBeenCalled ( ) ;
150
150
} ) ;
151
151
} ) ;
152
152
153
153
describe ( 'sendCliCommandExecutedEvent' , ( ) => {
154
154
it ( 'should emit CliCommandExecuted event' , ( ) => {
155
- service . sendCliCommandExecutedEvent ( instanceId , { command : 'info' } ) ;
155
+ service . sendCommandExecutedEvent ( instanceId , AppTool . CLI , { command : 'info' } ) ;
156
156
157
157
expect ( sendEventMethod ) . toHaveBeenCalledWith (
158
- TelemetryEvents . CliCommandExecuted ,
158
+ `CLI_ ${ TelemetryEvents . CommandExecuted } ` ,
159
159
{
160
160
databaseId : instanceId ,
161
161
command : 'info' ,
162
162
} ,
163
163
) ;
164
164
} ) ;
165
165
it ( 'should emit CliCommandExecuted event without additional data' , ( ) => {
166
- service . sendCliCommandExecutedEvent ( instanceId ) ;
166
+ service . sendCommandExecutedEvent ( instanceId , AppTool . CLI ) ;
167
167
168
168
expect ( sendEventMethod ) . toHaveBeenCalledWith (
169
- TelemetryEvents . CliCommandExecuted ,
169
+ `CLI_${ TelemetryEvents . CommandExecuted } ` ,
170
+ {
171
+ databaseId : instanceId ,
172
+ } ,
173
+ ) ;
174
+ } ) ;
175
+ it ( 'should emit CliCommandExecuted for undefined namespace' , ( ) => {
176
+ service . sendCommandExecutedEvent ( instanceId , undefined , { command : 'info' } ) ;
177
+
178
+ expect ( sendEventMethod ) . toHaveBeenCalledWith (
179
+ `CLI_${ TelemetryEvents . CommandExecuted } ` ,
180
+ {
181
+ databaseId : instanceId ,
182
+ command : 'info' ,
183
+ } ,
184
+ ) ;
185
+ } ) ;
186
+ it ( 'should emit WorkbenchCommandExecuted event' , ( ) => {
187
+ service . sendCommandExecutedEvent ( instanceId , 'workbench' , { command : 'info' } ) ;
188
+
189
+ expect ( sendEventMethod ) . toHaveBeenCalledWith (
190
+ `WORKBENCH_${ TelemetryEvents . CommandExecuted } ` ,
191
+ {
192
+ databaseId : instanceId ,
193
+ command : 'info' ,
194
+ } ,
195
+ ) ;
196
+ } ) ;
197
+ it ( 'should emit WorkbenchCommandExecuted event without additional data' , ( ) => {
198
+ service . sendCommandExecutedEvent ( instanceId , 'workbench' ) ;
199
+
200
+ expect ( sendEventMethod ) . toHaveBeenCalledWith (
201
+ `WORKBENCH_${ TelemetryEvents . CommandExecuted } ` ,
170
202
{
171
203
databaseId : instanceId ,
172
204
} ,
@@ -176,10 +208,10 @@ describe('CliAnalyticsService', () => {
176
208
177
209
describe ( 'sendCliCommandErrorEvent' , ( ) => {
178
210
it ( 'should emit CliCommandError event' , ( ) => {
179
- service . sendCliCommandErrorEvent ( instanceId , redisReplyError , { data : 'Some data' } ) ;
211
+ service . sendCommandErrorEvent ( instanceId , AppTool . CLI , redisReplyError , { data : 'Some data' } ) ;
180
212
181
213
expect ( sendEventMethod ) . toHaveBeenCalledWith (
182
- TelemetryEvents . CliCommandErrorReceived ,
214
+ `CLI_ ${ TelemetryEvents . CommandErrorReceived } ` ,
183
215
{
184
216
databaseId : instanceId ,
185
217
error : ReplyError . name ,
@@ -189,10 +221,10 @@ describe('CliAnalyticsService', () => {
189
221
) ;
190
222
} ) ;
191
223
it ( 'should emit CliCommandError event without additional data' , ( ) => {
192
- service . sendCliCommandErrorEvent ( instanceId , redisReplyError ) ;
224
+ service . sendCommandErrorEvent ( instanceId , AppTool . CLI , redisReplyError ) ;
193
225
194
226
expect ( sendEventMethod ) . toHaveBeenCalledWith (
195
- TelemetryEvents . CliCommandErrorReceived ,
227
+ `CLI_ ${ TelemetryEvents . CommandErrorReceived } ` ,
196
228
{
197
229
databaseId : instanceId ,
198
230
error : ReplyError . name ,
@@ -202,10 +234,10 @@ describe('CliAnalyticsService', () => {
202
234
} ) ;
203
235
it ( 'should emit event for custom error' , ( ) => {
204
236
const error : any = CliParsingError ;
205
- service . sendCliCommandErrorEvent ( instanceId , error ) ;
237
+ service . sendCommandErrorEvent ( instanceId , AppTool . CLI , error ) ;
206
238
207
239
expect ( sendEventMethod ) . toHaveBeenCalledWith (
208
- TelemetryEvents . CliCommandErrorReceived ,
240
+ `CLI_ ${ TelemetryEvents . CommandErrorReceived } ` ,
209
241
{
210
242
databaseId : instanceId ,
211
243
error : CliParsingError . name ,
@@ -216,10 +248,10 @@ describe('CliAnalyticsService', () => {
216
248
217
249
describe ( 'sendCliClientCreationFailedEvent' , ( ) => {
218
250
it ( 'should emit CliConnectionError event' , ( ) => {
219
- service . sendCliConnectionErrorEvent ( instanceId , httpException , { data : 'Some data' } ) ;
251
+ service . sendConnectionErrorEvent ( instanceId , AppTool . CLI , httpException , { data : 'Some data' } ) ;
220
252
221
253
expect ( sendFailedEventMethod ) . toHaveBeenCalledWith (
222
- TelemetryEvents . CliClientConnectionError ,
254
+ `CLI_ ${ TelemetryEvents . ClientConnectionError } ` ,
223
255
httpException ,
224
256
{
225
257
databaseId : instanceId ,
@@ -228,10 +260,10 @@ describe('CliAnalyticsService', () => {
228
260
) ;
229
261
} ) ;
230
262
it ( 'should emit CliConnectionError event without additional data' , ( ) => {
231
- service . sendCliConnectionErrorEvent ( instanceId , httpException ) ;
263
+ service . sendConnectionErrorEvent ( instanceId , AppTool . CLI , httpException ) ;
232
264
233
265
expect ( sendFailedEventMethod ) . toHaveBeenCalledWith (
234
- TelemetryEvents . CliClientConnectionError ,
266
+ `CLI_ ${ TelemetryEvents . ClientConnectionError } ` ,
235
267
httpException ,
236
268
{
237
269
databaseId : instanceId ,
@@ -249,10 +281,10 @@ describe('CliAnalyticsService', () => {
249
281
status : CommandExecutionStatus . Success ,
250
282
} ;
251
283
252
- service . sendCliClusterCommandExecutedEvent ( instanceId , nodExecResult , { command : 'sadd' } ) ;
284
+ service . sendClusterCommandExecutedEvent ( instanceId , AppTool . CLI , nodExecResult , { command : 'sadd' } ) ;
253
285
254
286
expect ( sendEventMethod ) . toHaveBeenCalledWith (
255
- TelemetryEvents . CliClusterNodeCommandExecuted ,
287
+ `CLI_ ${ TelemetryEvents . ClusterNodeCommandExecuted } ` ,
256
288
{
257
289
databaseId : instanceId ,
258
290
command : 'sadd' ,
@@ -268,10 +300,10 @@ describe('CliAnalyticsService', () => {
268
300
status : CommandExecutionStatus . Fail ,
269
301
} ;
270
302
271
- service . sendCliClusterCommandExecutedEvent ( instanceId , nodExecResult ) ;
303
+ service . sendClusterCommandExecutedEvent ( instanceId , AppTool . CLI , nodExecResult ) ;
272
304
273
305
expect ( sendEventMethod ) . toHaveBeenCalledWith (
274
- TelemetryEvents . CliCommandErrorReceived ,
306
+ `CLI_ ${ TelemetryEvents . CommandErrorReceived } ` ,
275
307
{
276
308
databaseId : instanceId ,
277
309
error : redisReplyError . name ,
@@ -288,10 +320,10 @@ describe('CliAnalyticsService', () => {
288
320
status : CommandExecutionStatus . Fail ,
289
321
} ;
290
322
291
- service . sendCliClusterCommandExecutedEvent ( instanceId , nodExecResult ) ;
323
+ service . sendClusterCommandExecutedEvent ( instanceId , AppTool . CLI , nodExecResult ) ;
292
324
293
325
expect ( sendEventMethod ) . toHaveBeenCalledWith (
294
- TelemetryEvents . CliCommandErrorReceived ,
326
+ `CLI_ ${ TelemetryEvents . CommandErrorReceived } ` ,
295
327
{
296
328
databaseId : instanceId ,
297
329
error : CliParsingError . name ,
@@ -305,7 +337,7 @@ describe('CliAnalyticsService', () => {
305
337
port : 7002 ,
306
338
status : 'undefined status' ,
307
339
} ;
308
- service . sendCliClusterCommandExecutedEvent ( instanceId , nodExecResult ) ;
340
+ service . sendClusterCommandExecutedEvent ( instanceId , AppTool . CLI , nodExecResult ) ;
309
341
310
342
expect ( sendEventMethod ) . not . toHaveBeenCalled ( ) ;
311
343
} ) ;
0 commit comments