23. Test your rules!
Targaryen is a former Great House of Westeros and
was the ruling royal House of the Seven Kingdoms
for three centuries, before it was deposed during
Robert's Rebellion and House Baratheon replaced it
as the new royal House. The few surviving
Targaryens fled into exile. Currently based in Essos,
House Targaryen seeks to retake the Seven
Kingdoms from House Lannister, who formally
replaced House Baratheon as the royal House
following the destruction of the Great Sept of Baelor.
http://gameofthrones.wikia.com/wiki/House_Targaryen
24. Test your rules!
targaryen = require 'targaryen'
rules = require 'rules.json'
describe 'Destinations', ->
beforeEach ->
targaryen.setFirebaseRules rules
targaryen.setFirebaseData
destinations:
queen:
buckingham_palace:
latitude: 51.5013021
longitude: -0.148308
it 'cannot be read publicly', ->
expect targaryen.users.unauthenticated
.cannotRead '/destinations'
25. Test your rules!
it 'can be read by owner', ->
expect uid: 'queen'
.canRead '/destinations/queen'
it 'cannot be read by others', ->
expect targaryen.users.unauthenticated
.cannotRead '/destinations/queen'
expect uid: 'mayor'
.cannotRead '/destinations/queen'
26. Test your rules!
it 'can be created by owner', ->
expect uid: 'queen'
.canWrite '/destinations/queen/palace,
latitude: 51.501364
longitude: -0.14189
27. Test your rules!
// package.json
{
"scripts": {
"test": "firebase-bolt rules.bolt &&
node node_modules/jasmine/bin/jasmine.js"
}
}
$ npm test
28. Automatic
deployment
$ npm test
bolt: Generating rules.json...
Started
...............................................................
...............................................................
...............................................................
..........................
215 specs, 0 failures
Finished in 0.5 seconds
The command "npm test" exited with 0.
$ firebase --project beeline-test-e7288 deploy
Deploying to 'master' beeline-test-e7288
=== Deploying to 'beeline-test-e7288'...
i deploying database, functions
✔ database: rules ready to deploy.
i starting release process (may take several minutes)...
✔ Deploy complete!
31. Android
@IgnoreExtraProperties
data class Destination(
val latitude: Double = 0.0,
val longitude: Double = 0.0,
val name: String? = null,
)
val ref = FirebaseDatabase.getInstance()
.getReference("/destinations/user1/dest1")
// Write data
ref.setValue(Destination(51.5, 0))
32. Android
// Read data
ref.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
val destination =
snapshot.getValue(Destination::class.java)
// ...
}
override fun onCancelled(error: DatabaseError) {}
})
39. Cloud function
security
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(Object.assign(
{databaseAuthVariableOverride: {
uid: "stats@cloudfunction.beeline.co"
},
functions.config().firebase
);
const db = admin.database();
41. Cloud function
testing tips
● Use .val()
● Unit test your data logic
● Unit test your functions (fiddly)
https://firebase.google.com/docs/functions/unit-testing
● Set up error notifications for production
https://console.cloud.google.com/errors
53. What we like
so far
● Easy to set up
● Easy to integrate
● Realtime DB updates
● Minimal backend code
● Detailed docs
54. What we like
less so far
● A bit of a learning curve
● Lacking examples
● Limited querying
● Developing functions is slow
● Slow to load lots of data
● “Open source”
● In flux
55. What’s next
● More in-depth stats
● Large data → Long term (cheaper)
storage
● Emails/push for in-app events
● Cloud Firestore?