|
1 | 1 | import { PLATFORM_ID, PendingTasks } from '@angular/core'; |
2 | 2 | import { TestBed } from '@angular/core/testing'; |
3 | 3 | import { FirebaseApp, deleteApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app'; |
4 | | -import { APP_CHECK_ON_SERVER, AppCheck, CustomProvider, initializeAppCheck, onTokenChanged, provideAppCheck } from '@angular/fire/app-check'; |
| 4 | +import { APP_CHECK_ON_SERVER, AppCheck, CustomProvider, initializeAppCheck, onTokenChanged, provideAppCheck, ɵresetAppCheckServerWarning } from '@angular/fire/app-check'; |
5 | 5 | import { Auth, connectAuthEmulator, getAuth, provideAuth } from '@angular/fire/auth'; |
6 | 6 | import { COMMON_CONFIG } from '../test-config'; |
7 | 7 | import { rando } from '../utils'; |
@@ -54,6 +54,39 @@ describe('AppCheck', () => { |
54 | 54 | beforeEach(() => { |
55 | 55 | appName = rando(); |
56 | 56 | setupCalls = 0; |
| 57 | + ɵresetAppCheckServerWarning(); |
| 58 | + }); |
| 59 | + |
| 60 | + const configureServerPlatform = () => { |
| 61 | + TestBed.configureTestingModule({ |
| 62 | + providers: [ |
| 63 | + { provide: PLATFORM_ID, useValue: 'server' }, |
| 64 | + provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), |
| 65 | + provideTestAppCheck(), |
| 66 | + ], |
| 67 | + }); |
| 68 | + }; |
| 69 | + |
| 70 | + it('warns once during server rendering, saying what a relayed token changes', () => { |
| 71 | + const warn = spyOn(console, 'warn'); |
| 72 | + configureServerPlatform(); |
| 73 | + TestBed.inject(AppCheck); |
| 74 | + expect(warn).toHaveBeenCalledTimes(1); |
| 75 | + const message = warn.calls.argsFor(0).join(' '); |
| 76 | + expect(message).toContain('server renders without a relayed App Check token send none'); |
| 77 | + expect(message).toContain('APP_CHECK_ON_SERVER'); |
| 78 | + expect(message).toContain('initializeBrowserOrServerApp'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('warns once per process, not once per render', () => { |
| 82 | + const warn = spyOn(console, 'warn'); |
| 83 | + configureServerPlatform(); |
| 84 | + TestBed.inject(AppCheck); |
| 85 | + TestBed.resetTestingModule(); |
| 86 | + appName = rando(); |
| 87 | + configureServerPlatform(); |
| 88 | + TestBed.inject(AppCheck); |
| 89 | + expect(warn).toHaveBeenCalledTimes(1); |
57 | 90 | }); |
58 | 91 |
|
59 | 92 | it('should skip App Check during server rendering by default', () => { |
|
0 commit comments