Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kits/delete-user-data/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { DocumentReference } from "firebase-admin/firestore";
import { FieldPath } from "firebase-admin/firestore";
import chunk from "lodash.chunk";
import * as events from "./events";
import { getDatabaseUrl } from "./export-config";
import { extractUserPaths, hasValidUserPath } from "./helpers";
import * as logs from "./logs";
import { recursiveDelete } from "./recursiveDelete";
Expand Down Expand Up @@ -156,7 +157,10 @@ export async function handleClear(
} else {
logs.firestoreNotConfigured();
}
if (ctx.config.rtdbPaths) {
if (
ctx.config.rtdbPaths &&
getDatabaseUrl(ctx.config.rtdbInstance, ctx.config.rtdbLocation)
) {
promises.push(clearDatabaseData(ctx.config.rtdbPaths, uid, ctx));
} else {
logs.rtdbNotConfigured();
Expand Down
23 changes: 21 additions & 2 deletions kits/delete-user-data/tests/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ describe("handleClear", () => {

test("deletes the configured rtdb paths", async () => {
const ctx = makeContext({
config: { rtdbPaths: "users/{UID},admins/{UID}" },
config: {
rtdbPaths: "users/{UID},admins/{UID}",
rtdbInstance: "test-rtdb-instance",
rtdbLocation: "us-central1",
},
});

await handleClear(UID, ctx);
Expand All @@ -418,6 +422,17 @@ describe("handleClear", () => {
});
});

test("skips rtdb deletion when no database instance is configured", async () => {
const ctx = makeContext({
config: { rtdbPaths: "users/{UID}" },
});

await handleClear(UID, ctx);

expect(ctx.rtdbRemovals).toEqual([]);
expect(log.rtdbNotConfigured).toHaveBeenCalled();
});

test("deletes the configured storage paths", async () => {
const ctx = makeContext({
config: {
Expand Down Expand Up @@ -463,7 +478,11 @@ describe("handleClear", () => {
test("logs rtdb errors without failing", async () => {
const error = new Error("boom");
const ctx = makeContext({
config: { rtdbPaths: "users/{UID}" },
config: {
rtdbPaths: "users/{UID}",
rtdbInstance: "test-rtdb-instance",
rtdbLocation: "us-central1",
},
rtdbError: error,
});

Expand Down
Loading