Skip to content

Commit 784e294

Browse files
committed
Formatting
1 parent d67c00d commit 784e294

File tree

7 files changed

+83
-45
lines changed

7 files changed

+83
-45
lines changed

packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import { testAuth, testUser } from '../../../test/mock_auth';
2929
import { makeMockPopupRedirectResolver } from '../../../test/mock_popup_redirect_resolver';
3030
import { Auth } from '../../model/auth';
3131
import {
32-
AuthEvent, AuthEventType, EventManager, PopupRedirectResolver
32+
AuthEvent,
33+
AuthEventType,
34+
EventManager,
35+
PopupRedirectResolver
3336
} from '../../model/popup_redirect';
3437
import { AuthEventManager } from '../auth/auth_event_manager';
3538
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors';
@@ -73,14 +76,26 @@ describe('src/core/strategies/abstract_popup_redirect_operation', () => {
7376

7477
context('#execute', () => {
7578
let operation: WrapperOperation;
76-
79+
7780
beforeEach(() => {
78-
operation = new WrapperOperation(auth, AuthEventType.LINK_VIA_POPUP, resolver);
79-
idpStubs._signIn.returns(Promise.resolve(new UserCredentialImpl(testUser(auth, 'uid'), null, OperationType.SIGN_IN)));
81+
operation = new WrapperOperation(
82+
auth,
83+
AuthEventType.LINK_VIA_POPUP,
84+
resolver
85+
);
86+
idpStubs._signIn.returns(
87+
Promise.resolve(
88+
new UserCredentialImpl(
89+
testUser(auth, 'uid'),
90+
null,
91+
OperationType.SIGN_IN
92+
)
93+
)
94+
);
8095
});
8196

8297
/** Finishes out the promise */
83-
function finishPromise(outcome: AuthEvent|FirebaseError): void {
98+
function finishPromise(outcome: AuthEvent | FirebaseError): void {
8499
delay((): void => {
85100
if (outcome instanceof FirebaseError) {
86101
operation.onError(outcome);
@@ -111,14 +126,20 @@ describe('src/core/strategies/abstract_popup_redirect_operation', () => {
111126
finishPromise(authEvent());
112127
await operation.execute();
113128
expect(eventManager.registerConsumer).to.have.been.calledWith(operation);
114-
expect(eventManager.unregisterConsumer).to.have.been.calledWith(operation);
129+
expect(eventManager.unregisterConsumer).to.have.been.calledWith(
130+
operation
131+
);
115132
});
116133

117134
it('unregisters itself in case of error', async () => {
118135
sinon.spy(eventManager, 'unregisterConsumer');
119136
finishPromise(ERROR);
120-
try { await operation.execute(); } catch {}
121-
expect(eventManager.unregisterConsumer).to.have.been.calledWith(operation);
137+
try {
138+
await operation.execute();
139+
} catch {}
140+
expect(eventManager.unregisterConsumer).to.have.been.calledWith(
141+
operation
142+
);
122143
});
123144

124145
it('emits the user credential returned from idp task', async () => {
@@ -153,7 +174,7 @@ describe('src/core/strategies/abstract_popup_redirect_operation', () => {
153174

154175
context('idp tasks', () => {
155176
function updateFilter(type: AuthEventType): void {
156-
(operation as unknown as Record<string, unknown>).filter = type;
177+
((operation as unknown) as Record<string, unknown>).filter = type;
157178
}
158179

159180
function expectedIdpTaskParams(): idp.IdpTaskParams {
@@ -163,57 +184,57 @@ describe('src/core/strategies/abstract_popup_redirect_operation', () => {
163184
sessionId: BASE_AUTH_EVENT.sessionId!,
164185
tenantId: BASE_AUTH_EVENT.tenantId || undefined,
165186
postBody: BASE_AUTH_EVENT.postBody || undefined,
166-
user: undefined,
187+
user: undefined
167188
};
168189
}
169190

170191
it('routes SIGN_IN_VIA_POPUP', async () => {
171192
const type = AuthEventType.SIGN_IN_VIA_POPUP;
172193
updateFilter(type);
173-
finishPromise(authEvent({type}));
194+
finishPromise(authEvent({ type }));
174195
await operation.execute();
175196
expect(idp._signIn).to.have.been.calledWith(expectedIdpTaskParams());
176197
});
177198

178199
it('routes SIGN_IN_VIA_REDIRECT', async () => {
179200
const type = AuthEventType.SIGN_IN_VIA_REDIRECT;
180201
updateFilter(type);
181-
finishPromise(authEvent({type}));
202+
finishPromise(authEvent({ type }));
182203
await operation.execute();
183204
expect(idp._signIn).to.have.been.calledWith(expectedIdpTaskParams());
184205
});
185206

186207
it('routes LINK_VIA_POPUP', async () => {
187208
const type = AuthEventType.LINK_VIA_POPUP;
188209
updateFilter(type);
189-
finishPromise(authEvent({type}));
210+
finishPromise(authEvent({ type }));
190211
await operation.execute();
191212
expect(idp._link).to.have.been.calledWith(expectedIdpTaskParams());
192213
});
193214

194215
it('routes LINK_VIA_REDIRECT', async () => {
195216
const type = AuthEventType.LINK_VIA_REDIRECT;
196217
updateFilter(type);
197-
finishPromise(authEvent({type}));
218+
finishPromise(authEvent({ type }));
198219
await operation.execute();
199220
expect(idp._link).to.have.been.calledWith(expectedIdpTaskParams());
200221
});
201222

202223
it('routes REAUTH_VIA_POPUP', async () => {
203224
const type = AuthEventType.REAUTH_VIA_POPUP;
204225
updateFilter(type);
205-
finishPromise(authEvent({type}));
226+
finishPromise(authEvent({ type }));
206227
await operation.execute();
207228
expect(idp._reauth).to.have.been.calledWith(expectedIdpTaskParams());
208229
});
209230

210231
it('routes REAUTH_VIA_REDIRECT', async () => {
211232
const type = AuthEventType.REAUTH_VIA_REDIRECT;
212233
updateFilter(type);
213-
finishPromise(authEvent({type}));
234+
finishPromise(authEvent({ type }));
214235
await operation.execute();
215236
expect(idp._reauth).to.have.been.calledWith(expectedIdpTaskParams());
216237
});
217238
});
218239
});
219-
});
240+
});

packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { FirebaseError } from '@firebase/util';
1919

2020
import { Auth } from '../../model/auth';
2121
import {
22-
AuthEvent, AuthEventConsumer, AuthEventType, EventManager, PopupRedirectResolver
22+
AuthEvent,
23+
AuthEventConsumer,
24+
AuthEventType,
25+
EventManager,
26+
PopupRedirectResolver
2327
} from '../../model/popup_redirect';
2428
import { User, UserCredential } from '../../model/user';
2529
import { AuthErrorCode } from '../errors';
@@ -35,19 +39,19 @@ interface PendingPromise {
3539
* Popup event manager. Handles the popup's entire lifecycle; listens to auth
3640
* events
3741
*/
38-
export abstract class AbstractPopupRedirectOperation implements AuthEventConsumer {
42+
export abstract class AbstractPopupRedirectOperation
43+
implements AuthEventConsumer {
3944
private pendingPromise: PendingPromise | null = null;
4045
private eventManager: EventManager | null = null;
41-
42-
abstract eventId: string|null;
46+
47+
abstract eventId: string | null;
4348

4449
constructor(
4550
protected readonly auth: Auth,
4651
readonly filter: AuthEventType,
4752
protected readonly resolver: PopupRedirectResolver,
4853
protected user?: User
49-
) {
50-
}
54+
) {}
5155

5256
abstract onExecution(): Promise<void>;
5357

@@ -92,12 +96,12 @@ export abstract class AbstractPopupRedirectOperation implements AuthEventConsume
9296
this.reject(error);
9397
}
9498

95-
isMatchingEvent(eventId: string|null): boolean {
99+
isMatchingEvent(eventId: string | null): boolean {
96100
return !!eventId && this.eventId === eventId;
97101
}
98102

99103
private getIdpTask(type: AuthEventType): IdpTask {
100-
switch(type) {
104+
switch (type) {
101105
case AuthEventType.SIGN_IN_VIA_POPUP:
102106
case AuthEventType.SIGN_IN_VIA_REDIRECT:
103107
return _signIn;
@@ -123,7 +127,7 @@ export abstract class AbstractPopupRedirectOperation implements AuthEventConsume
123127
this.pendingPromise.reject(error);
124128
this.unregisterAndCleanUp();
125129
}
126-
130+
127131
private unregisterAndCleanUp(): void {
128132
if (this.eventManager) {
129133
this.eventManager.unregisterConsumer(this);

packages-exp/auth-exp/src/core/strategies/idp.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
import * as externs from '@firebase/auth-types-exp';
1919

20-
import { signInWithIdp, SignInWithIdpRequest } from '../../api/authentication/idp';
20+
import {
21+
signInWithIdp,
22+
SignInWithIdpRequest
23+
} from '../../api/authentication/idp';
2124
import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa';
2225
import { Auth } from '../../model/auth';
2326
import { IdTokenResponse } from '../../model/id_token';
@@ -87,23 +90,20 @@ class IdpCredential implements AuthCredential {
8790
}
8891
}
8992

90-
export function _signIn(
91-
params: IdpTaskParams
92-
): Promise<UserCredential> {
93-
return signInWithCredential(params.auth, new IdpCredential(params)) as Promise<UserCredential>;
93+
export function _signIn(params: IdpTaskParams): Promise<UserCredential> {
94+
return signInWithCredential(
95+
params.auth,
96+
new IdpCredential(params)
97+
) as Promise<UserCredential>;
9498
}
9599

96-
export function _reauth(
97-
params: IdpTaskParams
98-
): Promise<UserCredential> {
100+
export function _reauth(params: IdpTaskParams): Promise<UserCredential> {
99101
const { auth, user } = params;
100102
assert(user, auth.name);
101103
return _reauthenticate(user, new IdpCredential(params));
102104
}
103105

104-
export async function _link(
105-
params: IdpTaskParams
106-
): Promise<UserCredential> {
106+
export async function _link(params: IdpTaskParams): Promise<UserCredential> {
107107
const { auth, user } = params;
108108
assert(user, auth.name);
109109
return _linkUser(user, new IdpCredential(params));

packages-exp/auth-exp/src/core/strategies/popup.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import * as chaiAsPromised from 'chai-as-promised';
2020
import * as sinon from 'sinon';
2121
import * as sinonChai from 'sinon-chai';
2222

23-
import { OperationType, PopupRedirectResolver, ProviderId } from '@firebase/auth-types-exp';
23+
import {
24+
OperationType,
25+
PopupRedirectResolver,
26+
ProviderId
27+
} from '@firebase/auth-types-exp';
2428
import { FirebaseError } from '@firebase/util';
2529

2630
import { delay } from '../../../test/delay';
@@ -39,8 +43,11 @@ import * as eid from '../util/event_id';
3943
import { AuthPopup } from '../util/popup';
4044
import * as idpTasks from './idp';
4145
import {
42-
_AUTH_EVENT_TIMEOUT, _POLL_WINDOW_CLOSE_TIMEOUT, linkWithPopup, reauthenticateWithPopup,
43-
signInWithPopup
46+
_AUTH_EVENT_TIMEOUT,
47+
_POLL_WINDOW_CLOSE_TIMEOUT,
48+
linkWithPopup,
49+
reauthenticateWithPopup,
50+
signInWithPopup
4451
} from './popup';
4552

4653
use(sinonChai);

packages-exp/auth-exp/src/core/strategies/popup.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import * as externs from '@firebase/auth-types-exp';
1919

2020
import { Auth } from '../../model/auth';
21-
import { AuthEventType, PopupRedirectResolver } from '../../model/popup_redirect';
21+
import {
22+
AuthEventType,
23+
PopupRedirectResolver
24+
} from '../../model/popup_redirect';
2225
import { User, UserCredential } from '../../model/user';
2326
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors';
2427
import { Delay } from '../util/delay';
@@ -144,7 +147,7 @@ class PopupOperation extends AbstractPopupRedirectOperation {
144147
if (this.pollId) {
145148
window.clearTimeout(this.pollId);
146149
}
147-
150+
148151
this.authWindow = null;
149152
this.pollId = null;
150153
PopupOperation.currentPopupAction = null;

packages-exp/auth-exp/test/iframe_event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ export function authEvent(event: Partial<AuthEvent> = {}): AuthEvent {
3131
...BASE_AUTH_EVENT,
3232
...event
3333
};
34-
}
34+
}

packages-exp/auth-exp/test/mock_popup_redirect_resolver.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { EventManager } from '../src/model/popup_redirect';
2525
* Generates a PopupRedirectResolver that can be used by the oauth methods.
2626
* These methods expect a class that can be instantiated.
2727
*/
28-
export function makeMockPopupRedirectResolver(eventManager?: EventManager, authPopup?: AuthPopup): PopupRedirectResolver {
28+
export function makeMockPopupRedirectResolver(
29+
eventManager?: EventManager,
30+
authPopup?: AuthPopup
31+
): PopupRedirectResolver {
2932
return class implements PopupRedirectResolver {
3033
async _initialize(): Promise<EventManager> {
3134
return eventManager || new AuthEventManager('test-app');
@@ -35,4 +38,4 @@ export function makeMockPopupRedirectResolver(eventManager?: EventManager, authP
3538
return authPopup || new AuthPopup(null);
3639
}
3740
};
38-
}
41+
}

0 commit comments

Comments
 (0)