Skip to content

Commit

Permalink
feat: add method and test (#11)
Browse files Browse the repository at this point in the history
* feat: add method and test

* chore: update

* refactor: change method
  • Loading branch information
yamashita-kenngo authored May 26, 2024
1 parent 95d6900 commit 4b3c504
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 85 deletions.
204 changes: 153 additions & 51 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.23.7",
"@firebase/rules-unit-testing": "^3.0.2",
"@solidjs/testing-library": "^0.8.7",
"autoprefixer": "^10.4.19",
"babel-preset-solid": "^1.8.9",
Expand Down
43 changes: 43 additions & 0 deletions app/src/service/firestore.test.ts
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();
Loading

0 comments on commit 4b3c504

Please sign in to comment.