I honestly don't comment on TH-cam videos much, but Todd, you're videos are always extremely well done and helpful! I just had to share how much I (and I'm sure many others) enjoy the work you do helping everyone learn how to use Firebase in better ways
Thank you for this one Todd, I went through this a lot today and hopefully it'll see me through what I'm currently stuck on. Nice, clear and very well explained examples. If I may also say, I am still amazed at how you managed to emulate the various circumstances in order to test them, and further amazed by how you'd be sure that the circumstances were being perfectly emulated ... It's coming from me thinking about other circumstances to emulate, and how I could be sure that I have set the circumstances perfectly. Many thanks.
2:14 is pretty much how I live my life.... "Somewhat recent version of Java. I don't actually know what the precise minimum version is. I have XX installed and that seems to work"
This video is equally helpful and fun to watch! Be careful not to miss the "await" statement when writing docs as admin to the database because if not this leads to seemingly erratic behaviour.
While we're here, I'm still wondering why there's no solution from Google for full text search in firestore. Even a separate solution would be okay. Algolia is soooooooo expensive !
It's a bit confusing that this library got renamed to @firebase/rules-unit-testing because a lot of its functionality seems useful for testing Firebase in general (such as clearing the database).
True, and I encountered the same problem earlier today. The solution was to change the version of @firebase/rules-unit-testing to 1.3.15 (the version I saw working within the Google Cloud Shell Editor. After that and reinstalling npm, this video could be followed.
Is there an updated version of this process. @firebase/testing is deprecated and points to @firebase/rules-unit-testing. However, when I install the latest version of @firebase/rules-unit-testing the code in the video does not work. Specifically 'TypeError: firebase.initializeTestApp is not a function'. I am proceeding with @firebase/rules-unit-testing v1.3.7 as this seems to work. But just wondering if the new process has been explained
I'm trying to follow along but I've getting a mocha error Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (..\firebase-auth-testing\tests\test.js)
You need to make sure the emulator is connected. I had the issue as I was running on non-default ports. My changes: 1.) I changed to the updated @firebase/rules-unit-testing 2.) const db = firebase.initializeTestApp({projectId: MY_PROJECT_ID}).firestore(); db.useEmulator("localhost", 8086)
This was a great video, but is honestly should probably be removed. This is not the current way to do unit testing in Firebase and the mix of information is confusing
I think the value proposition of this video is that is explains the moving parts of testing Security Rules using the Emulator Suite. Our libraries will evolve, and documentation will always be more up to date than videos.
@@rachelmmyers I think it would be helpful to provide a sample file with the new library setup process as opposed to the random code snippets that are provided in the documentation. For those who already know the mechanics of this stuff, the code snippets may be adequate, but I believe most people who turn to TH-cam for help are beginners and thus have little-to-no experience with setting up a test suite. If anything, I think it would be helpful to provide a short video explaining the new setup, as the rest of the process seems relatively unchanged.
Please god update this code to use version 9 SDK, your docs link to this video but your docs literally recommend to ppl to use the version9 instead of this.
Beautiful video: huge congrats! Functions will be nice to learn to test, probably in a future video. Pubsub as well, but maybe less users would appreciate (I would).
anyone know how to fix FirebaseError: Failed to get document because client is offline. I've tried running firebase emulators:start at project level and even test level. The emulator starts at port 5000 correctly and all are online as in on emulator UI. So why does it say that the client is offline!!!!!!!!!!!!!!!
Great video, Todd, thanks! I wish Google just updated their tutorials as they update the codebase - turns out `@firebase/testing` is now deprecated and we should use `@firebase/rules-unit-testing` instead
I cannot get past the Java dependency for the emulators. I had to install Java on my Mac, found that appears to be the latest version jre-8u261-macosx-x64.dmg which then gives me java version "1.6.0_65" in the Terminal whilst the emulator insists on 1.8 or higher. Setting this up is a rabbit hole inside a rabbit hole.
Hint: DON'T type a rule description as "if(...)" instead of "it(...)" because (a) it won't show up as an error and (b) it'll be difficult to track down! LOL
I'm really missing something like this for firebase function acting as triggers for CUD operations. Particularly when testing collection modifications which result in other collection documents being changed. Currently I can only get it working with ONE document change, where the code which should delete the database doesn't do so.
Excellent video! Question, what would be an elegant way to ensure the emulator starts and is available for use prior to proceeding with test execution?
Great video, i have been looking for something like this! The rule at 21:47 did not work form me, though. allow read: if (request.auth.uid == resource.data.userId) i had to use this instead: allow read: if (request.auth.uid == request.resource.data.userId)
I'm confused. You imported the firebase admin SDK to add a document to the firestore running in the emulator. Then how would use you use the admin SDK to add a document to the production database?
Like, you didn't add any config to the admin SDK telling it whether to write data to the emulator or the production SDK. So why did it go to the emulator by default?
hi what happened with the pathway "Validate app behavior and verify security rules with Firebase Emulators"? I could completed it in google.dev, but I do not find it now.
#askFirebase am i wrong or map fields are not supported on the new security rules? why can't I map a field like this: allow create: if !('userDetails.status' in incomingData());
btw @RachelMyers #askFirebase you have an error on your last blog post, please remove the bracket: allow create: if request.resource.data.keys().toSet() .hasOnly(["required","and","optional","keys"]). firebase.googleblog.com/2020/06/new-firestore-security-rules-features.html
Hmmm the assertSucceds and assertFails did not seem to work for me. I had to write my own little functions const isDocumentAccessible = async (db, path: string): Promise => { let isAccessible: boolean = true; try { await db.doc("/business/ABNMJ/expenses/2020/quarters/qtr1/items/item1").get(); } catch { isAccessible = false; } return isAccessible; };
Thanks for the wonderful video! Please help me with this use case - I have a restaurant collection with restaurant documents. 1) Certain fields in this document (like restaurant name, timings, etc) can be updated by owners or by admin users with special custom claims. 2) Certain fields (like ratings, popularity, visit count) CAN NOT be updated by any user (will be updated using cloud functions). 3) Certain fields (like internal flags) can only be updated by users with the special custom claim and not by owners. Thank you for your response!
I want my app to be able to create documents but not read or write those documents once they are created. Is this possible? I'm using cloud functions to process the documents but don't want the app to be able to come back and update the document, even if it's the owner of the document.
I cannot pass to th-cam.com/video/VDulvfBpzZE/w-d-xo.html I keep getting this error after I ran the emulators, cant find a solution, any ideas? @firebase/firestore: Firestore (7.16.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connection droppedThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend. My internet connection seems fine, thanks!
I honestly don't comment on TH-cam videos much, but Todd, you're videos are always extremely well done and helpful! I just had to share how much I (and I'm sure many others) enjoy the work you do helping everyone learn how to use Firebase in better ways
please make a new video, the syntax is no longer valid for the latest npm package
Excellent, the best tutorials ever. Completely generous!
Excellent step-by-step instructions of how to do unit test for cloud firestore with firebase emulator. Thank you very much.
You are welcome!
Thank you for this one Todd, I went through this a lot today and hopefully it'll see me through what I'm currently stuck on. Nice, clear and very well explained examples. If I may also say, I am still amazed at how you managed to emulate the various circumstances in order to test them, and further amazed by how you'd be sure that the circumstances were being perfectly emulated ... It's coming from me thinking about other circumstances to emulate, and how I could be sure that I have set the circumstances perfectly. Many thanks.
AWESOME. Seriously, you explain it so clear! 100!
Glad it was helpful!
2:14 is pretty much how I live my life....
"Somewhat recent version of Java. I don't actually know what the precise minimum version is. I have XX installed and that seems to work"
This video is equally helpful and fun to watch! Be careful not to miss the "await" statement when writing docs as admin to the database because if not this leads to seemingly erratic behaviour.
While we're here, I'm still wondering why there's no solution from Google for full text search in firestore. Even a separate solution would be okay. Algolia is soooooooo expensive !
"Let's just add an email for fun - uh, that was fun. *I need to get out more*" 😂
Great tutorial! Thorough and easy to follow. So helpful. Thank you!
Awesome video as always, thank you Todd! Looking forward to the next one.
The @firebase/testing package has been deprecated. Could you do a video tutorial explaining how to use @firebase/rules-unit-testing?
@@ToddKerpelmanCorp Looking forward then! Thank's for your valuable videos, you have a real teaching talent.
Thank you Todd! Your videos are helping me a LOT!
This tutorial was fantastic!
It's a bit confusing that this library got renamed to @firebase/rules-unit-testing because a lot of its functionality seems useful for testing Firebase in general (such as clearing the database).
True, and I encountered the same problem earlier today. The solution was to change the version of @firebase/rules-unit-testing to 1.3.15 (the version I saw working within the Google Cloud Shell Editor. After that and reinstalling npm, this video could be followed.
Is there an updated version of this process. @firebase/testing is deprecated and points to @firebase/rules-unit-testing. However, when I install the latest version of @firebase/rules-unit-testing the code in the video does not work. Specifically 'TypeError: firebase.initializeTestApp is not a function'. I am proceeding with @firebase/rules-unit-testing v1.3.7 as this seems to work. But just wondering if the new process has been explained
I also faced same issue as you mentioned here
Just 1 year later the library has been detracted the API changed and nothing works after update ...
At 2:33 the command should be `npm i -g firebase-tools`. You might also need to add `sudo` in front of it. Thanks for the video!
The MY_PROJECT_ID needs to be exactly the same as what the emulator knows from your local project or changes to security rules will not be picked up
I'm trying to follow along but I've getting a mocha error
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (..\firebase-auth-testing\tests\test.js)
I got the same error. I resolved it by ensuring my emulator was running using firebase emulators:start
You need to make sure the emulator is connected. I had the issue as I was running on non-default ports.
My changes:
1.) I changed to the updated @firebase/rules-unit-testing
2.)
const db = firebase.initializeTestApp({projectId: MY_PROJECT_ID}).firestore();
db.useEmulator("localhost", 8086)
I have watched this somewhere... Like yesterday XD ... But watching Todd again n again is fun n his lessons are interesting
05:34 I would love to know more about the "kraken-control-panel" project on the list though.
This is just excellent. Thanks!
Very valuable, thank you for sharing!
A lot of this does not work when using WSL
Great introduction! Can you expand on when to use what project id for initialisation of the test sdk?
super good topic!!! guess i can do the same thing to test my realtime db validation as well!
Can't wait for the next one!
This was a great video, but is honestly should probably be removed. This is not the current way to do unit testing in Firebase and the mix of information is confusing
I think the value proposition of this video is that is explains the moving parts of testing Security Rules using the Emulator Suite. Our libraries will evolve, and documentation will always be more up to date than videos.
@@rachelmmyers I think it would be helpful to provide a sample file with the new library setup process as opposed to the random code snippets that are provided in the documentation. For those who already know the mechanics of this stuff, the code snippets may be adequate, but I believe most people who turn to TH-cam for help are beginners and thus have little-to-no experience with setting up a test suite. If anything, I think it would be helpful to provide a short video explaining the new setup, as the rest of the process seems relatively unchanged.
Please make more videos on this topic, like for example when a document is updated/deleted
Could you also share best practices on splitting the code in the firestore.rules file and the test.js file
Was looking for this. Can't find anything on this
Please god update this code to use version 9 SDK, your docs link to this video but your docs literally recommend to ppl to use the version9 instead of this.
Great tutorial, thank you!
Beautiful video: huge congrats! Functions will be nice to learn to test, probably in a future video. Pubsub as well, but maybe less users would appreciate (I would).
anyone know how to fix FirebaseError: Failed to get document because client is offline. I've tried running firebase emulators:start at project level and even test level. The emulator starts at port 5000 correctly and all are online as in on emulator UI. So why does it say that the client is offline!!!!!!!!!!!!!!!
Could you please give me the link to the video refered in 12:04?
This was gold. Thanks.
What about realtime database
Does anybody where the next episode is 🤔?
The playlist doesn’t seem to have the matching content mentioned in the video, like list
Great video as always Todd 👏
Perhaps you could show how to setup a CI with the emulator (would be nice if it was using GitHub actions)?
Great video, Todd, thanks! I wish Google just updated their tutorials as they update the codebase - turns out `@firebase/testing` is now deprecated and we should use `@firebase/rules-unit-testing` instead
The codelab isn't available anymore?
I cannot get past the Java dependency for the emulators. I had to install Java on my Mac, found that appears to be the latest version jre-8u261-macosx-x64.dmg which then gives me java version "1.6.0_65" in the Terminal whilst the emulator insists on 1.8 or higher. Setting this up is a rabbit hole inside a rabbit hole.
Is there any flutter/dart examples?
Excellent tutorial!!!
Is there a way to add thousands of documents to firestore for testing purposes?
Hint: DON'T type a rule description as "if(...)" instead of "it(...)" because (a) it won't show up as an error and (b) it'll be difficult to track down! LOL
Darn. This video is severly outdated. Worst of all, its what the official docs point to still.
Classic Google style unfortunatelly.
Request for a video helping with Firestore security rules coverage?
firebase real time database is not working in india from sep3 2020 and still there is no response from firebase team
Can you please provide a link to the end working code in the description
I'm really missing something like this for firebase function acting as triggers for CUD operations. Particularly when testing collection modifications which result in other collection documents being changed. Currently I can only get it working with ONE document change, where the code which should delete the database doesn't do so.
how can you use the playground to test with multiple tenants?
I think you wanted `npm i -g firebase-tools` and not `npm -i g firebase-tools` @2:30
Excellent video! Question, what would be an elegant way to ensure the emulator starts and is available for use prior to proceeding with test execution?
Use firebase emulators:exec "test command"
Great video, i have been looking for something like this!
The rule at 21:47 did not work form me, though.
allow read: if (request.auth.uid == resource.data.userId)
i had to use this instead:
allow read: if (request.auth.uid == request.resource.data.userId)
I'm confused. You imported the firebase admin SDK to add a document to the firestore running in the emulator. Then how would use you use the admin SDK to add a document to the production database?
Like, you didn't add any config to the admin SDK telling it whether to write data to the emulator or the production SDK. So why did it go to the emulator by default?
@@ToddKerpelmanCorp Ah. Environment Variables. Thank you!
hi
what happened with the pathway "Validate app behavior and verify security rules with Firebase Emulators"?
I could completed it in google.dev, but I do not find it now.
Can we use firebase emulators to test authentication also? If yes how?
#askFirebase am i wrong or map fields are not supported on the new security rules? why can't I map a field like this: allow create: if !('userDetails.status' in incomingData());
btw @RachelMyers #askFirebase you have an error on your last blog post, please remove the bracket: allow create: if request.resource.data.keys().toSet()
.hasOnly(["required","and","optional","keys"]). firebase.googleblog.com/2020/06/new-firestore-security-rules-features.html
How can I test a query (list)?
Also, 2:23 should read ```npm i g firebase-tools``` instead of ```npm -i g firebase-tools```
Thanks for the video!
Is this possible for storage rules too?
Meaning, running unit tests against the rules?
Hmmm the assertSucceds and assertFails did not seem to work for me. I had to write my own little functions
const isDocumentAccessible = async (db, path: string): Promise => {
let isAccessible: boolean = true;
try {
await db.doc("/business/ABNMJ/expenses/2020/quarters/qtr1/items/item1").get();
} catch {
isAccessible = false;
}
return isAccessible;
};
I'm wondering how you set-up the firebase rules with a framework like react
Same. They are framework agnostic (firebase init). You can run the same tests with jest.
What do u mean by "if true" and "if false" why not just "true" and "false".
Thanks for the wonderful video! Please help me with this use case - I have a restaurant collection with restaurant documents. 1) Certain fields in this document (like restaurant name, timings, etc) can be updated by owners or by admin users with special custom claims. 2) Certain fields (like ratings, popularity, visit count) CAN NOT be updated by any user (will be updated using cloud functions). 3) Certain fields (like internal flags) can only be updated by users with the special custom claim and not by owners. Thank you for your response!
Aren't these integration tests?
I want my app to be able to create documents but not read or write those documents once they are created. Is this possible? I'm using cloud functions to process the documents but don't want the app to be able to come back and update the document, even if it's the owner of the document.
Hi Adam, you can make a rule like if the data coming is the same as the data in the database, in that case is impossible to change the original data.
Firebase/testing is deprecated, use @firebase/rules-unit-testing
No no .. it was not firecast series XD
I cannot pass to th-cam.com/video/VDulvfBpzZE/w-d-xo.html I keep getting this error after I ran the emulators, cant find a solution, any ideas?
@firebase/firestore: Firestore (7.16.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connection droppedThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
My internet connection seems fine, thanks!
The same issue here