Skip to content

Commit b8e5442

Browse files
committed
PR feedback
1 parent 075dab0 commit b8e5442

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

packages-exp/auth-exp/src/api/index.test.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FirebaseError } from '@firebase/util';
1919
import { expect, use } from 'chai';
2020
import * as chaiAsPromised from 'chai-as-promised';
2121
import { SinonStub, stub, useFakeTimers } from 'sinon';
22-
import { DEFAULT_API_TIMEOUT, Endpoint, HttpMethod, performApiRequest } from '.';
22+
import { DEFAULT_API_TIMEOUT_MS, Endpoint, HttpMethod, performApiRequest } from '.';
2323
import { mockEndpoint } from '../../test/api/helper';
2424
import { mockAuth } from '../../test/mock_auth';
2525
import * as mockFetch from '../../test/mock_fetch';
@@ -43,7 +43,12 @@ describe('performApiRequest', () => {
4343

4444
it('should set the correct request, method and HTTP Headers', async () => {
4545
const mock = mockEndpoint(Endpoint.SIGN_UP, serverResponse);
46-
const response = await performApiRequest<typeof request, typeof serverResponse>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request);
46+
const response = await performApiRequest<typeof request, typeof serverResponse>(
47+
mockAuth,
48+
HttpMethod.POST,
49+
Endpoint.SIGN_UP,
50+
request
51+
);
4752
expect(response).to.eql(serverResponse);
4853
expect(mock.calls.length).to.eq(1);
4954
expect(mock.calls[0].method).to.eq(HttpMethod.POST);
@@ -69,7 +74,12 @@ describe('performApiRequest', () => {
6974
},
7075
400
7176
);
72-
const promise = performApiRequest<typeof request, typeof serverResponse>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request);
77+
const promise = performApiRequest<typeof request, typeof serverResponse>(
78+
mockAuth,
79+
HttpMethod.POST,
80+
Endpoint.SIGN_UP,
81+
request
82+
);
7383
await expect(promise).to.be.rejectedWith(
7484
FirebaseError,
7585
'Firebase: The email address is already in use by another account. (auth/email-already-in-use).'
@@ -93,7 +103,12 @@ describe('performApiRequest', () => {
93103
},
94104
400
95105
);
96-
const promise = performApiRequest<typeof request, typeof serverResponse>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request);
106+
const promise = performApiRequest<typeof request, typeof serverResponse>(
107+
mockAuth,
108+
HttpMethod.POST,
109+
Endpoint.SIGN_UP,
110+
request
111+
);
97112
await expect(promise).to.be.rejectedWith(
98113
FirebaseError,
99114
'Firebase: An internal AuthError has occurred. (auth/internal-error).'
@@ -117,7 +132,14 @@ describe('performApiRequest', () => {
117132
},
118133
400
119134
);
120-
const promise = performApiRequest<typeof request, typeof serverResponse>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request, { [ServerError.EMAIL_EXISTS]: AuthErrorCode.ARGUMENT_ERROR });
135+
const promise = performApiRequest<typeof request, typeof serverResponse>(
136+
mockAuth,
137+
HttpMethod.POST,
138+
Endpoint.SIGN_UP,
139+
request,
140+
{
141+
[ServerError.EMAIL_EXISTS]: AuthErrorCode.ARGUMENT_ERROR
142+
});
121143
await expect(promise).to.be.rejectedWith(
122144
FirebaseError,
123145
'Firebase: Error (auth/argument-error).'
@@ -142,8 +164,13 @@ describe('performApiRequest', () => {
142164
fetchStub.callsFake(() => {
143165
return new Promise<never>(() => null);
144166
});
145-
const promise = performApiRequest<typeof request, never>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request);
146-
clock.tick(DEFAULT_API_TIMEOUT + 1);
167+
const promise = performApiRequest<typeof request, never>(
168+
mockAuth,
169+
HttpMethod.POST,
170+
Endpoint.SIGN_UP,
171+
request
172+
);
173+
clock.tick(DEFAULT_API_TIMEOUT_MS + 1);
147174
await expect(promise).to.be.rejectedWith(FirebaseError, 'Firebase: The operation has timed out. (auth/timeout).');
148175
clock.restore();
149176
});
@@ -152,7 +179,12 @@ describe('performApiRequest', () => {
152179
fetchStub.callsFake(() => {
153180
return new Promise<never>((_, reject) => reject(new Error('network error')));
154181
});
155-
const promise = performApiRequest<typeof request, never>(mockAuth, HttpMethod.POST, Endpoint.SIGN_UP, request);
182+
const promise = performApiRequest<typeof request, never>(
183+
mockAuth,
184+
HttpMethod.POST,
185+
Endpoint.SIGN_UP,
186+
request
187+
);
156188
await expect(promise).to.be.rejectedWith(FirebaseError, 'Firebase: A network AuthError (such as timeout]: interrupted connection or unreachable host) has occurred. (auth/network-request-failed).');
157189
});
158190
});

packages-exp/auth-exp/src/api/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export enum Endpoint {
5353
WITHDRAW_MFA = '/v2/accounts/mfaEnrollment:withdraw'
5454
}
5555

56-
export const DEFAULT_API_TIMEOUT = 30_000;
56+
export const DEFAULT_API_TIMEOUT_MS = 30_000;
5757

5858
export async function performApiRequest<T, V>(
5959
auth: Auth,
@@ -97,7 +97,9 @@ export async function performApiRequest<T, V>(
9797
...body
9898
}
9999
), new Promise((_, reject) =>
100-
setTimeout(() => reject(AUTH_ERROR_FACTORY.create(AuthErrorCode.TIMEOUT, { appName: auth.name })), DEFAULT_API_TIMEOUT)
100+
setTimeout(() => {
101+
return reject(AUTH_ERROR_FACTORY.create(AuthErrorCode.TIMEOUT, { appName: auth.name }));
102+
}, DEFAULT_API_TIMEOUT_MS)
101103
)]);
102104
if (response.ok) {
103105
return response.json();

0 commit comments

Comments
 (0)