Skip to content

Commit bebb398

Browse files
authored
Rework apps, update admin, remove lodash (#1144)
* Update admin; remove lodash * Adding missing file * Uncomment code
1 parent e844387 commit bebb398

26 files changed

+342
-524
lines changed

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@
184184
"@types/express": "4.17.3",
185185
"cors": "^2.8.5",
186186
"express": "^4.17.1",
187-
"lodash": "^4.17.14",
188187
"node-fetch": "^2.6.7"
189188
},
190189
"devDependencies": {
@@ -194,7 +193,6 @@
194193
"@types/chai": "^4.1.7",
195194
"@types/chai-as-promised": "^7.1.0",
196195
"@types/jsonwebtoken": "^8.3.2",
197-
"@types/lodash": "^4.14.135",
198196
"@types/mocha": "^5.2.7",
199197
"@types/mock-require": "^2.0.0",
200198
"@types/nock": "^10.0.3",
@@ -234,4 +232,4 @@
234232
"engines": {
235233
"node": ">=14.10.0"
236234
}
237-
}
235+
}

spec/common/providers/https.spec.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai';
2-
import * as firebase from 'firebase-admin';
2+
import { App, deleteApp, initializeApp } from 'firebase-admin/app';
33
import * as sinon from 'sinon';
44

5-
import { apps as appsNamespace } from '../../../src/apps';
5+
import { getApp, setApp } from '../../../src/common/app';
66
import * as debug from '../../../src/common/debug';
77
import * as https from '../../../src/common/providers/https';
88
import * as mocks from '../../fixtures/credential/key.json';
@@ -76,7 +76,7 @@ async function runCallableTest(test: CallTest): Promise<any> {
7676
}
7777

