Skip to content

Commit 4390b0e

Browse files
committed
chore: adds tests
1 parent 5d1e2a7 commit 4390b0e

2 files changed

Lines changed: 403 additions & 0 deletions

File tree

packages/snap/src/core/services/analytics/AnalyticsService.test.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Network } from '../../constants/solana';
66
import { MOCK_SOLANA_KEYRING_ACCOUNT_0 } from '../../test/mocks/solana-keyring-accounts';
77
import logger from '../../utils/logger';
88
import { AnalyticsService } from './AnalyticsService';
9+
import { ScanStatus, SecurityAlertResponse } from '../transaction-scan/types';
910

1011
const mockSnapRequest = jest.fn();
1112
const snap = {
@@ -293,6 +294,120 @@ describe('AnalyticsService', () => {
293294
});
294295
});
295296

297+
describe('trackEventSecurityAlertDetected', () => {
298+
it('tracks security alert detected event', async () => {
299+
const securityAlertResponse = SecurityAlertResponse.Warning;
300+
const securityAlertReason = 'transfer_farming';
301+
const securityAlertDescription = 'Substantial transfer of the account\'s assets to untrusted entities';
302+
303+
await analyticsService.trackEventSecurityAlertDetected(
304+
mockAccount,
305+
mockBase64Transaction,
306+
mockOrigin,
307+
mockScope,
308+
securityAlertResponse,
309+
securityAlertReason,
310+
securityAlertDescription,
311+
);
312+
313+
expect(loggerSpy).toHaveBeenCalledWith(
314+
'[📣 AnalyticsService] Tracking event security alert detected',
315+
);
316+
317+
expect(mockSnapRequest).toHaveBeenCalledWith({
318+
method: 'snap_trackEvent',
319+
params: {
320+
event: {
321+
event: 'Security Alert Detected',
322+
properties: {
323+
message: 'Snap security alert detected',
324+
origin: mockOrigin,
325+
account_id: mockAccount.id,
326+
account_address: mockAccount.address,
327+
account_type: mockAccount.type,
328+
chain_id: mockScope,
329+
security_alert_response: securityAlertResponse,
330+
security_alert_reason: securityAlertReason,
331+
security_alert_description: securityAlertDescription,
332+
},
333+
},
334+
},
335+
});
336+
});
337+
});
338+
339+
describe('trackEventSecurityScanCompleted', () => {
340+
it('tracks security scan completed event with alerts detected', async () => {
341+
const scanStatus = ScanStatus.SUCCESS;
342+
const hasSecurityAlerts = true;
343+
344+
await analyticsService.trackEventSecurityScanCompleted(
345+
mockAccount,
346+
mockBase64Transaction,
347+
mockOrigin,
348+
mockScope,
349+
scanStatus,
350+
hasSecurityAlerts,
351+
);
352+
353+
expect(loggerSpy).toHaveBeenCalledWith(
354+
'[📣 AnalyticsService] Tracking event security scan completed',
355+
);
356+
357+
expect(mockSnapRequest).toHaveBeenCalledWith({
358+
method: 'snap_trackEvent',
359+
params: {
360+
event: {
361+
event: 'Security Scan Completed',
362+
properties: {
363+
message: 'Snap security scan completed',
364+
origin: mockOrigin,
365+
account_id: mockAccount.id,
366+
account_address: mockAccount.address,
367+
account_type: mockAccount.type,
368+
chain_id: mockScope,
369+
scan_status: scanStatus,
370+
has_security_alerts: hasSecurityAlerts,
371+
},
372+
},
373+
},
374+
});
375+
});
376+
377+
it('tracks security scan completed event without alerts', async () => {
378+
const scanStatus = ScanStatus.SUCCESS;
379+
const hasSecurityAlerts = false;
380+
381+
await analyticsService.trackEventSecurityScanCompleted(
382+
mockAccount,
383+
mockBase64Transaction,
384+
mockOrigin,
385+
mockScope,
386+
scanStatus,
387+
hasSecurityAlerts,
388+
);
389+
390+
expect(mockSnapRequest).toHaveBeenCalledWith({
391+
method: 'snap_trackEvent',
392+
params: {
393+
event: {
394+
event: 'Security Scan Completed',
395+
properties: {
396+
message: 'Snap security scan completed',
397+
origin: mockOrigin,
398+
account_id: mockAccount.id,
399+
account_address: mockAccount.address,
400+
account_type: mockAccount.type,
401+
chain_id: mockScope,
402+
scan_status: scanStatus,
403+
has_security_alerts: hasSecurityAlerts,
404+
},
405+
},
406+
},
407+
});
408+
});
409+
});
410+
296411
describe('error handling', () => {
297412
it('handles snap.request errors gracefully', async () => {
298413
const error = new Error('Snap request failed');

0 commit comments

Comments
 (0)