Framework

Seed an Angular + Firebase App with MockHero

Script

// scripts/seed.mjs
import { initializeApp, cert } from "firebase-admin/app";
import { getFirestore } from "firebase-admin/firestore";

initializeApp({ credential: cert("./service-account.json") });
const db = getFirestore();

const data = await fetch("https://api.mockhero.dev/api/v1/generate", {
  method: "POST",
  headers: { "x-api-key": process.env.MOCKHERO_API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    tables: [
      { name: "organizations", count: 10, fields: [
        { name: "id", type: "uuid" },
        { name: "name", type: "company_name" }
      ]},
      { name: "members", count: 80, fields: [
        { name: "id", type: "uuid" },
        { name: "orgId", type: "ref", ref: "organizations.id" },
        { name: "email", type: "email" }
      ]}
    ]
  })
}).then(r => r.json());

const batch = db.batch();
for (const o of data.organizations) batch.set(db.collection("orgs").doc(o.id), o);
for (const m of data.members) batch.set(db.collection("members").doc(m.id), m);
await batch.commit();

Get Started

Get a free API key.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles