对子集合进行单元测试Firestore安全规则

时间:2020-10-04 20:37:04

标签: firebase google-cloud-firestore firebase-security

我想将一些数据组织为一个子集合,以使直接访问该子集合更为简单。但是,我无法添加与这些子集合相关的,有用的,以安全规则为中心的单元测试。

我正在使用firebase / tesitng软件包。

const getAdminFirestore = () => {
    return firebase.initializeAdminApp({ projectId: PROJECT_ID }).firestore();
  };

  const myUser = {
    id: "user_abc",
    name: 'joseph'
  };

  const myDocument = {
      id: "doc_abc",
      text: "some very interesting information"
  }

  describe("An authenticated user", async () => {
    const myAuth = { uid: "user_abc", email: "abc@gmail.com" };

    it("Can read their document", async () => {
        await setup();
        const db = getFirestore(myAuth);

        const testDoc = db
            .collection(`users/${myUser.id}/documents`)
            .doc(myDocument.id);

        await firebase.assertSucceeds(testDoc.get());
    });
  });

此特定测试继续抛出FirebaseError: false for 'get' @ L88, Null value error. for 'get' @ L125

我已经在本地打开规则,并继续遇到相同的错误,这使我认为我的设置无效。我应该为子测试Firestore安全规则设置子集合数据吗?

0 个答案:

没有答案