Skip to content

Commit

Permalink
test(analytics): ensure modular API are exported properly (#7930)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 29, 2024
1 parent f679c8a commit 686896f
Show file tree
Hide file tree
Showing 4 changed files with 548 additions and 429 deletions.
266 changes: 265 additions & 1 deletion packages/analytics/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import { describe, expect, it, xit } from '@jest/globals';

import { firebase } from '../lib';
import {
firebase,
getAnalytics,
initializeAnalytics,
logEvent,
setAnalyticsCollectionEnabled,
setSessionTimeoutDuration,
getAppInstanceId,
getSessionId,
setUserId,
setUserProperty,
setUserProperties,
resetAnalyticsData,
logAddPaymentInfo,
logScreenView,
logAddShippingInfo,
logAddToCart,
logAddToWishlist,
logAppOpen,
logBeginCheckout,
logCampaignDetails,
logEarnVirtualCurrency,
logGenerateLead,
logJoinGroup,
logLevelEnd,
logLevelStart,
logLevelUp,
logLogin,
logPostScore,
logSelectContent,
logPurchase,
logRefund,
logRemoveFromCart,
logSearch,
logSelectItem,
logSetCheckoutOption,
logSelectPromotion,
logShare,
logSignUp,
logSpendVirtualCurrency,
logTutorialBegin,
logTutorialComplete,
logUnlockAchievement,
logViewCart,
logViewItem,
logViewItemList,
logViewPromotion,
logViewSearchResults,
setDefaultEventParameters,
initiateOnDeviceConversionMeasurementWithEmailAddress,
initiateOnDeviceConversionMeasurementWithPhoneNumber,
isSupported,
setConsent,
settings,
} from '../lib';

describe('Analytics', function () {
describe('namespace', function () {
Expand Down Expand Up @@ -595,4 +649,214 @@ describe('Analytics', function () {
);
});
});

describe('modular', function () {
it('`getAnalytics` function is properly exposed to end user', function () {
expect(getAnalytics).toBeDefined();
});

it('`initializeAnalytics` function is properly exposed to end user', function () {
expect(initializeAnalytics).toBeDefined();
});

it('`logEvent` function is properly exposed to end user', function () {
expect(logEvent).toBeDefined();
});

it('`setAnalyticsCollectionEnabled` function is properly exposed to end user', function () {
expect(setAnalyticsCollectionEnabled).toBeDefined();
});

it('`setSessionTimeoutDuration` function is properly exposed to end user', function () {
expect(setSessionTimeoutDuration).toBeDefined();
});

it('`getAppInstanceId` function is properly exposed to end user', function () {
expect(getAppInstanceId).toBeDefined();
});

it('`getSessionId` function is properly exposed to end user', function () {
expect(getSessionId).toBeDefined();
});

it('`setUserId` function is properly exposed to end user', function () {
expect(setUserId).toBeDefined();
});

it('`setUserProperty` function is properly exposed to end user', function () {
expect(setUserProperty).toBeDefined();
});

it('`setUserProperties` function is properly exposed to end user', function () {
expect(setUserProperties).toBeDefined();
});

it('`resetAnalyticsData` function is properly exposed to end user', function () {
expect(resetAnalyticsData).toBeDefined();
});

it('`logAddPaymentInfo` function is properly exposed to end user', function () {
expect(logAddPaymentInfo).toBeDefined();
});

it('`logScreenView` function is properly exposed to end user', function () {
expect(logScreenView).toBeDefined();
});

it('`logAddShippingInfo` function is properly exposed to end user', function () {
expect(logAddShippingInfo).toBeDefined();
});

it('`logAddToCart` function is properly exposed to end user', function () {
expect(logAddToCart).toBeDefined();
});

it('`logAddToWishlist` function is properly exposed to end user', function () {
expect(logAddToWishlist).toBeDefined();
});

it('`logAppOpen` function is properly exposed to end user', function () {
expect(logAppOpen).toBeDefined();
});

it('`logBeginCheckout` function is properly exposed to end user', function () {
expect(logBeginCheckout).toBeDefined();
});

it('`logCampaignDetails` function is properly exposed to end user', function () {
expect(logCampaignDetails).toBeDefined();
});

it('`logEarnVirtualCurrency` function is properly exposed to end user', function () {
expect(logEarnVirtualCurrency).toBeDefined();
});

it('`logGenerateLead` function is properly exposed to end user', function () {
expect(logGenerateLead).toBeDefined();
});

it('`logJoinGroup` function is properly exposed to end user', function () {
expect(logJoinGroup).toBeDefined();
});

it('`logLevelEnd` function is properly exposed to end user', function () {
expect(logLevelEnd).toBeDefined();
});

it('`logLevelStart` function is properly exposed to end user', function () {
expect(logLevelStart).toBeDefined();
});

it('`logLevelUp` function is properly exposed to end user', function () {
expect(logLevelUp).toBeDefined();
});

it('`logLogin` function is properly exposed to end user', function () {
expect(logLogin).toBeDefined();
});

it('`logPostScore` function is properly exposed to end user', function () {
expect(logPostScore).toBeDefined();
});

it('`logSelectContent` function is properly exposed to end user', function () {
expect(logSelectContent).toBeDefined();
});

it('`logPurchase` function is properly exposed to end user', function () {
expect(logPurchase).toBeDefined();
});

it('`logRefund` function is properly exposed to end user', function () {
expect(logRefund).toBeDefined();
});

it('`logRemoveFromCart` function is properly exposed to end user', function () {
expect(logRemoveFromCart).toBeDefined();
});

it('`logSearch` function is properly exposed to end user', function () {
expect(logSearch).toBeDefined();
});

it('`logSelectItem` function is properly exposed to end user', function () {
expect(logSelectItem).toBeDefined();
});

it('`logSetCheckoutOption` function is properly exposed to end user', function () {
expect(logSetCheckoutOption).toBeDefined();
});

it('`logSelectPromotion` function is properly exposed to end user', function () {
expect(logSelectPromotion).toBeDefined();
});

it('`logShare` function is properly exposed to end user', function () {
expect(logShare).toBeDefined();
});

it('`logSignUp` function is properly exposed to end user', function () {
expect(logSignUp).toBeDefined();
});

it('`logSpendVirtualCurrency` function is properly exposed to end user', function () {
expect(logSpendVirtualCurrency).toBeDefined();
});

it('`logTutorialBegin` function is properly exposed to end user', function () {
expect(logTutorialBegin).toBeDefined();
});

it('`logTutorialComplete` function is properly exposed to end user', function () {
expect(logTutorialComplete).toBeDefined();
});

it('`logUnlockAchievement` function is properly exposed to end user', function () {
expect(logUnlockAchievement).toBeDefined();
});

it('`logViewCart` function is properly exposed to end user', function () {
expect(logViewCart).toBeDefined();
});

it('`logViewItem` function is properly exposed to end user', function () {
expect(logViewItem).toBeDefined();
});

it('`logViewItemList` function is properly exposed to end user', function () {
expect(logViewItemList).toBeDefined();
});

it('`logViewPromotion` function is properly exposed to end user', function () {
expect(logViewPromotion).toBeDefined();
});

it('`logViewSearchResults` function is properly exposed to end user', function () {
expect(logViewSearchResults).toBeDefined();
});

it('`setDefaultEventParameters` function is properly exposed to end user', function () {
expect(setDefaultEventParameters).toBeDefined();
});

it('`initiateOnDeviceConversionMeasurementWithEmailAddress` function is properly exposed to end user', function () {
expect(initiateOnDeviceConversionMeasurementWithEmailAddress).toBeDefined();
});

it('`initiateOnDeviceConversionMeasurementWithPhoneNumber` function is properly exposed to end user', function () {
expect(initiateOnDeviceConversionMeasurementWithPhoneNumber).toBeDefined();
});

it('`isSupported` function is properly exposed to end user', function () {
expect(isSupported).toBeDefined();
});

it('`setConsent` function is properly exposed to end user', function () {
expect(setConsent).toBeDefined();
});

it('`settings` function is properly exposed to end user', function () {
expect(settings).toBeDefined();
});
});
});
54 changes: 2 additions & 52 deletions packages/analytics/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,6 @@ import fallBackModule from './web/RNFBAnalyticsModule';
import version from './version';
import * as structs from './structs';

