Skip to content

Commit ccceef8

Browse files
committed
Test fixes
1 parent 7598b12 commit ccceef8

File tree

8 files changed

+161
-168
lines changed

8 files changed

+161
-168
lines changed

packages/app-check/src/client.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ describe('client', () => {
5252
});
5353

5454
it('returns a AppCheck token', async () => {
55-
useFakeTimers();
55+
// To get a consistent expireTime/issuedAtTime.
56+
const clock = useFakeTimers();
5657
fetchStub.returns(
5758
Promise.resolve({
5859
status: 200,
@@ -77,6 +78,7 @@ describe('client', () => {
7778
expireTimeMillis: 3600,
7879
issuedAtTimeMillis: 0
7980
});
81+
clock.restore();
8082
});
8183

8284
it('throws when there is a network error', async () => {

packages/app-check/src/factory.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ import {
3636
import { Provider } from '@firebase/component';
3737
import { PartialObserver } from '@firebase/util';
3838

39-
export function factory(
40-
app: FirebaseApp,
41-
platformLoggerProvider: Provider<'platform-logger'>
42-
): FirebaseAppCheck {
39+
import { FirebaseService } from '@firebase/app-types/private';
40+
import { getState } from './state';
41+
42+
export function factory(app: FirebaseApp,
43+
platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheck & FirebaseService {
4344
return {
45+
app,
4446
activate: (
4547
siteKeyOrProvider: string | AppCheckProvider,
4648
isTokenAutoRefreshEnabled?: boolean
4749
) => activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled),
4850
setTokenAutoRefreshEnabled: (isTokenAutoRefreshEnabled: boolean) =>
4951
setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled),
50-
5152
getToken: forceRefresh =>
5253
getToken(app, platformLoggerProvider, forceRefresh),
5354
onTokenChanged: (
@@ -68,7 +69,16 @@ export function factory(
6869
onNextOrObserver as (tokenResult: AppCheckTokenResult) => void,
6970
onError,
7071
onCompletion
71-
)
72+
),
73+
INTERNAL: {
74+
delete: () => {
75+
const { tokenObservers } = getState(app);
76+
for (const tokenObserver of tokenObservers) {
77+
removeTokenListener(app, tokenObserver.next);
78+
}
79+
return Promise.resolve();
80+
}
81+
}
7282
};
7383
}
7484

packages/app-check/src/indexeddb.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,16 @@ function getDBPromise(): Promise<IDBDatabase> {
7373
}
7474

7575
export function readTokenFromIndexedDB(
76-
app: FirebaseApp,
77-
keySuffix?: string
76+
app: FirebaseApp
7877
): Promise<AppCheckTokenInternal | undefined> {
79-
return read(computeKey(app, keySuffix)) as Promise<
80-
AppCheckTokenInternal | undefined
81-
>;
78+
return read(computeKey(app)) as Promise<AppCheckTokenInternal | undefined>;
8279
}
8380

8481
export function writeTokenToIndexedDB(
8582
app: FirebaseApp,
86-
token: AppCheckTokenInternal,
87-
keySuffix?: string
83+
token: AppCheckTokenInternal
8884
): Promise<void> {
89-
return write(computeKey(app, keySuffix), token);
85+
return write(computeKey(app), token);
9086
}
9187

9288
export function writeDebugTokenToIndexedDB(token: string): Promise<void> {
@@ -150,10 +146,6 @@ async function read(key: string): Promise<unknown> {
150146
});
151147
}
152148

153-
function computeKey(app: FirebaseApp, keySuffix?: string): string {
154-
let key = `${app.options.appId}-${app.name}`;
155-
if (keySuffix != null) {
156-
key += `-${keySuffix}`;
157-
}
158-
return key;
149+
function computeKey(app: FirebaseApp): string {
150+
return `${app.options.appId}-${app.name}`;
159151
}

0 commit comments

Comments
 (0)