-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1512 from firebase/next
March 17 2023 release
- Loading branch information
Showing
57 changed files
with
11,327 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,127 @@ | ||
import { getDatabaseUrl } from "../src/helpers"; | ||
|
||
describe("Test Realtime Database URL helper function", () => { | ||
test("Can return the correct url for us-central-1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "us-central1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.firebaseio.com` | ||
); | ||
}); | ||
import * as admin from "firebase-admin"; | ||
import { UserRecord } from "firebase-functions/v1/auth"; | ||
import setupEnvironment from "./helpers/setupEnvironment"; | ||
|
||
test("Can return the correct url for europe-west1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "europe-west1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.europe-west1.firebasedatabase.app` | ||
); | ||
}); | ||
import { hasValidUserPath, getDatabaseUrl } from "../src/helpers"; | ||
import { createFirebaseUser } from "./helpers"; | ||
|
||
test("Can return the correct url for asia-southeast1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "asia-southeast1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.asia-southeast1.firebasedatabase.app` | ||
); | ||
}); | ||
admin.initializeApp(); | ||
setupEnvironment(); | ||
|
||
const db = admin.firestore(); | ||
const collection = db.collection("hasValidUserPath"); | ||
let user: UserRecord; | ||
|
||
describe("helpers", () => { | ||
describe("Test Realtime Database URL helper function", () => { | ||
test("Can return the correct url for us-central-1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "us-central1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.firebaseio.com` | ||
); | ||
}); | ||
|
||
test("Can return the correct url for europe-west1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "europe-west1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.europe-west1.firebasedatabase.app` | ||
); | ||
}); | ||
|
||
test("Can return the correct url for asia-southeast1", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: "asia-southeast1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe( | ||
`https://${environment.SELECTED_DATABASE_INSTANCE}.asia-southeast1.firebasedatabase.app` | ||
); | ||
}); | ||
|
||
test("Return null if instance is undefined", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: undefined, | ||
SELECTED_DATABASE_LOCATION: "asia-southeast1", | ||
}; | ||
|
||
test("Return null if instance is undefined", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: undefined, | ||
SELECTED_DATABASE_LOCATION: "asia-southeast1", | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe(null); | ||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe(null); | ||
}); | ||
|
||
test("Return null if location is undefined", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: undefined, | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe(null); | ||
}); | ||
}); | ||
|
||
test("Return null if location is undefined", () => { | ||
const environment = { | ||
SELECTED_DATABASE_INSTANCE: "server-name", | ||
SELECTED_DATABASE_LOCATION: undefined, | ||
}; | ||
|
||
const serverUrl = getDatabaseUrl( | ||
environment.SELECTED_DATABASE_INSTANCE, | ||
environment.SELECTED_DATABASE_LOCATION | ||
); | ||
expect(serverUrl).toBe(null); | ||
describe("hasValidUserPath", () => { | ||
DocumentReference: beforeAll(async () => { | ||
/** create a test user */ | ||
user = await createFirebaseUser(); | ||
}); | ||
test("should return true if the path matches a valid string", async () => { | ||
/** create a string example field value */ | ||
const stringDoc = await collection.add({ field1: user.uid }); | ||
|
||
/** get the result */ | ||
const result = await hasValidUserPath(stringDoc, "", user.uid); | ||
|
||
/** check the result */ | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
test("should return true if the path matches a valid string path", async () => { | ||
/** create a string example field value */ | ||
const stringDoc = await collection.add({ field1: `testing/${user.uid}` }); | ||
|
||
/** get the result */ | ||
const result = await hasValidUserPath(stringDoc, "", user.uid); | ||
|
||
/** check the result */ | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
test("should return false if with a non string value", async () => { | ||
/** create a string example field value */ | ||
const stringDoc = await collection.add({ field1: 1234 }); | ||
|
||
/** get the result */ | ||
const result = await hasValidUserPath(stringDoc, "", user.uid); | ||
|
||
/** check the result */ | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
delete-user-data/functions/__tests__/runBatchPubSubDeletions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as admin from "firebase-admin"; | ||
import { runBatchPubSubDeletions } from "../src/runBatchPubSubDeletions"; | ||
import setupEnvironment from "./helpers/setupEnvironment"; | ||
|
||
import { Paths } from "../src/types"; | ||
|
||
admin.initializeApp(); | ||
setupEnvironment(); | ||
|
||
const db = admin.firestore(); | ||
|
||
const generateTopLevelUserCollection = async (name) => { | ||
const collection = db.collection(name); | ||
|
||
return collection; | ||
}; | ||
|
||
describe("runBatchPubSubDeletions", () => { | ||
let rootCollection: admin.firestore.CollectionReference; | ||
|
||
beforeEach(async () => { | ||
rootCollection = await generateTopLevelUserCollection( | ||
"runBatchPubSubDeletions" | ||
); | ||
}); | ||
|
||
test("cannot delete paths with an invalid userId", async () => { | ||
/** Add a new document for testing */ | ||
const doc = await rootCollection.add({ testing: "testing" }); | ||
const invalidUserId = "invalidUserId"; | ||
|
||
const paths: Paths = { firestorePaths: [`${rootCollection.id}/${doc.id}`] }; | ||
|
||
/** Run deletion */ | ||
await runBatchPubSubDeletions(paths, invalidUserId); | ||
|
||
/** Wait 10 seconds */ | ||
await new Promise((resolve) => setTimeout(resolve, 10000)); | ||
|
||
/** Check document still exist */ | ||
const documentCheck = await doc.get(); | ||
expect(documentCheck.exists).toBe(true); | ||
}, 60000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.