SELF-773: standardize analytics imports (#1538)

* standardize analytics

* format
This commit is contained in:
Justin Hernandez
2025-12-30 14:04:28 -08:00
committed by GitHub
parent 9860020cd1
commit 5cdf345372
12 changed files with 147 additions and 132 deletions

View File

@@ -19,6 +19,9 @@ jest.mock('@/services/analytics', () => ({
trackScreenView: jest.fn(),
flush: jest.fn(),
})),
trackEvent: jest.fn(),
trackScreenView: jest.fn(),
flush: jest.fn(),
}));
describe('navigation', () => {

View File

@@ -11,16 +11,20 @@ import {
checkAndUpdateRegistrationStates,
getAlternativeCSCA,
} from '@/proving/validateDocument';
import analytics from '@/services/analytics';
import { trackEvent } from '@/services/analytics';
// Mock the analytics module to avoid side effects in tests
jest.mock('@/services/analytics', () => {
// Create mock inside factory to avoid temporal dead zone
const mockTrackEvent = jest.fn();
return jest.fn(() => ({
trackEvent: mockTrackEvent,
}));
});
jest.mock('@/services/analytics', () => ({
__esModule: true,
default: jest.fn(() => ({
trackEvent: jest.fn(),
trackScreenView: jest.fn(),
flush: jest.fn(),
})),
trackEvent: jest.fn(),
trackScreenView: jest.fn(),
flush: jest.fn(),
}));
// Mock the passport data provider to avoid database operations
const mockGetAllDocumentsDirectlyFromKeychain = jest.fn();
@@ -153,8 +157,7 @@ describe('getAlternativeCSCA', () => {
beforeEach(() => {
jest.clearAllMocks();
// Get the mocked trackEvent from the analytics module
const mockAnalytics = jest.mocked(analytics);
mockTrackEvent = mockAnalytics().trackEvent as jest.Mock;
mockTrackEvent = jest.mocked(trackEvent) as jest.Mock;
});
it('should return public keys in Record format for Aadhaar with valid public keys', () => {
@@ -245,8 +248,7 @@ describe('checkAndUpdateRegistrationStates', () => {
beforeEach(() => {
jest.clearAllMocks();
// Get the mocked trackEvent from the analytics module
const mockAnalytics = jest.mocked(analytics);
mockTrackEvent = mockAnalytics().trackEvent as jest.Mock;
mockTrackEvent = jest.mocked(trackEvent) as jest.Mock;
mockGetState.mockReturnValue(
buildState({

View File

@@ -2,7 +2,7 @@
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
import analytics from '@/services/analytics';
import { trackEvent, trackScreenView } from '@/services/analytics';
// Mock the Segment client
jest.mock('@/config/segment', () => ({
@@ -13,8 +13,6 @@ jest.mock('@/config/segment', () => ({
}));
describe('analytics', () => {
const { trackEvent, trackScreenView } = analytics();
beforeEach(() => {
jest.clearAllMocks();
});