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
- select database
- select project name that you created
- select default for other options
- Go to "Project Setting" on firebase console.
- Select "SERVICE ACCOUNTS" tab
- Click on "GENERATE NEW PRIVATE KEY" at the bottom
- It will download a creds json file
- Copy that file to root folder of your project and rename it as 'firebase-admin.json'
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'
...
...
Welcome to contribute