Repository navigation
Expand file tree
/
Copy pathexport-config.test.ts
More file actions
114 lines (100 loc) · 3.92 KB
/
Copy pathexport-config.test.ts
File metadata and controls
114 lines (100 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, expect, test } from "vitest";
import {
getDatabaseUrl,
resolveDeleteUserDataConfig,
} from "../src/export-config";
// Parity: delete-user-data/functions/__tests__/helpers.test.ts
// ("Test Realtime Database URL helper function"). The helper moved from
// `helpers.ts` to `export-config.ts` in the kit; the cases are unchanged.
describe("getDatabaseUrl", () => {
test("returns the correct url for us-central1", () => {
expect(getDatabaseUrl("server-name", "us-central1")).toBe(
"https://server-name.firebaseio.com"
);
});
test("returns the correct url for europe-west1", () => {
expect(getDatabaseUrl("server-name", "europe-west1")).toBe(
"https://server-name.europe-west1.firebasedatabase.app"
);
});
test("returns the correct url for asia-southeast1", () => {
expect(getDatabaseUrl("server-name", "asia-southeast1")).toBe(
"https://server-name.asia-southeast1.firebasedatabase.app"
);
});
test("returns null if the instance is undefined", () => {
expect(getDatabaseUrl(undefined, "asia-southeast1")).toBe(null);
});
test("returns null if the location is undefined", () => {
expect(getDatabaseUrl("server-name", undefined)).toBe(null);
});
});
describe("resolveDeleteUserDataConfig", () => {
test("applies the extension.yaml defaults", () => {
const config = resolveDeleteUserDataConfig({ instanceId: "my-instance" });
expect(config.firestoreDatabaseId).toBe("(default)");
expect(config.firestoreDeleteMode).toBe("shallow");
expect(config.enableAutoDiscovery).toBe(false);
expect(config.searchDepth).toBe(3);
expect(config.searchFields).toBe("id,uid,userId");
});
// The extension skips RTDB paths when the location is blank, rather than
// assuming us-central1, so a blank location must stay unset.
test("leaves a blank RTDB location unset", () => {
const config = resolveDeleteUserDataConfig({ instanceId: "my-instance" });
expect(config.rtdbLocation).toBeUndefined();
});
test("derives topic names from the instance id", () => {
const config = resolveDeleteUserDataConfig({ instanceId: "my-instance" });
expect(config.discoveryTopicName).toBe("kit-my-instance-discovery");
expect(config.deletionTopicName).toBe("kit-my-instance-deletion");
});
test("passes through the supplied values", () => {
const config = resolveDeleteUserDataConfig({
instanceId: "my-instance",
firestorePaths: "users/{UID}",
firestoreDatabaseId: "secondary",
firestoreDeleteMode: "recursive",
rtdbInstance: "server-name",
rtdbLocation: "europe-west1",
rtdbPaths: "users/{UID}",
storageBucket: "my-bucket",
storagePaths: "{DEFAULT}/{UID}",
enableAutoDiscovery: true,
searchDepth: 5,
searchFields: "uid",
searchFunction: "https://example.com/search",
projectId: "demo-test",
});
expect(config).toMatchObject({
firestorePaths: "users/{UID}",
firestoreDatabaseId: "secondary",
firestoreDeleteMode: "recursive",
rtdbInstance: "server-name",
rtdbLocation: "europe-west1",
rtdbPaths: "users/{UID}",
storageBucket: "my-bucket",
storagePaths: "{DEFAULT}/{UID}",
enableAutoDiscovery: true,
searchDepth: 5,
searchFields: "uid",
searchFunction: "https://example.com/search",
projectId: "demo-test",
});
});
});