Flutter 앱 골격 · 5탭 네비게이션 · 로그인 화면 · Firestore 보안 규칙·인덱스
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { initializeTestEnvironment } from '@firebase/rules-unit-testing';
|
||||
import { doc, setDoc } from 'firebase/firestore';
|
||||
|
||||
export const projectId = process.env.GCLOUD_PROJECT ?? 'demo-fancake';
|
||||
|
||||
function emulatorAddress() {
|
||||
const value = process.env.FIRESTORE_EMULATOR_HOST ?? '127.0.0.1:8080';
|
||||
const separator = value.lastIndexOf(':');
|
||||
|
||||
if (separator < 1) {
|
||||
throw new Error(`Invalid FIRESTORE_EMULATOR_HOST: ${value}`);
|
||||
}
|
||||
|
||||
const host = value.slice(0, separator);
|
||||
const port = Number(value.slice(separator + 1));
|
||||
|
||||
if (!Number.isInteger(port)) {
|
||||
throw new Error(`Invalid Firestore emulator port: ${value}`);
|
||||
}
|
||||
|
||||
return { host, port };
|
||||
}
|
||||
|
||||
export async function createTestEnvironment() {
|
||||
const rules = readFileSync(new URL('../../firestore.rules', import.meta.url), 'utf8');
|
||||
|
||||
return initializeTestEnvironment({
|
||||
projectId,
|
||||
firestore: {
|
||||
...emulatorAddress(),
|
||||
rules,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function seedDocuments(testEnvironment, documents) {
|
||||
await testEnvironment.withSecurityRulesDisabled(async (context) => {
|
||||
const firestore = context.firestore();
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(documents).map(([path, data]) => setDoc(doc(firestore, path), data)),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function userDocument(uid, overrides = {}) {
|
||||
return {
|
||||
uid,
|
||||
displayName: uid,
|
||||
fandomId: 'fandom-a',
|
||||
grade: 'SILVER',
|
||||
totalContributedPop: 0,
|
||||
status: 'active',
|
||||
updatedAt: '2026-08-08T00:00:00Z',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user