Skip to content

Instantly share code, notes, and snippets.

@pocha
Created January 1, 2023 23:12
Show Gist options
  • Save pocha/cd13f511180d12844b6cb93b3f74681e to your computer and use it in GitHub Desktop.
Save pocha/cd13f511180d12844b6cb93b3f74681e to your computer and use it in GitHub Desktop.
import { initializeTestEnvironment } from "@firebase/rules-unit-testing"
import { setLogLevel } from "firebase/firestore"
const FIREBASE_PROJECT_ID = "xxxx"
export const USER_COLLECTION = "users-main"
export const APPLICATION_COLLECTION = "applications"
export const ASHISH_ID = "xxxx"
export const BETTS_ID = "xxxx"
export const ZUKA_ID = "xxxx"
let rulesTestEnv
export const initialize_firestore_db = async () => {
if (!rulesTestEnv) {
setLogLevel("silent") // hiding logs that show up when writes fail
rulesTestEnv = await initializeTestEnvironment({
projectId: FIREBASE_PROJECT_ID,
firestore: {
host: "localhost",
port: 8080,
},
})
}
}
export const get_fresh_collection_ref = (uid, collection) => {
if (!uid) return rulesTestEnv.unauthenticatedContext().firestore().collection(collection)
return rulesTestEnv.authenticatedContext(uid).firestore().collection(collection)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment