Skip to content

Commit c50da50

Browse files
author
Izaak Gough
committed
tests: update tests
1 parent aac55eb commit c50da50

6 files changed

Lines changed: 47 additions & 33 deletions

File tree

spec/v2/options.spec.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,30 @@ describe("assertTimeoutSecondsValid", () => {
115115
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 540 }, "event")).to.not.throw();
116116
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 3600 }, "https")).to.not.throw();
117117
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 1800 }, "task")).to.not.throw();
118-
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 0 }, "event")).to.not.throw();
118+
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 1 }, "event")).to.not.throw();
119119
});
120120

121121
it("throws when timeoutSeconds exceeds the event-handler limit", () => {
122122
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 3600 }, "event")).to.throw(
123-
/between 0 and 540 for event-handling functions/
123+
/between 1 and 540 for event-handling functions/
124124
);
125125
});
126126

127127
it("throws when timeoutSeconds exceeds the HTTPS limit", () => {
128128
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 3601 }, "https")).to.throw(
129-
/between 0 and 3600 for HTTPS and callable functions/
129+
/between 1 and 3600 for HTTPS and callable functions/
130130
);
131131
});
132132

133133
it("throws when timeoutSeconds exceeds the task-queue limit", () => {
134134
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 1801 }, "task")).to.throw(
135-
/between 0 and 1800 for task queue functions/
135+
/between 1 and 1800 for task queue functions/
136136
);
137137
});
138138

139139
it("throws when timeoutSeconds is negative", () => {
140140
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: -1 }, "event")).to.throw(
141-
/between 0 and 540/
141+
/between 1 and 540/
142142
);
143143
});
144144

@@ -152,18 +152,32 @@ describe("assertTimeoutSecondsValid", () => {
152152
expect(() => assertTimeoutSecondsValid(opts, "event")).to.not.throw();
153153
});
154154

155+
it("throws when timeoutSeconds has an invalid non-number type", () => {
156+
const opts = { timeoutSeconds: "30" as unknown as number };
157+
expect(() => assertTimeoutSecondsValid(opts, "event")).to.throw(
158+
/must be a number, Expression, or RESET_VALUE/
159+
);
160+
});
161+
162+
it("throws when global timeoutSeconds has an invalid non-number type", () => {
163+
setGlobalOptions({ timeoutSeconds: true as unknown as number });
164+
expect(() => assertTimeoutSecondsValid({}, "event")).to.throw(
165+
/must be a number, Expression, or RESET_VALUE/
166+
);
167+
});
168+
155169
it("falls back to the global timeoutSeconds when the function-level option is absent", () => {
156170
setGlobalOptions({ timeoutSeconds: 3600 });
157171
expect(() => assertTimeoutSecondsValid({}, "event")).to.throw(
158-
/between 0 and 540 for event-handling functions/
172+
/between 1 and 540 for event-handling functions/
159173
);
160174
expect(() => assertTimeoutSecondsValid({}, "https")).to.not.throw();
161175
});
162176

163177
it("prefers the function-level timeoutSeconds over the global one", () => {
164178
setGlobalOptions({ timeoutSeconds: 60 });
165179
expect(() => assertTimeoutSecondsValid({ timeoutSeconds: 1000 }, "event")).to.throw(
166-
/between 0 and 540/
180+
/between 1 and 540/
167181
);
168182
});
169183

