Giter Club home page Giter Club logo

expect-firestore's People

Contributors

samtstern avatar samypesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

expect-firestore's Issues

Test for listing collection

The module should have methods: database.canList(auth, collection) and database.cannotList(auth, collection)

Data without subcollections causes 'Maximum call stack size exceeded'

If I use the following data everything works fine:

const mockData = {
  stories: [
    {
      key: 'story1',
      fields: {
        name: 'Story 1',
        'roles.user123': 'owner'
      },
      collections: {} // Note
    }
  ]
};

But I make this change:

const mockData = {
  stories: [
    {
      key: 'story1',
      fields: {
        name: 'Story 1',
        'roles.user123': 'owner'
      }
    }
  ]
};

I get this error:

RangeError: Maximum call stack size exceeded
    at assertPath (path.js:5:20)
    at Object.join (path.js:1211:7)
    at /usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/database.js:102:50
    at Array.reduce (native)
    at /usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/database.js:101:56
    at Array.reduce (native)
    at Database.getDocuments (/usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/database.js:98:45)
    at /usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/database.js:103:42
    at Array.reduce (native)
    at /usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/database.js:101:56

If I dive into the call stack and go to expect-firestore/lib/database.js:102:50:

101               var docs = collections[collectionName].reduce(function (_docs, doc) {
102                   var docPath = _path2.default.join(collectionPath, doc.key);
103                    var children = _this.getDocuments(doc.collections, docPath);
104
105                    return [{
106                        path: docPath,
107                        doc: doc
108                    }].concat(_docs).concat(children);
109                }, []);

request.resource should be "hydrated" for update requests

Right now we send requests that look likes this for an update:

"testSuite": {
      "testCases": [
        {
          "expectation": "ALLOW",
          "request": {
            "auth": {
              "uid": "writeruser"
            },
            "path": "/databases/(default)/documents/stories/story1",
            "method": "update",
            "resource": {
              "data": {
                "content": "Something new!"
              }
            }
          },
          "resource": {
            "data": {
              "title": "Story 1",
              "content": "Something new!",
              "roles": {
                "owneruser": "owner",
                "writeruser": "writer",
                "readeruser": "reader"
              }
            }
          },

In Firestore rules, request.resource should reflect the complete state of resource with the current request applied.

It seems in this case, the update change is being made to resource and not request.resource which is not correct.

API to test batched writes

This module is missing an API to test batched writes.

await database.canCommit([
   firebase.Batch.set('users/userA', { .. }),
   firebase.Batch.delete('users/userA')
])

The goal is to have an API that match the firestore naming as much as possible:

  • batch.commit -> database.canCommit(batch: Array<firestore.Batch.Operation>)
  • batch.set -> firestore.Batch.set(path: string, value: any)
  • batch.delete -> firestore.Batch.delete(path: string)
  • batch.update -> firestore.Batch.update(path: string, data: Object)

The main blocker is that the Firestore rules API doesn't seem to support batch updates. Can you confirm @samtstern ?

ReferenceError: regeneratorRuntime is not defined

Trying to use this module, I get the error (sanitized output):

[...]/expect-firestore/lib/database.js:171
 var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {

ReferenceError: regeneratorRuntime is not defined

As far as I know, simply changing the babel config would fix it (transform-runtime plugin I think).

Edit did not saw #1

Wrong method types for operations

Right now the library has this mapping:

  • Create --> post
  • Update --> patch
  • Read --> get

The methods should actually be the same ones that are in the rules after the allow keyword. So for Firestore those are create, update, delete, get, list, read, and write (where read and write are combinations of some of the more granular ones).

Actually expose setData() and setRules() on the database type

As far as I am aware, the functions in the README do not exist.

Instead I had to hack up my own version:

function clearMockData(database: any) {
  // TODO: should not have to call both .data and .collections
  database.data = undefined;
  database.collections = undefined;
  database.rules = undefined;
}

function setMockDataAndRules(database: any, data: any, rulesFile: string) {
  database.data = data;
  database.collections = data;
  database.rules = getRulesFile(rulesFile);
}

Test for deleting

You can test deleting using batch operations, but it would be nice if there was canDelete and cannotDelete, too.

FR: Return debugging information from failures

When access fails I'd love to get more than false. Would be good to get the full API response so that I can find unexpected errors or make sure that the error is of the kind I expected.

ReferenceError: regeneratorRuntime is not defined

I work on Firebase and I wanted to add your awesome library to our firebase/snippets-rules github repository. I am running into a strange error, hoping you can help (I'm not a JavaScript expert at all so excuse me if this is totally user error).

I am trying out this library and decided to run a basic test:

import * as expectFirestore from 'expect-firestore';

const database = expectFirestore.Database({
  credential: {},
  data: {},
  rules: ''
});

// Note: doesn't matter if this function is async or not, or if I await the promises or not
async function main() {
  database.authorize();

  // Test a get
  database.canGet({ uid: 'some-user' }, 'users/userA');
}

main();

When I run it, this errors:

$ ts-node test/index.ts

/usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/global.js:37
}();
 ^
ReferenceError: regeneratorRuntime is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.