Skip to main content

Posts

Showing posts with the label testing

A month of Flutter: Firestore create user rules and tests

Originally published on bendyworks. com. When a user  signs in with Google  I'm going to create a user document in Firestore. Each authenticated user should only be able to create one user document. These documents will eventually be readable by other users so Firestore needs to have  server(less)-side validation  to keep the data as correct as possible. Right now I'm working on  registering users  so I'm only going to implement  create  rules, not  read ,  update , etc. match / users / { userId } { allow create : if isOwner ( userId ) && // TODO: enable after bug fix https://github.com/firebase/firebase-tools/issues/1073 // validCreateTimestamps() && validCreateUser (); } This will allow  user  documents to be created if the owner has the same ID and the document being created passes validation. Validation of timestamps is being...

A month of Flutter: set up Firestore rules tests

Originally published on bendyworks.com . One aspect of using Firestore for my data backend means I need to be certain my  security rules  are configured correctly. Otherwise users might be able to read or write date they shouldn't have access to. A few days ago I  set up Firestore  in the  server  directory. I'm going to continue that work and configure tests to run on the  Firestore emulator  based off of the  typescript-qickstart  example. In  package.json  I'll add some  devDependencies  and define several  scripts .  Node package  scripts  can be run with  npm run <name> . postinstall  will set up the Firestore emulator after  npm install  is run in the  scripts  directory start-emulator  will will do just that pretest  will compile the project's  TypeScript  files before the  test  script is run test  will r...