@@ -186,13 +200,13 @@ describe("optionsToEndpoint timeout validation", () => {
186200

187201
it("throws when kind is provided and timeoutSeconds exceeds the limit", () => {
188202
expect(() => optionsToEndpoint({ timeoutSeconds: 3600 }, "event")).to.throw(
189-
/between 0 and 540/
203+
/between 1 and 540/
190204
);
191205
expect(() => optionsToEndpoint({ timeoutSeconds: 3601 }, "https")).to.throw(
192-
/between 0 and 3600/
206+
/between 1 and 3600/
193207
);
194208
expect(() => optionsToEndpoint({ timeoutSeconds: 1801 }, "task")).to.throw(
195-
/between 0 and 1800/
209+
/between 1 and 1800/
196210
);
197211
});
198212

@@ -214,13 +228,13 @@ describe("optionsToTriggerAnnotations timeout validation", () => {
214228

215229
it("throws when kind is provided and timeoutSeconds exceeds the limit", () => {
216230
expect(() => optionsToTriggerAnnotations({ timeoutSeconds: 3600 }, "event")).to.throw(
217-
/between 0 and 540/
231+
/between 1 and 540/
218232
);
219233
expect(() => optionsToTriggerAnnotations({ timeoutSeconds: 3601 }, "https")).to.throw(
220-
/between 0 and 3600/
234+
/between 1 and 3600/
221235
);
222236
expect(() => optionsToTriggerAnnotations({ timeoutSeconds: 1801 }, "task")).to.throw(
223-
/between 0 and 1800/
237+
/between 1 and 1800/
224238
);
225239
});
226240

spec/v2/providers/https.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ describe("onRequest", () => {
342342
https.onRequest({ timeoutSeconds: 3601 }, (_req, res) => {
343343
res.end();
344344
})
345-
).to.throw(/between 0 and 3600 for HTTPS and callable functions/);
345+
).to.throw(/between 1 and 3600 for HTTPS and callable functions/);
346346
});
347347
});
348348

@@ -615,7 +615,7 @@ describe("onCall", () => {
615615

616616
it("rejects timeoutSeconds above the 3600s HTTPS limit", () => {
617617
expect(() => https.onCall({ timeoutSeconds: 3601 }, () => 42)).to.throw(
618-
/between 0 and 3600 for HTTPS and callable functions/
618+
/between 1 and 3600 for HTTPS and callable functions/
619619
);
620620
});
621621

spec/v2/providers/pubsub.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ describe("onMessagePublished", () => {
137137
it("rejects timeoutSeconds above the 540s event-handler limit", () => {
138138
expect(() =>
139139
pubsub.onMessagePublished({ topic: "topic", timeoutSeconds: 3600 }, () => 42)
140-
).to.throw(/between 0 and 540 for event-handling functions/);
140+
).to.throw(/between 1 and 540 for event-handling functions/);
141141
});
142142

143143
it("rejects a global timeoutSeconds above the 540s event-handler limit", () => {
144144
options.setGlobalOptions({ timeoutSeconds: 3600 });
145145
expect(() => pubsub.onMessagePublished("topic", () => 42)).to.throw(
146-
/between 0 and 540 for event-handling functions/
146+
/between 1 and 540 for event-handling functions/
147147
);
148148
});
149149

spec/v2/providers/storage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ describe("v2/storage", () => {
509509
{ bucket: "my-bucket", timeoutSeconds: 3600 },
510510
() => 42
511511
);
512-
expect(() => func.__endpoint).to.throw(/between 0 and 540 for event-handling functions/);
512+
expect(() => func.__endpoint).to.throw(/between 1 and 540 for event-handling functions/);
513513
});
514514
});
515515

