Skip to content

Commit afcb54c

Browse files
committed
chore: remove debug tests
1 parent 81531c5 commit afcb54c

2 files changed

Lines changed: 1 addition & 235 deletions

File tree

test/integration/auth.spec.ts

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ import {
3333
TenantAwareAuth, UpdatePhoneMultiFactorInfoRequest, UpdateTenantRequest, UserImportOptions,
3434
UserImportRecord, UserRecord, getAuth, UpdateProjectConfigRequest, UserMetadata, MultiFactorConfig,
3535
PasswordPolicyConfig, SmsRegionConfig, RecaptchaConfig, ActionCodeSettings,
36-
FirebaseAuthError,
3736
} from '../../lib/auth/index';
3837
import * as sinon from 'sinon';
3938
import * as sinonChai from 'sinon-chai';
40-
import { FirebaseAppError, initializeApp, deleteApp } from '../../lib/app';
4139

4240
const chalk = require('chalk'); // eslint-disable-line @typescript-eslint/no-var-requires
4341

@@ -3551,76 +3549,7 @@ async function deleteUsersWithDelay(uids: string[]): Promise<DeleteUsersResult>
35513549
return getAuth().deleteUsers(uids);
35523550
}
35533551

3554-
describe('Standardized Error Handling Demonstration', () => {
3555-
it('demoErrorResponseLogs: should have httpResponse when a request fails', async () => {
3556-
const auth = getAuth();
3557-
console.log('\n\n=======================================================');
3558-
console.log('🔥 DEMONSTRATION 1: FIREBASE ERROR WITH RESPONSE');
3559-
console.log('=======================================================');
3560-
try {
3561-
console.log('Attempting to fetch a non-existent user...');
3562-
await auth.getUser('non-existent-uid-' + Date.now());
3563-
} catch (err: any) {
3564-
console.log('\n🔥 Caught Exception:');
3565-
if (err instanceof FirebaseAuthError) {
3566-
console.log('Exception message:', err.message);
3567-
console.log('Error code:', err.code);
3568-
console.log('Cause:', err.cause);
3569-
3570-
if (err.httpResponse) {
3571-
console.log('\n📡 HTTP Response Metadata Attached:');
3572-
console.log('Status Code:', err.httpResponse.status);
3573-
console.log('Content Data:', err.httpResponse.data);
3574-
console.log('Headers:', err.httpResponse.headers);
3575-
} else {
3576-
console.log('\n📡 No HTTP Response metadata attached.');
3577-
}
3578-
}
3579-
}
3580-
console.log('=======================================================\n\n');
3581-
});
3582-
3583-
it('demoErrorResponseLogs: should have error cause', async () => {
3584-
const originalHost = process.env.FIREBASE_AUTH_EMULATOR_HOST;
3585-
process.env.FIREBASE_AUTH_EMULATOR_HOST = 'completely.nonexistent.domain.invalid:9999';
3586-
3587-
// Create a new app instance to ensure a fresh Auth instance is created with the new env var
3588-
const demoApp = initializeApp({ projectId: 'demo-project-' + Date.now() }, 'demo-app-' + Date.now());
3589-
const auth = getAuth(demoApp);
35903552

3591-
console.log('\n\n=======================================================');
3592-
console.log('🔥 DEMONSTRATION 2: FIREBASE ERROR WITH CAUSE');
3593-
console.log('=======================================================');
3594-
try {
3595-
console.log('Attempting to fetch a user with a simulated network error...');
3596-
await auth.getUser('some-uid');
3597-
} catch (err: any) {
3598-
// console.log(err);
3599-
if (err instanceof FirebaseAppError || err instanceof FirebaseAuthError) {
3600-
console.log('\n🔥 Caught Exception:');
3601-
console.log('Exception message:', err.message);
3602-
console.log('Error code:', err.code);
3603-
console.log('Cause:', err.cause);
3604-
3605-
if (err.httpResponse) {
3606-
console.log('\n📡 HTTP Response Metadata Attached:');
3607-
console.log('Status Code:', err.httpResponse.status);
3608-
console.log('Content Data:', err.httpResponse.data);
3609-
console.log('Headers:', err.httpResponse.headers);
3610-
} else {
3611-
console.log('\n📡 No HTTP Response metadata attached.');
3612-
}
3613-
} else {
3614-
console.log('\n🔥 Caught non-Firebase error:');
3615-
console.log(err);
3616-
}
3617-
} finally {
3618-
process.env.FIREBASE_AUTH_EMULATOR_HOST = originalHost;
3619-
await deleteApp(demoApp);
3620-
}
3621-
console.log('=======================================================\n\n');
3622-
});
3623-
});
36243553