export {
getAnalytics,
logEvent,
setAnalyticsCollectionEnabled,
setSessionTimeoutDuration,
getAppInstanceId,
getSessionId,
setUserId,
setUserProperty,
setUserProperties,
resetAnalyticsData,
logAddPaymentInfo,
logScreenView,
logAddShippingInfo,
logAddToCart,
logAddToWishlist,
logAppOpen,
logBeginCheckout,
logCampaignDetails,
logEarnVirtualCurrency,
logGenerateLead,
logJoinGroup,
logLevelEnd,
logLevelStart,
logLevelUp,
logLogin,
logPostScore,
logSelectContent,
logPurchase,
logRefund,
logRemoveFromCart,
logSearch,
logSelectItem,
logSetCheckoutOption,
logSelectPromotion,
logShare,
logSignUp,
logSpendVirtualCurrency,
logTutorialBegin,
logTutorialComplete,
logUnlockAchievement,
logViewCart,
logViewItem,
logViewItemList,
logViewPromotion,
logViewSearchResults,
setDefaultEventParameters,
initiateOnDeviceConversionMeasurementWithEmailAddress,
initiateOnDeviceConversionMeasurementWithPhoneNumber,
setConsent,
} from './modular/index';

const ReservedEventNames = [
'ad_activeview',
'ad_click',
Expand Down Expand Up @@ -826,6 +774,8 @@ export default createModuleNamespace({
ModuleClass: FirebaseAnalyticsModule,
});

export * from './modular/index';

// import analytics, { firebase } from '@react-native-firebase/analytics';
// analytics().logEvent(...);
// firebase.analytics().logEvent(...);
Expand Down
10 changes: 10 additions & 0 deletions packages/analytics/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,3 +1210,13 @@ export function setConsent(
* @returns {void}
*/
export function settings(options: FirebaseAnalyticsTypes.SettingsOptions): void;

/**
* Retrieves the session id from the client.
* On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details.
*
* Returns the session id or null if session is expired, null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied.
* @param {Analytics} instance.
* @returns {Promise<number | null>}
*/
export function getSessionId(analytics: Analytics): Promise<number | null>;
Loading

0 comments on commit 686896f

Please sign in to comment.