-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add method and test * chore: update * refactor: change method
- Loading branch information
1 parent
95d6900
commit 4b3c504
Showing
7 changed files
with
254 additions
and
85 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { test} from "uvu"; | ||
import * as assert from "uvu/assert"; | ||
import fs from "node:fs"; | ||
import { initializeTestEnvironment, RulesTestEnvironment } from '@firebase/rules-unit-testing'; | ||
|
||
import { getAllDocumentsWithCollectionName } from "./firestore"; | ||
import type { Firestore } from "firebase/firestore"; | ||
|
||
// setup the test environment with the Firestore emulator | ||
// before running the tests | ||
let testEnv: RulesTestEnvironment | null = null; | ||
|
||
test.before.each(async() => { | ||
testEnv = await initializeTestEnvironment({ | ||
projectId: "test-project", | ||
firestore: { | ||
rules: fs.readFileSync("/home/yamashita/tegata/firestore.rules", "utf8"), | ||
host: "localhost", | ||
port: 8080 | ||
} | ||
}); | ||
}); | ||
|
||
test.after.each(async() => { | ||
await testEnv?.cleanup(); | ||
}); | ||
|
||
test("getAllDocumentsWithCollectionName", async() => { | ||
const user = testEnv?.authenticatedContext("test-user"); | ||
const firestore = user?.firestore() as unknown as Firestore; | ||
const collectionName = "users"; | ||
if (!firestore) { | ||
throw new Error("Firestore is not initialized"); | ||
} | ||
const result = await getAllDocumentsWithCollectionName(firestore, collectionName); | ||
if (result instanceof Error) { | ||
throw result; | ||
} | ||
assert.is(result.length, 0); | ||
}); | ||
|
||
|
||
test.run(); |
Oops, something went wrong.