36253554
/**
36263555
* Asserts actual object is equal to expected object while ignoring key order.

test/unit/auth/auth.spec.ts

Lines changed: 1 addition & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import * as jwt from 'jsonwebtoken';
2121
import * as _ from 'lodash';
2222
import * as chai from 'chai';
23-
import * as nock from 'nock';
2423
import * as sinon from 'sinon';
2524
import * as sinonChai from 'sinon-chai';
2625
import * as chaiAsPromised from 'chai-as-promised';
@@ -32,7 +31,7 @@ import { FirebaseApp } from '../../../src/app/firebase-app';
3231
import {
3332
AuthRequestHandler, TenantAwareAuthRequestHandler, AbstractAuthRequestHandler,
3433
} from '../../../src/auth/auth-api-request';
35-
import { AuthClientErrorCode, FirebaseAppError, FirebaseAuthError } from '../../../src/utils/error';
34+
import { AuthClientErrorCode, FirebaseAuthError } from '../../../src/utils/error';
3635

3736
import * as validator from '../../../src/utils/validator';
3837
import { DecodedAuthBlockingToken, FirebaseTokenVerifier } from '../../../src/auth/token-verifier';
@@ -3977,167 +3976,5 @@ AUTH_CONFIGS.forEach((testConfig) => {
39773976
});
39783977
});
39793978

3980-
describe('Standardized Error Handling Demonstration', () => {
3981-
let auth: Auth;
3982-
let mockApp: FirebaseApp;
3983-
3984-
beforeEach(() => {
3985-
mockApp = mocks.appWithOptions({
3986-
credential: new mocks.MockCredential(),
3987-
projectId: 'project-id',
3988-
});
3989-
auth = new Auth(mockApp);
3990-
});
3991-
3992-
afterEach(() => {
3993-
nock.cleanAll();
3994-
});
3995-
3996-
it('demoErrorWithCause: should have a cause when a low-level network error occurs', async () => {
3997-
const uid = 'some-uid';
3998-
const expectedError = new Error('Network failure');
3999-
4000-
// Simulate a low-level network error using nock
4001-
nock('https://identitytoolkit.googleapis.com')
4002-
.post(/.*accounts:lookup.*/)
4003-
.replyWithError(expectedError);
4004-
4005-
console.log('\n\n=======================================================');
4006-
console.log('🔥 DEMONSTRATION 1: FIREBASE ERROR WITH CAUSE');
4007-
console.log('=======================================================');
4008-
try {
4009-
console.log('Attempting to fetch a user with a simulated network error...');
4010-
await auth.getUser(uid);
4011-
} catch (err: any) {
4012-
if (err instanceof FirebaseAppError || err instanceof FirebaseAuthError) {
4013-
console.log('\n🔥 Caught Exception:');
4014-
console.log('Exception message:', err.message);
4015-
console.log('Error code:', err.code);
4016-
console.log('Cause:', err.cause);
4017-
4018-
if (err.httpResponse) {
4019-
console.log('\n📡 HTTP Response Metadata Attached:');
4020-
console.log('Status Code:', err.httpResponse.status);
4021-
console.log('Content Data:', err.httpResponse.data);
4022-
console.log('Headers:', err.httpResponse.headers);
4023-
} else {
4024-
console.log('\n📡 No HTTP Response metadata attached.');
4025-
}
4026-
}
4027-
}
4028-
console.log('=======================================================\n\n');
4029-
});
4030-
4031-
it('demoErrorWithResponse: should have httpResponse when a request fails', async () => {
4032-
const uid = 'some-uid';
4033-
4034-
// Simulate a server error using nock
4035-
nock('https://identitytoolkit.googleapis.com')
4036-
.post(/.*accounts:lookup.*/)
4037-
.reply(200, {
4038-
// Missing 'users' field
4039-
somethingElse: 'unexpected'
4040-
});
4041-
4042-
console.log('\n\n=======================================================');
4043-
console.log('🔥 DEMONSTRATION 2: FIREBASE ERROR WITH RESPONSE');
4044-
console.log('=======================================================');
4045-
try {
4046-
console.log('Attempting to fetch a user with a simulated server error...');
4047-
await auth.getUser(uid);
4048-
} catch (err: any) {
4049-
if (err instanceof FirebaseAppError || err instanceof FirebaseAuthError) {
4050-
console.log('\n🔥 Caught Exception:');
4051-
console.log('Exception message:', err.message);
4052-
console.log('Error code:', err.code);
4053-
console.log('Cause:', err.cause);
4054-
4055-
if (err.httpResponse) {
4056-
console.log('\n📡 HTTP Response Metadata Attached:');
4057-
console.log(' Status Code:', err.httpResponse.status);
4058-
console.log(' Content Data:', JSON.stringify(err.httpResponse.data));
4059-
console.log(' Headers:', JSON.stringify(err.httpResponse.headers));
4060-
} else {
4061-
console.log('\n📡 No HTTP Response metadata attached.');
4062-
}
4063-
}
4064-
}
4065-
console.log('=======================================================\n\n');
4066-
});
4067-
it('demoErrorWithUnextractableCode: should have cause when errorCode is missing', async () => {
4068-
const uid = 'some-uid';
4069-
4070-
// Simulate a server error with an invalid body using nock
4071-
nock('https://identitytoolkit.googleapis.com')
4072-
.post(/.*accounts:lookup.*/)
4073-
.reply(500, {
4074-
// No error code or message
4075-
foo: 'bar'
4076-
});
4077-
4078-
console.log('\n\n=======================================================');
4079-
console.log('🔥 DEMONSTRATION 3: FIREBASE ERROR WITH UNEXTRACTABLE CODE');
4080-
console.log('=======================================================');
4081-
try {
4082-
console.log('Attempting to fetch a user with a simulated unextractable error...');
4083-
await auth.getUser(uid);
4084-
} catch (err: any) {
4085-
if (err instanceof FirebaseAppError || err instanceof FirebaseAuthError) {
4086-
console.log('\n🔥 Caught Exception:');
4087-
console.log(err);
4088-
console.log('Exception message:', err.message);
4089-
console.log('Error code:', err.code);
4090-
console.log('Cause:', err.cause);
4091-
4092-
if (err.httpResponse) {
4093-
console.log('\n📡 HTTP Response Metadata Attached:');
4094-
console.log(' Status Code:', err.httpResponse.status);
4095-
console.log(' Content Data:', JSON.stringify(err.httpResponse.data));
4096-
console.log(' Headers:', JSON.stringify(err.httpResponse.headers));
4097-
} else {
4098-
console.log('\n📡 No HTTP Response metadata attached.');
4099-
}
4100-
}
4101-
}
4102-
console.log('=======================================================\n\n');
4103-
});
41043979

