Skip to content

Commit cb088dd

Browse files
committed
Fix broken test.
1 parent 20cf772 commit cb088dd

28 files changed

+294
-44
lines changed

spec/runtime/loader.spec.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as functions from "../../src/v1";
55
import * as loader from "../../src/runtime/loader";
66
import { ManifestEndpoint, ManifestRequiredAPI, ManifestStack } from "../../src/runtime/manifest";
77
import { clearParams } from "../../src/params";
8+
import { MINIMAL_ENDPOINT } from "../fixtures";
9+
import { MINIMAL_SCHEDULE_TRIGGER, MINIMIAL_TASK_QUEUE_TRIGGER } from "../v1/providers/fixtures";
810

911
describe("extractStack", () => {
1012
const httpFn = functions.https.onRequest(() => undefined);
@@ -32,8 +34,16 @@ describe("extractStack", () => {
3234
loader.extractStack(module, endpoints, requiredAPIs);
3335

3436
expect(endpoints).to.be.deep.equal({
35-
http: { entryPoint: "http", ...httpEndpoint },
36-
callable: { entryPoint: "callable", ...callableEndpoint },
37+
http: {
38+
...MINIMAL_ENDPOINT,
39+
entryPoint: "http",
40+
...httpEndpoint,
41+
},
42+
callable: {
43+
...MINIMAL_ENDPOINT,
44+
entryPoint: "callable",
45+
...callableEndpoint,
46+
},
3747
});
3848

3949
expect(requiredAPIs).to.be.empty;
@@ -51,9 +61,10 @@ describe("extractStack", () => {
5161

5262
expect(endpoints).to.be.deep.equal({
5363
taskq: {
64+
...MINIMAL_ENDPOINT,
5465
entryPoint: "taskq",
5566
platform: "gcfv1",
56-
taskQueueTrigger: {},
67+
taskQueueTrigger: MINIMIAL_TASK_QUEUE_TRIGGER,
5768
},
5869
});
5970

@@ -80,10 +91,12 @@ describe("extractStack", () => {
8091

8192
expect(endpoints).to.be.deep.equal({
8293
fn1: {
94+
...MINIMAL_ENDPOINT,
8395
entryPoint: "fn1",
8496
...httpEndpoint,
8597
},
8698
"g1-fn2": {
99+
...MINIMAL_ENDPOINT,
87100
entryPoint: "g1.fn2",
88101
...httpEndpoint,
89102
},
@@ -116,6 +129,7 @@ describe("extractStack", () => {
116129

117130
expect(endpoints).to.be.deep.equal({
118131
fn: {
132+
...MINIMAL_ENDPOINT,
119133
entryPoint: "fn",
120134
platform: "gcfv1",
121135
eventTrigger: {
@@ -142,11 +156,12 @@ describe("extractStack", () => {
142156

143157
expect(endpoints).to.be.deep.equal({
144158
scheduled: {
159+
...MINIMAL_ENDPOINT,
145160
entryPoint: "scheduled",
146161
platform: "gcfv1",
147162
// TODO: This label should not exist?
148163
labels: {},
149-
scheduleTrigger: { schedule: "every 5 minutes" },
164+
scheduleTrigger: { ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes" },
150165
},
151166
});
152167

@@ -217,23 +232,27 @@ describe("loadStack", () => {
217232
const expected: ManifestStack = {
218233
endpoints: {
219234
v1http: {
235+
...MINIMAL_ENDPOINT,
220236
platform: "gcfv1",
221237
entryPoint: "v1http",
222238
httpsTrigger: {},
223239
},
224240
v1callable: {
241+
...MINIMAL_ENDPOINT,
225242
platform: "gcfv1",
226243
entryPoint: "v1callable",
227244
labels: {},
228245
callableTrigger: {},
229246
},
230247
v2http: {
248+
...MINIMAL_ENDPOINT,
231249
platform: "gcfv2",
232250
entryPoint: "v2http",
233251
labels: {},
234252
httpsTrigger: {},
235253
},
236254
v2callable: {
255+
...MINIMAL_ENDPOINT,
237256
platform: "gcfv2",
238257
entryPoint: "v2callable",
239258
labels: {},
@@ -293,11 +312,13 @@ describe("loadStack", () => {
293312
endpoints: {
294313
...expected.endpoints,
295314
"g1-groupedhttp": {
315+
...MINIMAL_ENDPOINT,
296316
platform: "gcfv1",
297317
entryPoint: "g1.groupedhttp",
298318
httpsTrigger: {},
299319
},
300320
"g1-groupedcallable": {
321+
...MINIMAL_ENDPOINT,
301322
platform: "gcfv1",
302323
entryPoint: "g1.groupedcallable",
303324
labels: {},

spec/v1/cloud-functions.spec.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222

2323
import { expect } from "chai";
2424

25-
import { Event, EventContext, makeCloudFunction, MakeCloudFunctionArgs } from "../../src/v1";
25+
import {
26+
Event,
27+
EventContext,
28+
makeCloudFunction,
29+
MakeCloudFunctionArgs,
30+
RESET_VALUE,
31+
} from "../../src/v1";
32+
import { MINIMAL_ENDPOINT } from "../fixtures";
2633

2734
describe("makeCloudFunction", () => {
2835
const cloudFunctionArgs: MakeCloudFunctionArgs<any> = {
@@ -44,6 +51,7 @@ describe("makeCloudFunction", () => {
4451
});
4552

4653
expect(cf.__endpoint).to.deep.equal({
54+
...MINIMAL_ENDPOINT,
4755
platform: "gcfv1",
4856
eventTrigger: {
4957
eventType: "mock.provider.mock.event",
@@ -60,6 +68,7 @@ describe("makeCloudFunction", () => {
6068
const cf = makeCloudFunction(cloudFunctionArgs);
6169

6270
expect(cf.__endpoint).to.deep.equal({
71+
...MINIMAL_ENDPOINT,
6372
platform: "gcfv1",
6473
eventTrigger: {
6574
eventType: "providers/provider/eventTypes/event",
@@ -89,6 +98,7 @@ describe("makeCloudFunction", () => {
8998
});
9099

91100
expect(cf.__endpoint).to.deep.equal({
101+
...MINIMAL_ENDPOINT,
92102
platform: "gcfv1",
93103
timeoutSeconds: 10,
94104
region: ["us-central1"],
@@ -117,6 +127,7 @@ describe("makeCloudFunction", () => {
117127
});
118128

119129
expect(cf.__endpoint).to.deep.equal({
130+
...MINIMAL_ENDPOINT,
120131
platform: "gcfv1",
121132
eventTrigger: {
122133
eventType: "mock.provider.mock.event",
@@ -146,8 +157,18 @@ describe("makeCloudFunction", () => {
146157
},
147158
});
148159
expect(cf.__endpoint).to.deep.equal({
160+
...MINIMAL_ENDPOINT,
149161
platform: "gcfv1",
150-
scheduleTrigger: schedule,
162+
scheduleTrigger: {
163+
...schedule,
164+
retryConfig: {
165+
...schedule.retryConfig,
166+
maxBackoffDuration: RESET_VALUE,
167+
maxDoublings: RESET_VALUE,
168+
maxRetryDuration: RESET_VALUE,
169+
minBackoffDuration: RESET_VALUE,
170+
},
171+
},
151172
labels: {},
152173
});
153174
});

spec/v1/providers/analytics.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as functions from "../../../src/v1";
2626
import { Event } from "../../../src/v1/cloud-functions";
2727
import * as analytics from "../../../src/v1/providers/analytics";
2828
import * as analyticsSpecInput from "./analytics.spec.input";
29+
import { MINIMAL_ENDPOINT } from "../../fixtures";
2930

3031
describe("Analytics Functions", () => {
3132
describe("EventBuilder", () => {
@@ -57,6 +58,7 @@ describe("Analytics Functions", () => {
5758
const cloudFunction = analytics.event("first_open").onLog(() => null);
5859

5960
expect(cloudFunction.__endpoint).to.deep.equal({
61+
...MINIMAL_ENDPOINT,
6062
platform: "gcfv1",
6163
eventTrigger: {
6264
eventFilters: {

spec/v1/providers/auth.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { UserRecord } from "../../../src/common/providers/identity";
2525
import * as functions from "../../../src/v1";
2626
import { CloudFunction, Event } from "../../../src/v1/cloud-functions";
2727
import * as auth from "../../../src/v1/providers/auth";
28+
import { MINIMAL_ENDPOINT } from "../../fixtures";
2829

2930
describe("Auth Functions", () => {
3031
const event: Event = {
@@ -48,6 +49,7 @@ describe("Auth Functions", () => {
4849
describe("AuthBuilder", () => {
4950
function expectedEndpoint(project: string, eventType: string) {
5051
return {
52+
...MINIMAL_ENDPOINT,
5153
platform: "gcfv1",
5254
eventTrigger: {
5355
eventFilters: {
@@ -114,6 +116,7 @@ describe("Auth Functions", () => {
114116
const fn = auth.user().beforeCreate(() => Promise.resolve());
115117

116118
expect(fn.__endpoint).to.deep.equal({
119+
...MINIMAL_ENDPOINT,
117120
platform: "gcfv1",
118121
labels: {},
119122
blockingTrigger: {
@@ -149,6 +152,7 @@ describe("Auth Functions", () => {
149152
.beforeCreate(() => Promise.resolve());
150153

151154
expect(fn.__endpoint).to.deep.equal({
155+
...MINIMAL_ENDPOINT,
152156
platform: "gcfv1",
153157
labels: {},
154158
region: ["us-east1"],
@@ -177,6 +181,7 @@ describe("Auth Functions", () => {
177181
const fn = auth.user().beforeSignIn(() => Promise.resolve());
178182

179183
expect(fn.__endpoint).to.deep.equal({
184+
...MINIMAL_ENDPOINT,
180185
platform: "gcfv1",
181186
labels: {},
182187
blockingTrigger: {
@@ -212,6 +217,7 @@ describe("Auth Functions", () => {
212217
.beforeSignIn(() => Promise.resolve());
213218

214219
expect(fn.__endpoint).to.deep.equal({
220+
...MINIMAL_ENDPOINT,
215221
platform: "gcfv1",
216222
labels: {},
217223
region: ["us-east1"],

spec/v1/providers/database.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import { applyChange } from "../../../src/common/utilities/utils";
2727
import * as functions from "../../../src/v1";
2828
import * as database from "../../../src/v1/providers/database";
2929
import { expectType } from "../../common/metaprogramming";
30+
import { MINIMAL_ENDPOINT } from "../../fixtures";
3031

3132
describe("Database Functions", () => {
3233
describe("DatabaseBuilder", () => {
3334
// TODO add tests for building a data or change based on the type of operation
3435

3536
function expectedEndpoint(resource: string, eventType: string) {
3637
return {
38+
...MINIMAL_ENDPOINT,
3739
platform: "gcfv1",
3840
eventTrigger: {
3941
eventFilters: {

spec/v1/providers/firestore.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Timestamp } from "firebase-admin/firestore";
2626
import * as functions from "../../../src/v1";
2727
import * as firestore from "../../../src/v1/providers/firestore";
2828
import { expectType } from "../../common/metaprogramming";
29+
import { MINIMAL_ENDPOINT } from "../../fixtures";
2930

3031
describe("Firestore Functions", () => {
3132
function constructValue(fields: any) {
@@ -93,6 +94,7 @@ describe("Firestore Functions", () => {
9394
describe("document builders and event types", () => {
9495
function expectedEndpoint(resource: string, eventType: string) {
9596
return {
97+
...MINIMAL_ENDPOINT,
9698
platform: "gcfv1",
9799
eventTrigger: {
98100
eventFilters: {

spec/v1/providers/fixtures.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
import { ManifestEndpoint } from "../../../src/runtime/manifest";
23+
import * as functions from "../../../src/v1";
24+
import * as options from "../../../src/v2/options";
25+
26+
export const MINIMIAL_TASK_QUEUE_TRIGGER: ManifestEndpoint["taskQueueTrigger"] = {
27+
rateLimits: {
28+
maxConcurrentDispatches: functions.RESET_VALUE,
29+
maxDispatchesPerSecond: functions.RESET_VALUE,
30+
},
31+
retryConfig: {
32+
maxAttempts: functions.RESET_VALUE,
33+
maxBackoffSeconds: functions.RESET_VALUE,
34+
maxDoublings: functions.RESET_VALUE,
35+
maxRetrySeconds: functions.RESET_VALUE,
36+
minBackoffSeconds: functions.RESET_VALUE,
37+
},
38+
};
39+
40+
export const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = {
41+
schedule: "",
42+
timeZone: options.RESET_VALUE,
43+
retryConfig: {
44+
retryCount: options.RESET_VALUE,
45+
maxRetryDuration: options.RESET_VALUE,
46+
maxBackoffDuration: options.RESET_VALUE,
47+
minBackoffDuration: options.RESET_VALUE,
48+
maxDoublings: options.RESET_VALUE,
49+
},
50+
};

spec/v1/providers/https.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as functions from "../../../src/v1";
2626
import * as https from "../../../src/v1/providers/https";
2727
import { expectedResponseHeaders, MockRequest } from "../../fixtures/mockrequest";
2828
import { runHandler } from "../../helper";
29+
import { MINIMAL_ENDPOINT } from "../../fixtures";
2930

3031
describe("CloudHttpsBuilder", () => {
3132
describe("#onRequest", () => {
@@ -34,6 +35,7 @@ describe("CloudHttpsBuilder", () => {
3435
resp.send(200);
3536
});
3637
expect(result.__endpoint).to.deep.equal({
38+
...MINIMAL_ENDPOINT,
3739
platform: "gcfv1",
3840
httpsTrigger: {},
3941
});
@@ -64,6 +66,7 @@ describe("#onCall", () => {
6466
});
6567

6668
expect(result.__endpoint).to.deep.equal({
69+
...MINIMAL_ENDPOINT,
6770
platform: "gcfv1",
6871
callableTrigger: {},
6972
labels: {},

0 commit comments

Comments
 (0)