spec/v2/providers/tasks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ describe("onTaskDispatched", () => {
326326

327327
it("rejects timeoutSeconds above the 1800s task-queue limit", () => {
328328
expect(() => onTaskDispatched({ timeoutSeconds: 1801 }, () => null)).to.throw(
329-
/between 0 and 1800 for task queue functions/
329+
/between 1 and 1800 for task queue functions/
330330
);
331331
});
332332

spec/v2/providers/timeout.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,38 @@ describe("v2 provider timeout validation", () => {
4747
https.onRequest({ timeoutSeconds: 3601 }, (_req, res) => {
4848
res.end();
4949
}),
50-
expectedError: /between 0 and 3600 for HTTPS and callable functions/,
50+
expectedError: /between 1 and 3600 for HTTPS and callable functions/,
5151
},
5252
{
5353
name: "https.onCall rejects HTTPS timeouts above 3600s",
5454
build: () => https.onCall({ timeoutSeconds: 3601 }, () => 42),
55-
expectedError: /between 0 and 3600 for HTTPS and callable functions/,
55+
expectedError: /between 1 and 3600 for HTTPS and callable functions/,
5656
},
5757
{
5858
name: "ai.beforeGenerateContent rejects HTTPS timeouts above 3600s",
5959
build: () => ai.beforeGenerateContent({ timeoutSeconds: 3601 }, () => ({})),
60-
expectedError: /between 0 and 3600 for HTTPS and callable functions/,
60+
expectedError: /between 1 and 3600 for HTTPS and callable functions/,
6161
},
6262
{
6363
name: "identity.beforeUserCreated rejects HTTPS timeouts above 3600s",
6464
build: () => identity.beforeUserCreated({ timeoutSeconds: 3601 }, () => undefined),
65-
expectedError: /between 0 and 3600 for HTTPS and callable functions/,
65+
expectedError: /between 1 and 3600 for HTTPS and callable functions/,
6666
},
6767
{
6868
name: "tasks.onTaskDispatched rejects task timeouts above 1800s",
6969
build: () => tasks.onTaskDispatched({ timeoutSeconds: 1801 }, () => null),
70-
expectedError: /between 0 and 1800 for task queue functions/,
70+
expectedError: /between 1 and 1800 for task queue functions/,
7171
},
7272
{
7373
name: "pubsub.onMessagePublished rejects event timeouts above 540s",
7474
build: () => pubsub.onMessagePublished({ topic: "topic", timeoutSeconds: 3600 }, () => 42),
75-
expectedError: /between 0 and 540 for event-handling functions/,
75+
expectedError: /between 1 and 540 for event-handling functions/,
7676
},
7777
{
7878
name: "storage.onObjectFinalized rejects event timeouts above 540s",
7979
build: () =>
8080
storage.onObjectFinalized({ bucket: "bucket", timeoutSeconds: 3600 }, () => null),
81-
expectedError: /between 0 and 540 for event-handling functions/,
81+
expectedError: /between 1 and 540 for event-handling functions/,
8282
validateOnEndpointAccess: true,
8383
},
8484
{
@@ -89,13 +89,13 @@ describe("v2 provider timeout validation", () => {
8989
() => null
9090
);
9191
},
92-
expectedError: /between 0 and 540 for event-handling functions/,
92+
expectedError: /between 1 and 540 for event-handling functions/,
9393
},
9494
{
9595
name: "firestore.onDocumentCreated rejects event timeouts above 540s",
9696
build: () =>
9797
firestore.onDocumentCreated({ document: "foo/{bar}", timeoutSeconds: 3600 }, () => null),
98-
expectedError: /between 0 and 540 for event-handling functions/,
98+
expectedError: /between 1 and 540 for event-handling functions/,
9999
},
100100
{
101101
name: "eventarc.onCustomEventPublished rejects event timeouts above 540s",
@@ -104,23 +104,23 @@ describe("v2 provider timeout validation", () => {
104104
{ eventType: "event-type", timeoutSeconds: 3600 },
105105
() => 42
106106
),
107-
expectedError: /between 0 and 540 for event-handling functions/,
107+
expectedError: /between 1 and 540 for event-handling functions/,
108108
},
109109
{
110110
name: "remoteConfig.onConfigUpdated rejects event timeouts above 540s",
111111
build: () => remoteConfig.onConfigUpdated({ timeoutSeconds: 3600 }, () => 42),
112-
expectedError: /between 0 and 540 for event-handling functions/,
112+
expectedError: /between 1 and 540 for event-handling functions/,
113113
},
114114
{
115115
name: "scheduler.onSchedule rejects event timeouts above 540s",
116116
build: () =>
117117
scheduler.onSchedule({ schedule: "* * * * *", timeoutSeconds: 3600 }, () => null),
118-
expectedError: /between 0 and 540 for event-handling functions/,
118+
expectedError: /between 1 and 540 for event-handling functions/,
119119
},
120120
{
121121
name: "testLab.onTestMatrixCompleted rejects event timeouts above 540s",
122122
build: () => testLab.onTestMatrixCompleted({ timeoutSeconds: 3600 }, () => 42),
123-
expectedError: /between 0 and 540 for event-handling functions/,
123+
expectedError: /between 1 and 540 for event-handling functions/,
124124
},
125125
{
126126
name: "dataconnect.onMutationExecuted rejects event timeouts above 540s",
@@ -134,7 +134,7 @@ describe("v2 provider timeout validation", () => {
134134
},
135135
() => true
136136
),
137-
expectedError: /between 0 and 540 for event-handling functions/,
137+
expectedError: /between 1 and 540 for event-handling functions/,
138138
},
139139
];
140140

0 commit comments

Comments
 (0)