4105-
it('demoErrorWithValidFormat: should have cause and httpResponse when error has valid format', async () => {
4106-
const uid = 'some-uid';
4107-
4108-
// Simulate a server error with a valid body using nock
4109-
nock('https://identitytoolkit.googleapis.com')
4110-
.post(/.*accounts:lookup.*/)
4111-
.reply(400, {
4112-
error: {
4113-
message: 'USER_NOT_FOUND : Some detailed custom message here: with more colons',
4114-
}
4115-
});
4116-
4117-
console.log('\n\n=======================================================');
4118-
console.log('🔥 DEMONSTRATION 4: FIREBASE ERROR WITH VALID FORMAT');
4119-
console.log('=======================================================');
4120-
try {
4121-
console.log('Attempting to fetch a user with a simulated valid formatted error...');
4122-
await auth.getUser(uid);
4123-
} catch (err: any) {
4124-
if (err instanceof FirebaseAppError || err instanceof FirebaseAuthError) {
4125-
console.log('\n🔥 Caught Exception:');
4126-
console.log('Exception message:', err.message);
4127-
console.log('Error code:', err.code);
4128-
console.log('Cause:', err.cause);
4129-
4130-
if (err.httpResponse) {
4131-
console.log('\n📡 HTTP Response Metadata Attached:');
4132-
console.log(' Status Code:', err.httpResponse.status);
4133-
console.log(' Content Data:', JSON.stringify(err.httpResponse.data));
4134-
console.log(' Headers:', JSON.stringify(err.httpResponse.headers));
4135-
} else {
4136-
console.log('\n📡 No HTTP Response metadata attached.');
4137-
}
4138-
}
4139-
}
4140-
console.log('=======================================================\n\n');
4141-
});
4142-
});
41433980
});

0 commit comments

Comments
 (0)