|
1 |
| -import { describe, expect, it } from '@jest/globals'; |
| 1 | +import { jest, beforeEach, describe, expect, it } from '@jest/globals'; |
| 2 | +// @ts-ignore test |
| 3 | +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; |
| 4 | + |
| 5 | +import { |
| 6 | + createCheckV9Deprecation, |
| 7 | + CheckV9DeprecationFunction, |
| 8 | +} from '../../app/lib/common/unitTestUtils'; |
2 | 9 |
|
3 | 10 | import {
|
4 | 11 | firebase,
|
5 | 12 | initializeAppCheck,
|
6 | 13 | getToken,
|
7 | 14 | getLimitedUseToken,
|
8 |
| - addTokenListener, |
9 | 15 | setTokenAutoRefreshEnabled,
|
| 16 | + onTokenChanged, |
| 17 | + CustomProvider, |
10 | 18 | } from '../lib';
|
11 | 19 |
|
12 | 20 | describe('appCheck()', function () {
|
@@ -47,12 +55,117 @@ describe('appCheck()', function () {
|
47 | 55 | expect(getLimitedUseToken).toBeDefined();
|
48 | 56 | });
|
49 | 57 |
|
50 |
| - it('`addTokenListener` function is properly exposed to end user', function () { |
51 |
| - expect(addTokenListener).toBeDefined(); |
52 |
| - }); |
53 |
| - |
54 | 58 | it('`setTokenAutoRefreshEnabled` function is properly exposed to end user', function () {
|
55 | 59 | expect(setTokenAutoRefreshEnabled).toBeDefined();
|
56 | 60 | });
|
| 61 | + |
| 62 | + it('`CustomProvider` function is properly exposed to end user', function () { |
| 63 | + expect(CustomProvider).toBeDefined(); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 68 | + let appCheckRefV9Deprecation: CheckV9DeprecationFunction; |
| 69 | + let staticsRefV9Deprecation: CheckV9DeprecationFunction; |
| 70 | + |
| 71 | + beforeEach(function () { |
| 72 | + appCheckRefV9Deprecation = createCheckV9Deprecation(['appCheck']); |
| 73 | + staticsRefV9Deprecation = createCheckV9Deprecation(['appCheck', 'statics']); |
| 74 | + |
| 75 | + // @ts-ignore test |
| 76 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 77 | + return new Proxy( |
| 78 | + {}, |
| 79 | + { |
| 80 | + get: () => |
| 81 | + jest.fn().mockResolvedValue({ |
| 82 | + source: 'cache', |
| 83 | + changes: [], |
| 84 | + documents: [], |
| 85 | + metadata: {}, |
| 86 | + path: 'foo', |
| 87 | + } as never), |
| 88 | + }, |
| 89 | + ); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + describe('AppCheck', function () { |
| 94 | + it('appCheck.activate()', function () { |
| 95 | + const app = firebase.app(); |
| 96 | + const appCheck = firebase.appCheck(); |
| 97 | + appCheckRefV9Deprecation( |
| 98 | + () => |
| 99 | + initializeAppCheck(app, { |
| 100 | + provider: { |
| 101 | + providerOptions: { |
| 102 | + android: { |
| 103 | + provider: 'playIntegrity', |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + isTokenAutoRefreshEnabled: true, |
| 108 | + }), |
| 109 | + () => appCheck.activate('string'), |
| 110 | + 'activate', |
| 111 | + ); |
| 112 | + }); |
| 113 | + |
| 114 | + it('appCheck.setTokenAutoRefreshEnabled()', function () { |
| 115 | + const appCheck = firebase.appCheck(); |
| 116 | + appCheckRefV9Deprecation( |
| 117 | + () => setTokenAutoRefreshEnabled(appCheck, true), |
| 118 | + () => appCheck.setTokenAutoRefreshEnabled(true), |
| 119 | + 'setTokenAutoRefreshEnabled', |
| 120 | + ); |
| 121 | + }); |
| 122 | + |
| 123 | + it('appCheck.getToken()', function () { |
| 124 | + const appCheck = firebase.appCheck(); |
| 125 | + appCheckRefV9Deprecation( |
| 126 | + () => getToken(appCheck, true), |
| 127 | + () => appCheck.getToken(true), |
| 128 | + 'getToken', |
| 129 | + ); |
| 130 | + }); |
| 131 | + |
| 132 | + it('appCheck.getLimitedUseToken()', function () { |
| 133 | + const appCheck = firebase.appCheck(); |
| 134 | + appCheckRefV9Deprecation( |
| 135 | + () => getLimitedUseToken(appCheck), |
| 136 | + () => appCheck.getLimitedUseToken(), |
| 137 | + 'getLimitedUseToken', |
| 138 | + ); |
| 139 | + }); |
| 140 | + |
| 141 | + it('appCheck.onTokenChanged()', function () { |
| 142 | + const appCheck = firebase.appCheck(); |
| 143 | + appCheckRefV9Deprecation( |
| 144 | + () => |
| 145 | + onTokenChanged( |
| 146 | + appCheck, |
| 147 | + () => {}, |
| 148 | + () => {}, |
| 149 | + () => {}, |
| 150 | + ), |
| 151 | + () => |
| 152 | + appCheck.onTokenChanged( |
| 153 | + () => {}, |
| 154 | + () => {}, |
| 155 | + () => {}, |
| 156 | + ), |
| 157 | + 'onTokenChanged', |
| 158 | + ); |
| 159 | + }); |
| 160 | + |
| 161 | + it('CustomProvider', function () { |
| 162 | + const appCheck = firebase.appCheck; |
| 163 | + staticsRefV9Deprecation( |
| 164 | + () => CustomProvider, |
| 165 | + () => appCheck.CustomProvider, |
| 166 | + 'CustomProvider', |
| 167 | + ); |
| 168 | + }); |
| 169 | + }); |
57 | 170 | });
|
58 | 171 | });
|
0 commit comments