Skip to content

Commit 7afacba

Browse files
committed
Formatting
1 parent c7b2524 commit 7afacba

File tree

2 files changed

+79
-34
lines changed

2 files changed

+79
-34
lines changed

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

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as sinonChai from 'sinon-chai';
18+
import * as sinonChai from 'sinon-chai';
1919
import * as sinon from 'sinon';
2020
import { FirebaseError, querystring } from '@firebase/util';
2121
import { expect, use } from 'chai';
2222
import { testAuth, TestAuth } from '../../../test/helpers/mock_auth';
2323
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';
2531
import { _createError } from '../../core/util/assert';
2632
import { AuthErrorCode } from '../../core/errors';
2733

@@ -65,10 +71,13 @@ describe('platform_cordova/popup_redirect/events', () => {
6571
});
6672

6773
describe('_savePartialEvent', () => {
68-
it('sets the event',async () => {
74+
it('sets the event', async () => {
6975
const event = _generateNewEvent(auth, AuthEventType.REAUTH_VIA_REDIRECT);
7076
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+
);
7281
});
7382
});
7483

@@ -79,19 +88,27 @@ describe('platform_cordova/popup_redirect/events', () => {
7988
});
8089

8190
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+
);
8394
storageStub.getItem.returns(event);
8495
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+
);
8699
});
87100
});
88101

89102
describe('_eventFromPartialAndUrl', () => {
90103
let partialEvent: AuthEvent;
91104
beforeEach(() => {
92-
partialEvent = _generateNewEvent(auth, AuthEventType.REAUTH_VIA_REDIRECT, 'id');
105+
partialEvent = _generateNewEvent(
106+
auth,
107+
AuthEventType.REAUTH_VIA_REDIRECT,
108+
'id'
109+
);
93110
});
94-
111+
95112
function generateCallbackUrl(params: Record<string, string>): string {
96113
const deepLink = `http://foo/__/auth/callback?${querystring(params)}`;
97114
return `http://outer-app?link=${encodeURIComponent(deepLink)}`;
@@ -105,7 +122,7 @@ describe('platform_cordova/popup_redirect/events', () => {
105122
tenantId: null,
106123
sessionId: partialEvent.sessionId,
107124
urlResponse: 'http://foo/__/auth/callback?',
108-
postBody: null,
125+
postBody: null
109126
});
110127
});
111128

@@ -116,45 +133,63 @@ describe('platform_cordova/popup_redirect/events', () => {
116133
it('generates an error if the callback has an error', () => {
117134
const handlerError = _createError(AuthErrorCode.INTERNAL_ERROR);
118135
const url = generateCallbackUrl({
119-
'firebaseError': JSON.stringify(handlerError),
136+
'firebaseError': JSON.stringify(handlerError)
120137
});
121-
const {error, ...rest} = _eventFromPartialAndUrl(partialEvent, url)!;
138+
const { error, ...rest } = _eventFromPartialAndUrl(partialEvent, url)!;
122139

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');
124143
expect(rest).to.eql({
125144
type: AuthEventType.REAUTH_VIA_REDIRECT,
126145
eventId: 'id',
127146
tenantId: null,
128147
urlResponse: null,
129148
sessionId: null,
130-
postBody: null,
149+
postBody: null
131150
});
132151
});
133152
});
134153

135154
describe('_getDeepLinkFromCallback', () => {
136155
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');
139162
});
140163

141164
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');
144171
});
145172

146173
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');
148179
});
149-
180+
150181
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');
154187
});
155188

156189
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+
);
158193
});
159194
});
160195
});

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import { querystringDecode } from '@firebase/util';
1919
import { AuthErrorCode } from '../../core/errors';
2020
import { PersistedBlob, Persistence } from '../../core/persistence';
21-
import { KeyName, _persistenceKeyName } from '../../core/persistence/persistence_user_manager';
21+
import {
22+
KeyName,
23+
_persistenceKeyName
24+
} from '../../core/persistence/persistence_user_manager';
2225
import { _createError } from '../../core/util/assert';
2326
import { _getInstance } from '../../core/util/instantiator';
2427
import { Auth } from '../../model/auth';
@@ -47,18 +50,23 @@ export function _generateNewEvent(
4750
}
4851

4952
export function _savePartialEvent(auth: Auth, event: AuthEvent): Promise<void> {
50-
return storage()._set(key(auth), event as object as PersistedBlob);
53+
return storage()._set(key(auth), (event as object) as PersistedBlob);
5154
}
5255

53-
export async function _getAndRemoveEvent(auth: Auth): Promise<AuthEvent|null> {
54-
const event = await storage()._get(key(auth)) as AuthEvent | null;
56+
export async function _getAndRemoveEvent(
57+
auth: Auth
58+
): Promise<AuthEvent | null> {
59+
const event = (await storage()._get(key(auth))) as AuthEvent | null;
5560
if (event) {
5661
await storage()._remove(key(auth));
5762
}
5863
return event;
5964
}
6065

61-
export function _eventFromPartialAndUrl(partialEvent: AuthEvent, url: string): AuthEvent|null {
66+
export function _eventFromPartialAndUrl(
67+
partialEvent: AuthEvent,
68+
url: string
69+
): AuthEvent | null {
6270
// Parse the deep link within the dynamic link URL.
6371
const callbackUrl = _getDeepLinkFromCallback(url);
6472
// Confirm it is actually a callback URL.
@@ -72,8 +80,9 @@ export function _eventFromPartialAndUrl(partialEvent: AuthEvent, url: string): A
7280
// https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
7381
const params = searchParamsOrEmpty(callbackUrl);
7482
// Get the error object corresponding to the stringified error if found.
75-
const errorObject = params['firebaseError'] ?
76-
JSON.parse(decodeURIComponent(params['firebaseError'])) : null;
83+
const errorObject = params['firebaseError']
84+
? JSON.parse(decodeURIComponent(params['firebaseError']))
85+
: null;
7786
const code = errorObject?.['code']?.split('auth/')?.[1];
7887
const error = code ? _createError(code) : null;
7988
if (error) {
@@ -84,7 +93,7 @@ export function _eventFromPartialAndUrl(partialEvent: AuthEvent, url: string): A
8493
error,
8594
urlResponse: null,
8695
sessionId: null,
87-
postBody: null,
96+
postBody: null
8897
};
8998
} else {
9099
return {
@@ -93,7 +102,7 @@ export function _eventFromPartialAndUrl(partialEvent: AuthEvent, url: string): A
93102
tenantId: partialEvent.tenantId,
94103
sessionId: partialEvent.sessionId,
95104
urlResponse: callbackUrl,
96-
postBody: null,
105+
postBody: null
97106
};
98107
}
99108
}
@@ -127,7 +136,9 @@ export function _getDeepLinkFromCallback(url: string): string {
127136
// Double link case (automatic redirect)
128137
const doubleDeepLink = searchParamsOrEmpty(link)['link'];
129138
// iOS custom scheme links.
130-
const iOSDeepLink = params['deep_link_id'] ? decodeURIComponent(params['deep_link_id']) : undefined;
139+
const iOSDeepLink = params['deep_link_id']
140+
? decodeURIComponent(params['deep_link_id'])
141+
: undefined;
131142
const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
132143
return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
133144
}
@@ -144,4 +155,3 @@ function searchParamsOrEmpty(url: string | undefined): Record<string, string> {
144155
const [_, ...rest] = url.split('?');
145156
return querystringDecode(rest.join('?')) as Record<string, string>;
146157
}
147-

0 commit comments

Comments
 (0)