From 56d822c57e07fddb09a3bc8bad63a437ff582ba8 Mon Sep 17 00:00:00 2001
From: Adam Sever <avacadoadam@gmail.com>
Date: Sat, 28 Mar 2020 14:39:23 +0000
Subject: [PATCH] Added admin database and used it to create mock data while
 returning the test Database

---
 README.md       | 5 +++++
 spec/helpers.js | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a126e06..dfac116 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,8 @@
 # Episode 147 - Testing Firestore Rules with the Emulator
 
 Learn how to test your Firebase security rules using the new Cloud Firestore emulator.
+
+
+### changelog
+Fixing permission errors when adding mock data to firestore 
+as seen in https://github.com/AngularFirebase/147-firestore-emulator-rules-testing/issues/1
diff --git a/spec/helpers.js b/spec/helpers.js
index 8ee85f0..62787eb 100644
--- a/spec/helpers.js
+++ b/spec/helpers.js
@@ -9,11 +9,12 @@ module.exports.setup = async (auth, data) => {
   });
 
   const db = app.firestore();
+  const dbAdmin = firebase.initializeAdminApp({projectId}).firestore();
 
   // Write mock documents before rules
   if (data) {
     for (const key in data) {
-      const ref = db.doc(key);
+      const ref = dbAdmin.doc(key);
       await ref.set(data[key]);
     }
   }