@firebase-function-kits/firestore-bigquery-export 0.0.2-rc.11 → 0.0.2-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Copyright 2026 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { afterEach, beforeAll, describe, expect, test, vi } from "vitest";
18
+ import { declaredParams } from "firebase-functions/params";
19
+
20
+ const REQUIRED = [
21
+ "DATASET_LOCATION",
22
+ "BIGQUERY_PROJECT_ID",
23
+ "DATABASE",
24
+ "COLLECTION_PATH",
25
+ "DATASET_ID",
26
+ "TABLE_ID",
27
+ "VIEW_TYPE",
28
+ "USE_NEW_SNAPSHOT_QUERY_SYNTAX",
29
+ "LOG_LEVEL",
30
+ ];
31
+
32
+ const OPTIONAL = [
33
+ "DATABASE_REGION",
34
+ "BACKUP_COLLECTION",
35
+ "MAX_DISPATCHES_PER_SECOND",
36
+ "MAX_ENQUEUE_ATTEMPTS",
37
+ ];
38
+
39
+ let assertRequiredParams: (names?: ReadonlyArray<string>) => void;
40
+
41
+ beforeAll(async () => {
42
+ // Some kits resolve the instance id at import; the CLI injects it for real
43
+ // instances, so supply one before loading the module under test.
44
+ process.env.FIREBASE_KIT_INSTANCE_ID ??= "test-instance";
45
+ ({ assertRequiredParams } = await import("../src/config"));
46
+ });
47
+
48
+ afterEach(() => {
49
+ vi.unstubAllEnvs();
50
+ });
51
+
52
+ describe("assertRequiredParams", () => {
53
+ test("passes when no params have been supplied yet", () => {
54
+ expect(() => assertRequiredParams()).not.toThrow();
55
+ });
56
+
57
+ test("passes when every required param holds a value", () => {
58
+ for (const name of REQUIRED) {
59
+ vi.stubEnv(name, "set");
60
+ }
61
+
62
+ expect(() => assertRequiredParams()).not.toThrow();
63
+ });
64
+
65
+ test("rejects required params blanked in .env, naming each one", () => {
66
+ for (const name of REQUIRED) {
67
+ vi.stubEnv(name, "");
68
+ }
69
+
70
+ expect(() => assertRequiredParams()).toThrow(REQUIRED.join(", "));
71
+ });
72
+
73
+ test("rejects a whitespace-only value, which the CLI prompt accepts", () => {
74
+ vi.stubEnv(REQUIRED[0], " ");
75
+
76
+ expect(() => assertRequiredParams()).toThrow(REQUIRED[0]);
77
+ });
78
+
79
+ test("ignores optional params left blank", () => {
80
+ for (const name of OPTIONAL) {
81
+ vi.stubEnv(name, "");
82
+ }
83
+
84
+ expect(() => assertRequiredParams()).not.toThrow();
85
+ });
86
+ });
87
+
88
+ type Declaration = {
89
+ name: string;
90
+ options?: {
91
+ default?: unknown;
92
+ input?: {
93
+ text?: { nonEmpty?: boolean; validationRegex?: string | RegExp };
94
+ multiSelect?: { nonEmpty?: boolean };
95
+ };
96
+ };
97
+ };
98
+
99
+ // The CLI writes whatever a prompt resolves to into .env, an empty answer
100
+ // included, so a required param the prompt accepts empty reaches
101
+ // assertRequiredParams as a blank entry the user never typed.
102
+ function promptAcceptsEmpty({ options }: Declaration): boolean {
103
+ const fallback = options?.default;
104
+ if (fallback !== undefined && String(fallback).trim() !== "") {
105
+ return false;
106
+ }
107
+
108
+ const input = options?.input;
109
+ if (!input) {
110
+ return true;
111
+ }
112
+ if (input.multiSelect) {
113
+ return input.multiSelect.nonEmpty !== true;
114
+ }
115
+ if (!input.text) {
116
+ return false;
117
+ }
118
+ if (input.text.nonEmpty) {
119
+ return false;
120
+ }
121
+ if (input.text.validationRegex) {
122
+ return new RegExp(input.text.validationRegex).test("");
123
+ }
124
+ return true;
125
+ }
126
+
127
+ describe("required param declarations", () => {
128
+ test("the CLI prompt cannot resolve any of them to an empty value", () => {
129
+ const declarations = declaredParams as unknown as Declaration[];
130
+
131
+ for (const name of REQUIRED) {
132
+ const declaration = declarations.find((param) => param.name === name);
133
+
134
+ expect(declaration, name).toBeDefined();
135
+ expect(promptAcceptsEmpty(declaration as Declaration), name).toBe(false);
136
+ }
137
+ });
138
+ });