Latest commit 67db3ad Oct 24, 2018
Permalink
..
Failed to load latest commit information.
test minor changes Oct 24, 2018
.eslintrc minor changes Oct 24, 2018
.gitignore minor changes Oct 24, 2018
.npmignore minor changes Oct 24, 2018
README.md temp commit Oct 24, 2018
firebase.json added emulator quickstarts Oct 23, 2018
firestore.rules updated with latest sdk version too Oct 24, 2018
package.json temp commit Oct 24, 2018
tsconfig.json minor changes Oct 24, 2018

README.md

Cloud Firestore emulator quickstart

Let's try writing some simple tests for our security rules.

Setup

Install Node dependencies

Run npm install from this directory.

Running the emulator

Make sure you've Opted-in to the emulator beta:

firebase --open-sesame emulators
firebase setup:emulators:firestore

Start the firestore emulator (and leave it running during the tests)

firebase serve --only firestore

Running the tests

To run the tests, execute

npm test

which runs all the tests in the tests/ directory. At the beginning, you should see 5 tests pass and 1 tests fail.

    ✓ require users to log in before creating a profile
    1) should let anyone create their own profile
    ✓ should let anyone read any profile
    ✓ should let anyone create a room
    ✓ should force people to name themselves as room owner when creating a room
    ✓ should not let one user steal a room from another user


  5 passing
  1 failing

Making the tests pass

The tests fail because they expect the rules to block unauthorized writes to a location. To fix this, go to the firestore.rules and uncomment the rule on line 5:

allow write: if request.auth.uid != null;

If we re-run the tests now, they should all pass.

npm test

should give you output like

    ✓ require users to log in before creating a profile
    ✓ should let anyone create their own profile 
    ✓ should let anyone read any profile
    ✓ should let anyone create a room
    ✓ should force people to name themselves as room owner when creating a room
    ✓ should not let one user steal a room from another user


  6 passing