Testing Docs
It would be great to have an overview of how to get tests running for your own rules.
I keep getting stuck at ReferenceError: suite is not defined
+1
Sorry about the sparse documentation - the testing framework IS used in the test suite for the Bolt compiler, but I haven't yet written docs for how you use it in your own project. In the meantime - here are some rough notes that can get you started (hopefully):
Since my use of the rules engine is WITHIN the Bolt package - your use of it from the outside will be a little different. But here are the basic steps:
$ npm install mocha chai
- Create a test file (e.g. rules-test.js)
- In the test file:
var bolt = require('firebase-bolt');
var rulesSuite = bolt.rulesSuite;
rulesSuite("My Test", function(test) {
test.database(<your app sandbox-name>, <your server secret>);
test.rules(<path-to-your-bolt-rules-file>);
...<your tests here>...
});
See this file for a sample of how to write a test:
https://github.com/firebase/bolt/blob/master/src/test/mail-test.ts
Use mocha to run your test.
Note that the test with DELETE ALL THE DATA IN YOUR FIREBASE APP - so please only use an app name you want to use as a "sandbox" version of your database - not your REAL ONE!
@aputinski you have to launch mocha with --ui tdd in order to have the suite function injected into the tests.
there must be a firebase-bolt rules testing framework for testing bolt rules for project
In my rules I do not allow anyone to write the user data, I do it through a node application which has server secret token. How do I write using the admin/utimate access using the test framework?
Got it, .as('admin') is letting me write anywhere without regard to rules.
Yes @ziaukhan !
@mckoss sorry to disturb you again, but what if I want to simulate a unauthenticated user what should I put in as() function? If I am leaving it out it is using the last as(). Thanks
Special user names are:
.as('anon') - The anonymous (not-signed-in) user.
.as('admin') - A full-access user (rules don't apply so you can write anything as this user.
I am struggling to find
The test library was written for the Firebase 2.X version - I have not updated it yet for Firebase 3.X. The tools/configure-project script will prompt you to get a server secret from the console and it will write it to a local file.
Thanks. Makes sense. Any estimates when it will be updated for Firebase 3.X? Also is this library the best way to test rules for Firebase 3.X? I am after best practices on how I should write tests (Node.js + Firebase Server SDK + Mocha & Chai)? Any hints will be greatly appreciated.
Hi everyone, unfortunately this project looks pretty dead, which is too bad because Bolt is incredible.
Should I be using Targaryan, the method laid out here, or something else in 2018?