Skip to content

Commit 8241eb6

Browse files
committed
Merge remote-tracking branch 'origin/master' into launch.next
2 parents 151eda9 + 139e1d9 commit 8241eb6

File tree

13 files changed

+394
-236
lines changed

13 files changed

+394
-236
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
- Adds RTDB Triggers for v2 functions (#1127)
2+
- Adds support for Firebase Admin SDK v11 (#1151)
3+
- Fixes bug where emulated task queue function required auth header (#1154)

spec/common/change.spec.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2022 Firebase
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import { expect } from 'chai';
24+
import * as change from '../../src/common/change';
25+
26+
describe('Change', () => {
27+
describe('applyFieldMask', () => {
28+
const after = {
29+
foo: 'bar',
30+
num: 2,
31+
obj: {
32+
a: 1,
33+
b: 2,
34+
},
35+
};
36+
37+
it('should handle deleted values', () => {
38+
const sparseBefore = { baz: 'qux' };
39+
const fieldMask = 'baz';
40+
expect(
41+
change.applyFieldMask(sparseBefore, after, fieldMask)
42+
).to.deep.equal({
43+
foo: 'bar',
44+
num: 2,
45+
obj: {
46+
a: 1,
47+
b: 2,
48+
},
49+
baz: 'qux',
50+
});
51+
});
52+
53+
it('should handle created values', () => {
54+
const sparseBefore = {};
55+
const fieldMask = 'num,obj.a';
56+
expect(
57+
change.applyFieldMask(sparseBefore, after, fieldMask)
58+
).to.deep.equal({
59+
foo: 'bar',
60+
obj: {
61+
b: 2,
62+
},
63+
});
64+
});
65+
66+
it('should handle mutated values', () => {
67+
const sparseBefore = {
68+
num: 3,
69+
obj: {
70+
a: 3,
71+
},
72+
};
73+
const fieldMask = 'num,obj.a';
74+
expect(
75+
change.applyFieldMask(sparseBefore, after, fieldMask)
76+
).to.deep.equal({
77+
foo: 'bar',
78+
num: 3,
79+
obj: {
80+
a: 3,
81+
b: 2,
82+
},
83+
});
84+
});
85+
});
86+
87+
describe('fromJSON', () => {
88+
it('should create a Change object with a `before` and `after`', () => {
89+
const created = change.Change.fromJSON<any>({
90+
before: { foo: 'bar' },
91+
after: { foo: 'faz' },
92+
});
93+
expect(created instanceof change.Change).to.equal(true);
94+
expect(created.before).to.deep.equal({ foo: 'bar' });
95+
expect(created.after).to.deep.equal({ foo: 'faz' });
96+
});
97+
98+
it('should apply the customizer function to `before` and `after`', () => {
99+
function customizer<T>(input: any) {
100+
input.another = 'value';
101+
return input as T;
102+
}
103+
const created = change.Change.fromJSON<object>(
104+
{
105+
before: { foo: 'bar' },
106+
after: { foo: 'faz' },
107+
},
108+
customizer
109+
);
110+
expect(created.before).to.deep.equal({
111+
foo: 'bar',
112+
another: 'value',
113+
});
114+
expect(created.after).to.deep.equal({
115+
foo: 'faz',
116+
another: 'value',
117+
});
118+
});
119+
});
120+
});

spec/common/providers/tasks.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('onEnqueueHandler', () => {
8383
function mockEnqueueRequest(
8484
data: unknown,
8585
contentType: string = 'application/json',
86-
context: { authorization: string } = { authorization: 'Bearer abc' }
86+
context: { authorization?: string } = { authorization: 'Bearer abc' }
8787
): ReturnType<typeof mockRequest> {
8888
return mockRequest(data, contentType, context);
8989
}
@@ -239,4 +239,24 @@ describe('onEnqueueHandler', () => {
239239
expectedStatus: 204,
240240
});
241241
});
242+
243+
it('should skip auth in emulated environment', async () => {
244+
const restore = process.env.FUNCTIONS_EMULATOR;
245+
process.env.FUNCTIONS_EMULATOR = 'true';
246+
247+
await runTaskTest({
248+
httpRequest: mockEnqueueRequest(null, 'application/json', {}),
249+
expectedData: null,
250+
taskFunction: (data, context) => {
251+
expect(context.auth).to.be.undefined;
252+
return null;
253+
},
254+
taskFunction2: (request) => {
255+
expect(request.auth).to.be.undefined;
256+
},
257+
expectedStatus: 204,
258+
});
259+
260+
process.env.FUNCTIONS_EMULATOR = restore;
261+
});
242262
});

spec/v1/cloud-functions.spec.ts

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import { expect } from 'chai';
2424

2525
import {
26-
Change,
2726
Event,
2827
EventContext,
2928
makeCloudFunction,
@@ -339,101 +338,3 @@ describe('makeAuth and makeAuthType', () => {
339338
});
340339
});
341340
});
342-
343-
describe('Change', () => {
344-
describe('applyFieldMask', () => {
345-
const after = {
346-
foo: 'bar',
347-
num: 2,
348-
obj: {
349-
a: 1,
350-
b: 2,
351-
},
352-
};
353-
354-
it('should handle deleted values', () => {
355-
const sparseBefore = { baz: 'qux' };
356-
const fieldMask = 'baz';
357-
expect(
358-
Change.applyFieldMask(sparseBefore, after, fieldMask)
359-
).to.deep.equal({
360-
foo: 'bar',
361-
num: 2,
362-
obj: {
363-
a: 1,
364-
b: 2,
365-
},
366-
baz: 'qux',
367-
});
368-
});
369-
370-
it('should handle created values', () => {
371-
const sparseBefore = {};
372-
const fieldMask = 'num,obj.a';
373-
expect(
374-
Change.applyFieldMask(sparseBefore, after, fieldMask)
375-
).to.deep.equal({
376-
foo: 'bar',
377-
obj: {
378-
b: 2,
379-
},
380-
});
381-
});
382-
383-
it('should handle mutated values', () => {
384-
const sparseBefore = {
385-
num: 3,
386-
obj: {
387-
a: 3,
388-
},
389-
};
390-
const fieldMask = 'num,obj.a';
391-
expect(
392-
Change.applyFieldMask(sparseBefore, after, fieldMask)
393-
).to.deep.equal({
394-
foo: 'bar',
395-
num: 3,
396-
obj: {
397-
a: 3,
398-
b: 2,
399-
},
400-
});
401-
});
402-
});
403-
404-
describe('fromJSON', () => {
405-
it('should create a Change object with a `before` and `after`', () => {
406-
const created = Change.fromJSON<any>({
407-
before: { foo: 'bar' },
408-
after: { foo: 'faz' },
409-
});
410-
expect(created instanceof Change).to.equal(true);
411-
expect(created.before).to.deep.equal({ foo: 'bar' });
412-
expect(created.after).to.deep.equal({ foo: 'faz' });
413-
});
414-
415-
it('should apply the customizer function to `before` and `after`', () => {
416-
function customizer<T>(input: any) {
417-
if (input) {
418-
input.another = 'value';
419-
}
420-
return input as T;
421-
}
422-
const created = Change.fromJSON<object>(
423-
{
424-
before: { foo: 'bar' },
425-
after: { foo: 'faz' },
426-
},
427-
customizer
428-
);
429-
expect(created.before).to.deep.equal({
430-
foo: 'bar',
431-
another: 'value',
432-
});
433-
expect(created.after).to.deep.equal({
434-
foo: 'faz',
435-
another: 'value',
436-
});
437-
});
438-
});
439-
});

