@@ -34,13 +34,13 @@ describe('platform_cordova/popup_redirect', () => {
34
34
35
35
beforeEach ( async ( ) => {
36
36
auth = await testAuth ( ) ;
37
+ attachExpectedPlugins ( ) ;
37
38
resolver = new ( cordovaPopupRedirectResolver as SingletonInstantiator < PopupRedirectResolver > ) ( ) ;
38
39
} ) ;
39
40
40
41
describe ( '_openRedirect plugin checks' , ( ) => {
41
42
// TODO: Rest of the tests go here
42
43
it ( 'does not reject if all plugins installed' , ( ) => {
43
- setExpectedPluginsButMissing ( [ ] ) ;
44
44
expect ( ( ) =>
45
45
resolver . _openRedirect (
46
46
auth ,
@@ -51,55 +51,58 @@ describe('platform_cordova/popup_redirect', () => {
51
51
} ) ;
52
52
53
53
it ( 'rejects if universal links is missing' , ( ) => {
54
- setExpectedPluginsButMissing ( [ 'universalLinks.subscribe' ] ) ;
54
+ removeProp ( window , 'universalLinks' ) ;
55
55
expect ( ( ) =>
56
56
resolver . _openRedirect (
57
57
auth ,
58
58
new GoogleAuthProvider ( ) ,
59
59
AuthEventType . SIGN_IN_VIA_REDIRECT
60
60
)
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' } ) ;
62
63
} ) ;
63
64
64
65
it ( 'rejects if build info is missing' , ( ) => {
65
- setExpectedPluginsButMissing ( [ 'BuildInfo. packageName'] ) ;
66
+ removeProp ( window . BuildInfo , ' packageName') ;
66
67
expect ( ( ) =>
67
68
resolver . _openRedirect (
68
69
auth ,
69
70
new GoogleAuthProvider ( ) ,
70
71
AuthEventType . SIGN_IN_VIA_REDIRECT
71
72
)
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' } ) ;
73
75
} ) ;
74
76
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') ;
77
79
expect ( ( ) =>
78
80
resolver . _openRedirect (
79
81
auth ,
80
82
new GoogleAuthProvider ( ) ,
81
83
AuthEventType . SIGN_IN_VIA_REDIRECT
82
84
)
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' } ) ;
84
87
} ) ;
85
88
86
89
it ( 'rejects if InAppBrowser is missing' , ( ) => {
87
- setExpectedPluginsButMissing ( [ ' cordova.InAppBrowser. open'] ) ;
90
+ removeProp ( window . cordova . InAppBrowser , ' open') ;
88
91
expect ( ( ) =>
89
92
resolver . _openRedirect (
90
93
auth ,
91
94
new GoogleAuthProvider ( ) ,
92
95
AuthEventType . SIGN_IN_VIA_REDIRECT
93
96
)
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' } ) ;
95
99
} ) ;
96
100
} ) ;
97
101
} ) ;
98
102
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 > ;
103
106
win . cordova = {
104
107
plugins : {
105
108
browsertab : {
@@ -115,17 +118,10 @@ function setExpectedPluginsButMissing(missingPlugins: string[]): void {
115
118
subscribe : ( ) => { }
116
119
} ;
117
120
win . BuildInfo = {
118
- packageName : 'com.name.package'
121
+ packageName : 'com.example. name.package'
119
122
} ;
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
- }
131
123
}
124
+
125
+ function removeProp ( obj : unknown , prop : string ) :void {
126
+ delete ( obj as Record < string , unknown > ) [ prop ] ;
127
+ }
0 commit comments