|
1 |
| -import { describe, expect, it, xit } from '@jest/globals'; |
| 1 | +import { jest, describe, expect, it, xit, beforeEach } from '@jest/globals'; |
| 2 | + |
| 3 | +// @ts-ignore test |
| 4 | +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; |
2 | 5 |
|
3 | 6 | import {
|
4 | 7 | firebase,
|
@@ -58,6 +61,11 @@ import {
|
58 | 61 | settings,
|
59 | 62 | } from '../lib';
|
60 | 63 |
|
| 64 | +import { |
| 65 | + createCheckV9Deprecation, |
| 66 | + CheckV9DeprecationFunction, |
| 67 | +} from '../../app/lib/common/unitTestUtils'; |
| 68 | + |
61 | 69 | describe('Analytics', function () {
|
62 | 70 | describe('namespace', function () {
|
63 | 71 | it('accessible from firebase.app()', function () {
|
@@ -924,4 +932,131 @@ describe('Analytics', function () {
|
924 | 932 | expect(settings).toBeDefined();
|
925 | 933 | });
|
926 | 934 | });
|
| 935 | + |
| 936 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 937 | + let analyticsRefV9Deprecation: CheckV9DeprecationFunction; |
| 938 | + |
| 939 | + beforeEach(function () { |
| 940 | + analyticsRefV9Deprecation = createCheckV9Deprecation(['analytics']); |
| 941 | + |
| 942 | + // @ts-ignore test |
| 943 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 944 | + return new Proxy( |
| 945 | + {}, |
| 946 | + { |
| 947 | + get: () => |
| 948 | + jest.fn().mockResolvedValue({ |
| 949 | + source: 'cache', |
| 950 | + changes: [], |
| 951 | + documents: [], |
| 952 | + metadata: {}, |
| 953 | + path: 'foo', |
| 954 | + } as never), |
| 955 | + }, |
| 956 | + ); |
| 957 | + }); |
| 958 | + }); |
| 959 | + |
| 960 | + describe('Analytics', function () { |
| 961 | + it('analytics.logEvent()', function () { |
| 962 | + const analytics = getAnalytics(); |
| 963 | + analyticsRefV9Deprecation( |
| 964 | + () => logEvent(analytics, 'invertase_event'), |
| 965 | + () => analytics.logEvent('invertase_event'), |
| 966 | + 'logEvent', |
| 967 | + ); |
| 968 | + }); |
| 969 | + |
| 970 | + it('analytics.setAnalyticsCollectionEnabled()', function () { |
| 971 | + const analytics = getAnalytics(); |
| 972 | + analyticsRefV9Deprecation( |
| 973 | + () => setAnalyticsCollectionEnabled(analytics, true), |
| 974 | + () => analytics.setAnalyticsCollectionEnabled(true), |
| 975 | + 'setAnalyticsCollectionEnabled', |
| 976 | + ); |
| 977 | + }); |
| 978 | + |
| 979 | + it('analytics.setSessionTimeoutDuration()', function () { |
| 980 | + const analytics = getAnalytics(); |
| 981 | + analyticsRefV9Deprecation( |
| 982 | + () => setSessionTimeoutDuration(analytics, 180000), |
| 983 | + () => analytics.setSessionTimeoutDuration(180000), |
| 984 | + 'setSessionTimeoutDuration', |
| 985 | + ); |
| 986 | + }); |
| 987 | + |
| 988 | + it('analytics.getAppInstanceId()', function () { |
| 989 | + const analytics = getAnalytics(); |
| 990 | + analyticsRefV9Deprecation( |
| 991 | + () => getAppInstanceId(analytics), |
| 992 | + () => analytics.getAppInstanceId(), |
| 993 | + 'getAppInstanceId', |
| 994 | + ); |
| 995 | + }); |
| 996 | + |
| 997 | + it('analytics.getSessionId()', function () { |
| 998 | + const analytics = getAnalytics(); |
| 999 | + analyticsRefV9Deprecation( |
| 1000 | + () => getSessionId(analytics), |
| 1001 | + () => analytics.getSessionId(), |
| 1002 | + 'getSessionId', |
| 1003 | + ); |
| 1004 | + }); |
| 1005 | + |
| 1006 | + it('analytics.setUserId()', function () { |
| 1007 | + const analytics = getAnalytics(); |
| 1008 | + analyticsRefV9Deprecation( |
| 1009 | + () => setUserId(analytics, 'id'), |
| 1010 | + () => analytics.setUserId('id'), |
| 1011 | + 'setUserId', |
| 1012 | + ); |
| 1013 | + }); |
| 1014 | + |
| 1015 | + it('analytics.setUserProperty()', function () { |
| 1016 | + const analytics = getAnalytics(); |
| 1017 | + analyticsRefV9Deprecation( |
| 1018 | + () => setUserProperty(analytics, 'prop', 'value'), |
| 1019 | + () => analytics.setUserProperty('prop', 'value'), |
| 1020 | + 'setUserProperty', |
| 1021 | + ); |
| 1022 | + }); |
| 1023 | + |
| 1024 | + it('analytics.setUserProperties()', function () { |
| 1025 | + const analytics = getAnalytics(); |
| 1026 | + analyticsRefV9Deprecation( |
| 1027 | + () => setUserProperties(analytics, { prop: 'value' }), |
| 1028 | + () => analytics.setUserProperties({ prop: 'value' }), |
| 1029 | + 'setUserProperties', |
| 1030 | + ); |
| 1031 | + }); |
| 1032 | + |
| 1033 | + it('analytics.resetAnalyticsData()', function () { |
| 1034 | + const analytics = getAnalytics(); |
| 1035 | + analyticsRefV9Deprecation( |
| 1036 | + () => resetAnalyticsData(analytics), |
| 1037 | + () => analytics.resetAnalyticsData(), |
| 1038 | + 'resetAnalyticsData', |
| 1039 | + ); |
| 1040 | + }); |
| 1041 | + |
| 1042 | + it('analytics.setConsent()', function () { |
| 1043 | + const analytics = getAnalytics(); |
| 1044 | + analyticsRefV9Deprecation( |
| 1045 | + () => setConsent(analytics, { ad_storage: true }), |
| 1046 | + () => analytics.setConsent({ ad_storage: true }), |
| 1047 | + 'setConsent', |
| 1048 | + ); |
| 1049 | + }); |
| 1050 | + |
| 1051 | + it('analytics.logAddPaymentInfo()', function () { |
| 1052 | + const analytics = getAnalytics(); |
| 1053 | + analyticsRefV9Deprecation( |
| 1054 | + // no corresponding method |
| 1055 | + () => {}, |
| 1056 | + () => analytics.logAddPaymentInfo({ value: 1 }), |
| 1057 | + 'logAddPaymentInfo', |
| 1058 | + ); |
| 1059 | + }); |
| 1060 | + }); |
| 1061 | + }); |
927 | 1062 | });
|
0 commit comments