7878
describe('onCallHandler', () => {
79-
let app: firebase.app.App;
79+
let app: App;
8080

8181
before(() => {
8282
const credential = {
@@ -92,16 +92,16 @@ describe('onCallHandler', () => {
9292
};
9393
},
9494
};
95-
app = firebase.initializeApp({
95+
app = initializeApp({
9696
projectId: 'aProjectId',
9797
credential,
9898
});
99-
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
99+
setApp(app);
100100
});
101101

102102
after(() => {
103-
app.delete();
104-
delete appsNamespace.singleton;
103+
deleteApp(app);
104+
setApp(undefined);
105105
});
106106

107107
it('should handle success', () => {
@@ -288,7 +288,7 @@ describe('onCallHandler', () => {
288288

289289
it('should handle auth', async () => {
290290
const mock = mockFetchPublicKeys();
291-
const projectId = appsNamespace().admin.options.projectId;
291+
const projectId = getApp().options.projectId;
292292
const idToken = generateIdToken(projectId);
293293
await runCallableTest({
294294
httpRequest: mockRequest(null, 'application/json', {
@@ -313,7 +313,7 @@ describe('onCallHandler', () => {
313313
});
314314

315315
it('should reject bad auth', async () => {
316-
const projectId = appsNamespace().admin.options.projectId;
316+
const projectId = getApp().options.projectId;
317317
const idToken = generateUnsignedIdToken(projectId);
318318
await runCallableTest({
319319
httpRequest: mockRequest(null, 'application/json', {
@@ -341,7 +341,7 @@ describe('onCallHandler', () => {
341341

342342
it('should handle AppCheck token', async () => {
343343
const mock = mockFetchAppCheckPublicJwks();
344-
const projectId = appsNamespace().admin.options.projectId;
344+
const projectId = getApp().options.projectId;
345345
const appId = '123:web:abc';
346346
const appCheckToken = generateAppCheckToken(projectId, appId);
347347
await runCallableTest({
@@ -365,7 +365,7 @@ describe('onCallHandler', () => {
365365
});
366366

367367
it('should reject bad AppCheck token', async () => {
368-
const projectId = appsNamespace().admin.options.projectId;
368+
const projectId = getApp().options.projectId;
369369
const appId = '123:web:abc';
370370
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
371371
await runCallableTest({
@@ -536,7 +536,7 @@ describe('onCallHandler', () => {
536536
});
537537

538538
it('should skip auth token verification', async () => {
539-
const projectId = appsNamespace().admin.options.projectId;
539+
const projectId = getApp().options.projectId;
540540
const idToken = generateUnsignedIdToken(projectId);
541541
await runCallableTest({
542542
httpRequest: mockRequest(null, 'application/json', {
@@ -560,7 +560,7 @@ describe('onCallHandler', () => {
560560
});
561561

562562
it('should skip app check token verification', async () => {
563-
const projectId = appsNamespace().admin.options.projectId;
563+
const projectId = getApp().options.projectId;
564564
const appId = '123:web:abc';
565565
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
566566
await runCallableTest({

spec/common/providers/tasks.spec.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
// SOFTWARE.
2222

2323
import { expect } from 'chai';
24-
import * as firebase from 'firebase-admin';
24+
import { App, deleteApp, initializeApp } from 'firebase-admin/app';
2525

26-
import { apps as appsNamespace } from '../../../src/apps';
26+
import { getApp, setApp } from '../../../src/common/app';
2727
import * as https from '../../../src/common/providers/https';
2828
import {
2929
onDispatchHandler,
@@ -78,7 +78,7 @@ export async function runTaskTest(test: TaskTest): Promise<any> {
7878
}
7979

8080
describe('onEnqueueHandler', () => {
81-
let app: firebase.app.App;
81+
let app: App;
8282

8383
function mockEnqueueRequest(
8484
data: unknown,
@@ -102,16 +102,16 @@ describe('onEnqueueHandler', () => {
102102
};
103103
},
104104
};
105-
app = firebase.initializeApp({
105+
app = initializeApp({
106106
projectId: 'aProjectId',
107107
credential,
108108
});
109-
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
109+
setApp(app);
110110
});
111111

112112
after(() => {
113-
app.delete();
114-
delete appsNamespace.singleton;
113+
deleteApp(app);
114+
setApp(undefined);
115115
});
116116

117117
it('should handle success', () => {
@@ -201,7 +201,7 @@ describe('onEnqueueHandler', () => {
201201
});
202202

203203
it('should handle auth', async () => {
204-
const projectId = appsNamespace().admin.options.projectId;
204+
const projectId = getApp().options.projectId;
205205
const idToken = generateIdToken(projectId);
206206
await runTaskTest({
207207
httpRequest: mockEnqueueRequest(null, 'application/json', {
@@ -221,7 +221,7 @@ describe('onEnqueueHandler', () => {
221221
});
222222

223223
it('should accept unsigned auth too', async () => {
224-
const projectId = appsNamespace().admin.options.projectId;
224+
const projectId = getApp().options.projectId;
225225
const idToken = generateUnsignedIdToken(projectId);
226226
await runTaskTest({
227227
httpRequest: mockEnqueueRequest(null, 'application/json', {

spec/fixtures/mockrequest.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as jwt from 'jsonwebtoken';
22
import * as jwkToPem from 'jwk-to-pem';
3-
import * as _ from 'lodash';
43
import * as nock from 'nock';
54
import * as mockJWK from '../fixtures/credential/jwk.json';
65
import * as mockKey from '../fixtures/credential/key.json';
@@ -32,7 +31,7 @@ export function mockRequest(
3231
} = {}
3332
) {
3433
const body: any = {};
35-
if (!_.isUndefined(data)) {
34+
if (typeof data !== 'undefined') {
3635
body.data = data;
3736
}
3837

spec/v1/apps.spec.ts

-143
This file was deleted.

spec/v1/cloud-functions.spec.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
import { expect } from 'chai';
24-
import * as _ from 'lodash';
2524

2625
import {
2726
Change,
@@ -176,9 +175,10 @@ describe('makeCloudFunction', () => {
176175
});
177176

178177
it('should construct the right context for event', () => {
179-
const args: any = _.assign({}, cloudFunctionArgs, {
178+
const args: any = {
179+
...cloudFunctionArgs,
180180
handler: (data: any, context: EventContext) => context,
181-
});
181+
};
182182
const cf = makeCloudFunction(args);
183183
const test: Event = {
184184
context: {
@@ -206,10 +206,11 @@ describe('makeCloudFunction', () => {
206206
});
207207

208208
it('should throw error when context.params accessed in handler environment', () => {
209-
const args: any = _.assign({}, cloudFunctionArgs, {
209+
const args: any = {
210+
...cloudFunctionArgs,
210211
handler: (data: any, context: EventContext) => context,
211212
triggerResource: () => null,
212-
});
213+
};
213214
const cf = makeCloudFunction(args);
214215
const test: Event = {
215216
context: {
@@ -429,7 +430,9 @@ describe('Change', () => {
429430

430431
it('should apply the customizer function to `before` and `after`', () => {
431432
function customizer<T>(input: any) {
432-
_.set(input, 'another', 'value');
433+
if (input) {
434+
input.another = 'value';
435+
}
433436
return input as T;
434437
}
435438
const created = Change.fromJSON<object>(

0 commit comments

Comments
 (0)