26 lines
890 B
TypeScript
26 lines
890 B
TypeScript
import { initializeApp, deleteApp, getApps, type App } from 'firebase-admin/app';
|
|
import { getFirestore } from 'firebase-admin/firestore';
|
|
|
|
/**
|
|
* 에뮬레이터 전용 테스트 환경.
|
|
*
|
|
* `FIRESTORE_EMULATOR_HOST` 가 없으면 **실 프로젝트로 붙을 위험**이 있으므로
|
|
* 바로 실패시킨다. 테스트가 운영 데이터를 건드리는 사고는 한 번이면 치명적이다.
|
|
*/
|
|
export const PROJECT_ID = 'demo-fanuzu';
|
|
|
|
export function bootAdmin(): App {
|
|
if (!process.env.FIRESTORE_EMULATOR_HOST) {
|
|
throw new Error(
|
|
'FIRESTORE_EMULATOR_HOST 가 없습니다. `npm run test:emulator` 로 실행하십시오.',
|
|
);
|
|
}
|
|
const existing = getApps()[0];
|
|
if (existing) return existing;
|
|
return initializeApp({ projectId: PROJECT_ID });
|
|
}
|
|
|
|
export async function shutdownAdmin(): Promise<void> {
|
|
for (const app of getApps()) await deleteApp(app);
|
|
}
|