Skip to content

Commit fa9f8e0

Browse files
committed
PR feedback
1 parent a005390 commit fa9f8e0

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

packages-exp/auth-exp/index.cordova.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
/**
19-
* This is the file that people using React Native will actually import. You
19+
* This is the file that people using Cordova will actually import. You
2020
* should only include this file if you have something specific about your
2121
* implementation that mandates having a separate entrypoint. Otherwise you can
2222
* just use index.ts

packages-exp/auth-exp/src/platform_cordova/popup_redirect.test.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ describe('platform_cordova/popup_redirect', () => {
3434

3535
beforeEach(async () => {
3636
auth = await testAuth();
37+
attachExpectedPlugins();
3738
resolver = new (cordovaPopupRedirectResolver as SingletonInstantiator<PopupRedirectResolver>)();
3839
});
3940

4041
describe('_openRedirect plugin checks', () => {
4142
// TODO: Rest of the tests go here
4243
it('does not reject if all plugins installed', () => {
43-
setExpectedPluginsButMissing([]);
4444
expect(() =>
4545
resolver._openRedirect(
4646
auth,
@@ -51,55 +51,58 @@ describe('platform_cordova/popup_redirect', () => {
5151
});
5252

5353
it('rejects if universal links is missing', () => {
54-
setExpectedPluginsButMissing(['universalLinks.subscribe']);
54+
removeProp(window, 'universalLinks');
5555
expect(() =>
5656
resolver._openRedirect(
5757
auth,
5858
new GoogleAuthProvider(),
5959
AuthEventType.SIGN_IN_VIA_REDIRECT
6060
)
61-
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration');
61+
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration')
62+
.that.has.deep.property('customData', {appName: 'test-app', missingPlugin: 'cordova-universal-links-plugin-fix'});
6263
});
6364

6465
it('rejects if build info is missing', () => {
65-
setExpectedPluginsButMissing(['BuildInfo.packageName']);
66+
removeProp(window.BuildInfo, 'packageName');
6667
expect(() =>
6768
resolver._openRedirect(
6869
auth,
6970
new GoogleAuthProvider(),
7071
AuthEventType.SIGN_IN_VIA_REDIRECT
7172
)
72-
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration');
73+
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration')
74+
.that.has.deep.property('customData', {appName: 'test-app', missingPlugin: 'cordova-plugin-buildInfo'});
7375
});
7476

75-
it('rejects if browsertab openUrl', () => {
76-
setExpectedPluginsButMissing(['cordova.plugins.browsertab.openUrl']);
77+
it('rejects if browsertab openUrl is missing', () => {
78+
removeProp(window.cordova.plugins.browsertab, 'openUrl');
7779
expect(() =>
7880
resolver._openRedirect(
7981
auth,
8082
new GoogleAuthProvider(),
8183
AuthEventType.SIGN_IN_VIA_REDIRECT
8284
)
83-
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration');
85+
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration')
86+
.that.has.deep.property('customData', {appName: 'test-app', missingPlugin: 'cordova-plugin-browsertab'});
8487
});
8588

8689
it('rejects if InAppBrowser is missing', () => {
87-
setExpectedPluginsButMissing(['cordova.InAppBrowser.open']);
90+
removeProp(window.cordova.InAppBrowser, 'open');
8891
expect(() =>
8992
resolver._openRedirect(
9093
auth,
9194
new GoogleAuthProvider(),
9295
AuthEventType.SIGN_IN_VIA_REDIRECT
9396
)
94-
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration');
97+
).to.throw(FirebaseError, 'auth/invalid-cordova-configuration')
98+
.that.has.deep.property('customData', {appName: 'test-app', missingPlugin: 'cordova-plugin-inappbrowser'});
9599
});
96100
});
97101
});
98102

99-
function setExpectedPluginsButMissing(missingPlugins: string[]): void {
100-
// eslint-disable @typescript-eslint/no-any We don't want a strictly typed window
101-
const win: any = window;
102-
// Eventually these will be replaced with mocks
103+
function attachExpectedPlugins(): void {
104+
// Eventually these will be replaced with full mocks
105+
const win = window as unknown as Record<string, unknown>;
103106
win.cordova = {
104107
plugins: {
105108
browsertab: {
@@ -115,17 +118,10 @@ function setExpectedPluginsButMissing(missingPlugins: string[]): void {
115118
subscribe: () => {}
116119
};
117120
win.BuildInfo = {
118-
packageName: 'com.name.package'
121+
packageName: 'com.example.name.package'
119122
};
120-
121-
for (const missing of missingPlugins) {
122-
const parts = missing.split('.');
123-
const last = parts.pop()!;
124-
// eslint-disable @typescript-eslint/no-any We're just traversing an object map
125-
let obj: any = win;
126-
for (const p of parts) {
127-
obj = obj[p];
128-
}
129-
delete obj[last];
130-
}
131123
}
124+
125+
function removeProp(obj: unknown, prop: string):void {
126+
delete (obj as Record<string, unknown>)[prop];
127+
}

packages-exp/auth-exp/src/platform_cordova/popup_redirect.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ import {
2525
PopupRedirectResolver
2626
} from '../model/popup_redirect';
2727
import { AuthPopup } from '../platform_browser/util/popup';
28-
import { _fail } from '../core/util/assert';
28+
import { _assert, _fail } from '../core/util/assert';
2929
import { AuthErrorCode } from '../core/errors';
3030

3131
class CordovaPopupRedirectResolver implements PopupRedirectResolver {
32+
readonly _redirectPersistence = browserSessionPersistence;
33+
_completeRedirectFn: () => Promise<null> = async () => null;
34+
3235
_initialize(_auth: Auth): Promise<EventManager> {
3336
throw new Error('Method not implemented.');
3437
}
@@ -50,8 +53,6 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver {
5053
): void {
5154
throw new Error('Method not implemented.');
5255
}
53-
readonly _redirectPersistence = browserSessionPersistence;
54-
_completeRedirectFn: () => Promise<null> = async () => null;
5556
}
5657

5758
function checkCordovaConfiguration(auth: Auth): void {
@@ -60,36 +61,30 @@ function checkCordovaConfiguration(auth: Auth): void {
6061
// Note that cordova-universal-links-plugin has been abandoned.
6162
// A fork with latest fixes is available at:
6263
// https://www.npmjs.com/package/cordova-universal-links-plugin-fix
63-
if (typeof window?.universalLinks?.subscribe !== 'function') {
64-
_fail(auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
64+
_assert(typeof window?.universalLinks?.subscribe === 'function', auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
6565
missingPlugin: 'cordova-universal-links-plugin-fix'
6666
});
67-
}
6867

6968
// https://www.npmjs.com/package/cordova-plugin-buildinfo
70-
if (typeof window?.BuildInfo?.packageName === 'undefined') {
71-
_fail(auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
69+
_assert (typeof window?.BuildInfo?.packageName !== 'undefined', auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
7270
missingPlugin: 'cordova-plugin-buildInfo'
7371
});
74-
}
7572

7673
// https://github.com/google/cordova-plugin-browsertab
77-
if (typeof window?.cordova?.plugins?.browsertab?.openUrl !== 'function') {
78-
_fail(auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
74+
_assert(typeof window?.cordova?.plugins?.browsertab?.openUrl === 'function',
75+
auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
7976
missingPlugin: 'cordova-plugin-browsertab'
8077
});
81-
}
8278

8379
// https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/
84-
if (typeof window?.cordova?.InAppBrowser?.open !== 'function') {
85-
_fail(auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
80+
_assert(typeof window?.cordova?.InAppBrowser?.open === 'function',
81+
auth, AuthErrorCode.INVALID_CORDOVA_CONFIGURATION, {
8682
missingPlugin: 'cordova-plugin-inappbrowser'
8783
});
88-
}
8984
}
9085

9186
/**
92-
* An implementation of {@link @firebase/auth-types#PopupRedirectResolver} suitable for browser
87+
* An implementation of {@link @firebase/auth-types#PopupRedirectResolver} suitable for Cordova
9388
* based applications.
9489
*
9590
* @public

0 commit comments

Comments
 (0)