15
15
* limitations under the License.
16
16
*/
17
17
18
- import * as sinonChai from 'sinon-chai' ;
18
+ import * as sinonChai from 'sinon-chai' ;
19
19
import * as sinon from 'sinon' ;
20
20
import { FirebaseError , querystring } from '@firebase/util' ;
21
21
import { expect , use } from 'chai' ;
22
22
import { testAuth , TestAuth } from '../../../test/helpers/mock_auth' ;
23
23
import { AuthEvent , AuthEventType } from '../../model/popup_redirect' ;
24
- import { _eventFromPartialAndUrl , _generateNewEvent , _getAndRemoveEvent , _getDeepLinkFromCallback , _savePartialEvent } from './events' ;
24
+ import {
25
+ _eventFromPartialAndUrl ,
26
+ _generateNewEvent ,
27
+ _getAndRemoveEvent ,
28
+ _getDeepLinkFromCallback ,
29
+ _savePartialEvent
30
+ } from './events' ;
25
31
import { _createError } from '../../core/util/assert' ;
26
32
import { AuthErrorCode } from '../../core/errors' ;
27
33
@@ -65,10 +71,13 @@ describe('platform_cordova/popup_redirect/events', () => {
65
71
} ) ;
66
72
67
73
describe ( '_savePartialEvent' , ( ) => {
68
- it ( 'sets the event' , async ( ) => {
74
+ it ( 'sets the event' , async ( ) => {
69
75
const event = _generateNewEvent ( auth , AuthEventType . REAUTH_VIA_REDIRECT ) ;
70
76
await _savePartialEvent ( auth , event ) ;
71
- expect ( storageStub . setItem ) . to . have . been . calledWith ( 'firebase:authEvent:test-api-key:test-app' , JSON . stringify ( event ) ) ;
77
+ expect ( storageStub . setItem ) . to . have . been . calledWith (
78
+ 'firebase:authEvent:test-api-key:test-app' ,
79
+ JSON . stringify ( event )
80
+ ) ;
72
81
} ) ;
73
82
} ) ;
74
83
@@ -79,19 +88,27 @@ describe('platform_cordova/popup_redirect/events', () => {
79
88
} ) ;
80
89
81
90
it ( 'returns the event and deletes the key if present' , async ( ) => {
82
- const event = JSON . stringify ( _generateNewEvent ( auth , AuthEventType . REAUTH_VIA_REDIRECT ) ) ;
91
+ const event = JSON . stringify (
92
+ _generateNewEvent ( auth , AuthEventType . REAUTH_VIA_REDIRECT )
93
+ ) ;
83
94
storageStub . getItem . returns ( event ) ;
84
95
expect ( await _getAndRemoveEvent ( auth ) ) . to . eql ( JSON . parse ( event ) ) ;
85
- expect ( storageStub . removeItem ) . to . have . been . calledWith ( 'firebase:authEvent:test-api-key:test-app' ) ;
96
+ expect ( storageStub . removeItem ) . to . have . been . calledWith (
97
+ 'firebase:authEvent:test-api-key:test-app'
98
+ ) ;
86
99
} ) ;
87
100
} ) ;
88
101
89
102
describe ( '_eventFromPartialAndUrl' , ( ) => {
90
103
let partialEvent : AuthEvent ;
91
104
beforeEach ( ( ) => {
92
- partialEvent = _generateNewEvent ( auth , AuthEventType . REAUTH_VIA_REDIRECT , 'id' ) ;
105
+ partialEvent = _generateNewEvent (
106
+ auth ,
107
+ AuthEventType . REAUTH_VIA_REDIRECT ,
108
+ 'id'
109
+ ) ;
93
110
} ) ;
94
-
111
+
95
112
function generateCallbackUrl ( params : Record < string , string > ) : string {
96
113
const deepLink = `http://foo/__/auth/callback?${ querystring ( params ) } ` ;
97
114
return `http://outer-app?link=${ encodeURIComponent ( deepLink ) } ` ;
@@ -105,7 +122,7 @@ describe('platform_cordova/popup_redirect/events', () => {
105
122
tenantId : null ,
106
123
sessionId : partialEvent . sessionId ,
107
124
urlResponse : 'http://foo/__/auth/callback?' ,
108
- postBody : null ,
125
+ postBody : null
109
126
} ) ;
110
127
} ) ;
111
128
@@ -116,45 +133,63 @@ describe('platform_cordova/popup_redirect/events', () => {
116
133
it ( 'generates an error if the callback has an error' , ( ) => {
117
134
const handlerError = _createError ( AuthErrorCode . INTERNAL_ERROR ) ;
118
135
const url = generateCallbackUrl ( {
119
- 'firebaseError' : JSON . stringify ( handlerError ) ,
136
+ 'firebaseError' : JSON . stringify ( handlerError )
120
137
} ) ;
121
- const { error, ...rest } = _eventFromPartialAndUrl ( partialEvent , url ) ! ;
138
+ const { error, ...rest } = _eventFromPartialAndUrl ( partialEvent , url ) ! ;
122
139
123
- expect ( error ) . to . be . instanceOf ( FirebaseError ) . with . property ( 'code' , 'auth/internal-error' ) ;
140
+ expect ( error )
141
+ . to . be . instanceOf ( FirebaseError )
142
+ . with . property ( 'code' , 'auth/internal-error' ) ;
124
143
expect ( rest ) . to . eql ( {
125
144
type : AuthEventType . REAUTH_VIA_REDIRECT ,
126
145
eventId : 'id' ,
127
146
tenantId : null ,
128
147
urlResponse : null ,
129
148
sessionId : null ,
130
- postBody : null ,
149
+ postBody : null
131
150
} ) ;
132
151
} ) ;
133
152
} ) ;
134
153
135
154
describe ( '_getDeepLinkFromCallback' , ( ) => {
136
155
it ( 'returns the iOS double deep link preferentially' , ( ) => {
137
- expect ( _getDeepLinkFromCallback ( 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep' +
138
- '&deep_link_id=http%3A%2F%2Ffoo%3Flink%3DdoubleDeepIos' ) ) . to . eq ( 'doubleDeepIos' ) ;
156
+ expect (
157
+ _getDeepLinkFromCallback (
158
+ 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep' +
159
+ '&deep_link_id=http%3A%2F%2Ffoo%3Flink%3DdoubleDeepIos'
160
+ )
161
+ ) . to . eq ( 'doubleDeepIos' ) ;
139
162
} ) ;
140
163
141
164
it ( 'returns the iOS deep link preferentially' , ( ) => {
142
- expect ( _getDeepLinkFromCallback ( 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep' +
143
- '&deep_link_id=http%3A%2F%2FfooIOS' ) ) . to . eq ( 'http://fooIOS' ) ;
165
+ expect (
166
+ _getDeepLinkFromCallback (
167
+ 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep' +
168
+ '&deep_link_id=http%3A%2F%2FfooIOS'
169
+ )
170
+ ) . to . eq ( 'http://fooIOS' ) ;
144
171
} ) ;
145
172
146
173
it ( 'returns double deep link preferentially' , ( ) => {
147
- expect ( _getDeepLinkFromCallback ( 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep' ) ) . to . eq ( 'doubleDeep' ) ;
174
+ expect (
175
+ _getDeepLinkFromCallback (
176
+ 'https://foo?link=http%3A%2F%2Ffoo%3Flink%3DdoubleDeep'
177
+ )
178
+ ) . to . eq ( 'doubleDeep' ) ;
148
179
} ) ;
149
-
180
+
150
181
it ( 'returns the deep link preferentially' , ( ) => {
151
- expect ( _getDeepLinkFromCallback ( 'https://foo?link=http%3A%2F%2Ffoo%3Funrelated%3Dyeah' ) ) . to . eq (
152
- 'http://foo?unrelated=yeah'
153
- ) ;
182
+ expect (
183
+ _getDeepLinkFromCallback (
184
+ 'https://foo?link=http%3A%2F%2Ffoo%3Funrelated%3Dyeah'
185
+ )
186
+ ) . to . eq ( 'http://foo?unrelated=yeah' ) ;
154
187
} ) ;
155
188
156
189
it ( 'returns the passed-in url when all else fails' , ( ) => {
157
- expect ( _getDeepLinkFromCallback ( 'https://foo?bar=baz' ) ) . to . eq ( 'https://foo?bar=baz' ) ;
190
+ expect ( _getDeepLinkFromCallback ( 'https://foo?bar=baz' ) ) . to . eq (
191
+ 'https://foo?bar=baz'
192
+ ) ;
158
193
} ) ;
159
194
} ) ;
160
195
} ) ;
0 commit comments