Unit tests for Firebase
Demonstrate how to perform automated unit tests against database and rules
https://yarnpkg.com/en/docs/install
yarn global add firebase-tools
git clone https://github.com/zirho/firebase-test
cd firebase-test
yarn install
Skip this if you already have a project setup and initiated
Go to https://console.firebase.google.com/project/
Create a new project
Update firebase.config.js with what your project gave you
vi src/firebase.config.js
It should look something like this
export default {
apiKey: 'your-app-key',
authDomain: 'your-app-domain.firebaseapp.io',
databaseURL: 'https://your-firebase-database-url.firebaseio.com',
}
firebase login
firebase init
Follow the instructions
For Mac user
cp ~/Downloads/[downloaded file name].json ./firebase-admin.json
Update ./database.rules.json
as you needed
And deploy it
firebase deploy --only database
yarn test-once
yarn test
Pick a UID from firebase console > Authentication > USERS
Put the UID to the test
vi src/auth.test.js
describe('Authenticated firebase', () => {
let authedFirebase
const UID = 'vl7GjxgIRre1sD0ftesttesttesttest'
...
...
/user/joshua
availableWelcome to contribute