@@ -28,7 +28,11 @@ import { TEST_AUTH_DOMAIN, TEST_KEY, testAuth } from '../../test/mock_auth';
28
28
import { AuthEventManager } from '../core/auth/auth_event_manager' ;
29
29
import { OAuthProvider } from '../core/providers/oauth' ;
30
30
import { Auth } from '../model/auth' ;
31
- import { AuthEvent , AuthEventType , GapiAuthEvent } from '../model/popup_redirect' ;
31
+ import {
32
+ AuthEvent ,
33
+ AuthEventType ,
34
+ GapiAuthEvent
35
+ } from '../model/popup_redirect' ;
32
36
import * as gapiLoader from './iframe/gapi' ;
33
37
import { BrowserPopupRedirectResolver } from './popup_redirect' ;
34
38
@@ -38,7 +42,7 @@ use(sinonChai);
38
42
describe ( 'src/platform_browser/popup_redirect' , ( ) => {
39
43
let resolver : BrowserPopupRedirectResolver ;
40
44
let auth : Auth ;
41
-
45
+
42
46
beforeEach ( async ( ) => {
43
47
auth = await testAuth ( ) ;
44
48
resolver = new BrowserPopupRedirectResolver ( ) ;
@@ -49,7 +53,7 @@ describe('src/platform_browser/popup_redirect', () => {
49
53
} ) ;
50
54
51
55
context ( '#openPopup' , ( ) => {
52
- let popupUrl : string | undefined ;
56
+ let popupUrl : string | undefined ;
53
57
let provider : OAuthProvider ;
54
58
const event = AuthEventType . LINK_VIA_POPUP ;
55
59
@@ -64,43 +68,53 @@ describe('src/platform_browser/popup_redirect', () => {
64
68
it ( 'builds the correct url' , async ( ) => {
65
69
provider . addScope ( 'some-scope-a' ) ;
66
70
provider . addScope ( 'some-scope-b' ) ;
67
- provider . setCustomParameters ( { foo : 'bar' } ) ;
71
+ provider . setCustomParameters ( { foo : 'bar' } ) ;
68
72
69
73
await resolver . openPopup ( auth , provider , event ) ;
70
- expect ( popupUrl ) . to . include ( `https://${ TEST_AUTH_DOMAIN } /__/auth/handler` ) ;
74
+ expect ( popupUrl ) . to . include (
75
+ `https://${ TEST_AUTH_DOMAIN } /__/auth/handler`
76
+ ) ;
71
77
expect ( popupUrl ) . to . include ( `apiKey=${ TEST_KEY } ` ) ;
72
78
expect ( popupUrl ) . to . include ( 'appName=test-app' ) ;
73
79
expect ( popupUrl ) . to . include ( `authType=${ AuthEventType . LINK_VIA_POPUP } ` ) ;
74
80
expect ( popupUrl ) . to . include ( `v=${ SDK_VERSION } ` ) ;
75
81
expect ( popupUrl ) . to . include ( 'scopes=some-scope-a%2Csome-scope-b' ) ;
76
- expect ( popupUrl ) . to . include ( 'customParameters=%7B%22foo%22%3A%22bar%22%7D' ) ;
82
+ expect ( popupUrl ) . to . include (
83
+ 'customParameters=%7B%22foo%22%3A%22bar%22%7D'
84
+ ) ;
77
85
} ) ;
78
86
79
87
it ( 'throws an error if authDomain is unspecified' , async ( ) => {
80
88
delete auth . config . authDomain ;
81
89
82
- await expect ( resolver . openPopup ( auth , provider , event ) ) . to . be . rejectedWith (
83
- FirebaseError , 'auth/auth-domain-config-required' ,
84
- ) ;
90
+ await expect (
91
+ resolver . openPopup ( auth , provider , event )
92
+ ) . to . be . rejectedWith ( FirebaseError , 'auth/auth-domain-config-required' ) ;
85
93
} ) ;
86
94
87
95
it ( 'throws an error if apiKey is unspecified' , async ( ) => {
88
96
delete auth . config . apiKey ;
89
97
90
- await expect ( resolver . openPopup ( auth , provider , event ) ) . to . be . rejectedWith (
91
- FirebaseError , 'auth/invalid-api-key' ,
92
- ) ;
98
+ await expect (
99
+ resolver . openPopup ( auth , provider , event )
100
+ ) . to . be . rejectedWith ( FirebaseError , 'auth/invalid-api-key' ) ;
93
101
} ) ;
94
102
} ) ;
95
103
96
104
context ( '#initialize' , ( ) => {
97
105
let onIframeMessage : ( event : GapiAuthEvent ) => Promise < void > ;
98
106
beforeEach ( ( ) => {
99
- sinon . stub ( gapiLoader , '_loadGapi' ) . returns ( Promise . resolve ( {
100
- open : ( ) => Promise . resolve ( {
101
- register : ( _message : string , cb : ( event : GapiAuthEvent ) => Promise < void > ) => onIframeMessage = cb
102
- } )
103
- } as unknown as gapi . iframes . Context ) ) ;
107
+ sinon . stub ( gapiLoader , '_loadGapi' ) . returns (
108
+ Promise . resolve ( ( {
109
+ open : ( ) =>
110
+ Promise . resolve ( {
111
+ register : (
112
+ _message : string ,
113
+ cb : ( event : GapiAuthEvent ) => Promise < void >
114
+ ) => ( onIframeMessage = cb )
115
+ } )
116
+ } as unknown ) as gapi . iframes . Context )
117
+ ) ;
104
118
} ) ;
105
119
106
120
it ( 'only registers once, returns same event manager' , async ( ) => {
@@ -109,19 +123,19 @@ describe('src/platform_browser/popup_redirect', () => {
109
123
} ) ;
110
124
111
125
it ( 'iframe event goes through to the manager' , async ( ) => {
112
- const manager = await resolver . initialize ( auth ) as AuthEventManager ;
126
+ const manager = ( await resolver . initialize ( auth ) ) as AuthEventManager ;
113
127
sinon . spy ( manager , 'onEvent' ) ;
114
128
const response = await onIframeMessage ( {
115
129
type : 'authEvent' ,
116
- authEvent : { type : AuthEventType . LINK_VIA_POPUP } as AuthEvent
130
+ authEvent : { type : AuthEventType . LINK_VIA_POPUP } as AuthEvent
117
131
} ) ;
118
132
119
- expect ( manager . onEvent ) . to . have . been . calledWith (
120
- { type : AuthEventType . LINK_VIA_POPUP }
121
- ) ;
133
+ expect ( manager . onEvent ) . to . have . been . calledWith ( {
134
+ type : AuthEventType . LINK_VIA_POPUP
135
+ } ) ;
122
136
expect ( response ) . to . eql ( {
123
- status : 'ACK' ,
137
+ status : 'ACK'
124
138
} ) ;
125
139
} ) ;
126
140
} ) ;
127
- } ) ;
141
+ } ) ;
0 commit comments