spec/v2/providers/database.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ describe('database', () => {
363363
});
364364
});
365365

366-
describe('onRefWritten', () => {
366+
describe('onValueWritten', () => {
367367
it('should create a function with a reference', () => {
368-
const func = database.onRefWritten('/foo/{bar}/', (event) => 2);
368+
const func = database.onValueWritten('/foo/{bar}/', (event) => 2);
369369

370370
expect(func.__endpoint).to.deep.equal({
371371
platform: 'gcfv2',
@@ -383,7 +383,7 @@ describe('database', () => {
383383
});
384384

385385
it('should create a function with opts', () => {
386-
const func = database.onRefWritten(
386+
const func = database.onValueWritten(
387387
{
388388
ref: '/foo/{path=**}/{bar}/',
389389
instance: 'my-instance',
@@ -414,9 +414,9 @@ describe('database', () => {
414414
});
415415
});
416416

417-
describe('onRefCreated', () => {
417+
describe('onValueCreated', () => {
418418
it('should create a function with a reference', () => {
419-
const func = database.onRefCreated('/foo/{bar}/', (event) => 2);
419+
const func = database.onValueCreated('/foo/{bar}/', (event) => 2);
420420

421421
expect(func.__endpoint).to.deep.equal({
422422
platform: 'gcfv2',
@@ -434,7 +434,7 @@ describe('database', () => {
434434
});
435435

436436
it('should create a function with opts', () => {
437-
const func = database.onRefCreated(
437+
const func = database.onValueCreated(
438438
{
439439
ref: '/foo/{path=**}/{bar}/',
440440
instance: 'my-instance',
@@ -465,9 +465,9 @@ describe('database', () => {
465465
});
466466
});
467467

468-
describe('onRefUpdated', () => {
468+
describe('onValueUpdated', () => {
469469
it('should create a function with a reference', () => {
470-
const func = database.onRefUpdated('/foo/{bar}/', (event) => 2);
470+
const func = database.onValueUpdated('/foo/{bar}/', (event) => 2);
471471

472472
expect(func.__endpoint).to.deep.equal({
473473
platform: 'gcfv2',
@@ -485,7 +485,7 @@ describe('database', () => {
485485
});
486486

487487
it('should create a function with opts', () => {
488-
const func = database.onRefUpdated(
488+
const func = database.onValueUpdated(
489489
{
490490
ref: '/foo/{path=**}/{bar}/',
491491
instance: 'my-instance',
@@ -516,9 +516,9 @@ describe('database', () => {
516516
});
517517
});
518518

519-
describe('onRefDeleted', () => {
519+
describe('onValueDeleted', () => {
520520
it('should create a function with a reference', () => {
521-
const func = database.onRefDeleted('/foo/{bar}/', (event) => 2);
521+
const func = database.onValueDeleted('/foo/{bar}/', (event) => 2);
522522

523523
expect(func.__endpoint).to.deep.equal({
524524
platform: 'gcfv2',
@@ -536,7 +536,7 @@ describe('database', () => {
536536
});
537537

538538
it('should create a function with opts', () => {
539-
const func = database.onRefDeleted(
539+
const func = database.onValueDeleted(
540540
{
541541
ref: '/foo/{path=**}/{bar}/',
542542
instance: 'my-instance',

0 commit comments

Comments
 (0)