Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
今日から始めるFirestoreのテスト
Search
oliver
August 24, 2019
Programming
2
10k
今日から始めるFirestoreのテスト
「Firebase Hands-on @BEENOS」にて登壇した発表資料です。
https://firebase-community.connpass.com/event/140369/
oliver
August 24, 2019
Tweet
Share
More Decks by oliver
See All by oliver
Cacheable Presigned URL with Cloudflare Workers
oliver_diary
2
5.7k
テキストエディタのブラウザ実装 / tokyo_study
oliver_diary
0
250
迫り来る絶望的状況からの脱却物語 / #CEDEC2021
oliver_diary
7
15k
PWAとクラウドゲーミングの現状そしてPWAとOOParts
oliver_diary
3
10k
OOPartsによるPWA事例紹介
oliver_diary
2
8.5k
クラウドゲーミング最新開発事例 - #CEDEC2020
oliver_diary
6
15k
クラウドゲーミング時代のPWA
oliver_diary
0
11k
OOPartsが切り開く クラウドゲーミング ✖︎ PWA
oliver_diary
4
15k
やっていこう。PWA
oliver_diary
13
16k
Other Decks in Programming
See All in Programming
Synchronizationを支える技術
s_shimotori
1
150
Piniaの現状と今後
waka292
5
1.5k
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
110
macOS でできる リアルタイム動画像処理
biacco42
7
1.9k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
870
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
580
Golang と Erlang
taiyow
8
1.9k
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.7k
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.9k
Automating Front-end Workflow
addyosmani
1365
200k
RailsConf 2023
tenderlove
29
880
How to Ace a Technical Interview
jacobian
275
23k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Gamification - CAS2011
davidbonilla
80
5k
Visualization
eitanlees
144
15k
Teambox: Starting and Learning
jrom
132
8.7k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Code Reviewing Like a Champion
maltzj
519
39k
Transcript
ࠓ͔Β࢝ΊΔFirestoreͷςετ ͓Γʔʢ@oliver_diaryʣ
ࣗݾհ
ࣗݾհ # Daiki Minakawa ( @oliver_diary ) - ৽ଔ1 -
ݸਓͰRailsͬͯͨΓ ৬ͰElm৮ͬͯͨΓ - αʔόʔαΠυϝΠϯ͕ͩͬͨͣ࠷ۙͰϑϩϯτΛ৮Δ͜ͱ͕ଟ͍… - झຯΧϝϥͱԻήʔͱΞχϝ
ͲΜͳ͜ͱ͢ʁ • Firestoreʹ͍ͭͯͬ͟ͱ • FirestoreΛͬͨҰྫ • FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • CircleCIͰςετΛճͦ͏ʂ •
͓ΘΓʹ
Firestoreʹ͍ͭͯͬ͟ͱ
Firestoreʹ͍ͭͯͬ͟ͱ • ެࣜʹʮRealtime Database ΑΓଟ࠼ͰߴͳΫΤϦͱߴੑೳͳε έʔϦϯά͕ಛʯͱॻ͔Ε͍ͯΔ • https://firebase.google.com/docs/database/rtdb-vs-firestore • ཁ͢Δʹʮ͛͢ʔ͍͘͢ʯͯʮ͛͢ʔߴʯͰʮ͛͢ʔεέʔϦϯά
͢ΔʯNoSQLσʔλϕʔε • σʔλϞσϧͱͯ͠ʮσʔλΛυΩϡϝϯτͷίϨΫγϣϯͱͯ͠อ ଘʯ͍ͯ͠Δ
FirestoreΛͬͨҰྫ
FirestoreΛͬͨҰྫ • Έͳ͞ΜFirestoreΛͬͨ͜ͱ͋Γ·͔͢ʁ • ͬͨ͜ͱ͕͋ΔͷͰ͋ΕɺςετΛॻ͍ͨ͜ͱ͋Γ·͢ ͔ʁ
FirestoreΛͬͨҰྫ • Ұྫ • UserίϨΫγϣϯ͕ଘࡏ͠ɺΞΧϯτొ࣌ʹυΩϡϝ ϯτʹEmailͱName͕ɺͦΕͧΕ࠷খ4จࣈɺ࠷େ256จ ࣈͰอଘ͞ΕΔ • ͦͷ༷ͰA͞Μ͕·ͣRuleΛॻ͍ͨ
FirestoreΛͬͨҰྫ • Rules of A͞Μ • A͞Μ͕هड़ͨ͠Rule (ࡉ͔͍෦ࠓճؾʹ͠ͳ͍)
FirestoreΛͬͨҰྫ • Ұྫ • ޙ͔ΒNameΛ࠷খ4จࣈɺ࠷େ16จࣈʹ͍ͨ͠ͱ͍͏ཁ ͕͖ͨ • B͞Μ͕Ҿ͖ܧ͍ͰRuleΛߋ৽ͨ͠
FirestoreΛͬͨҰྫ • Rules of B͞Μ • B͞Μ͕มߋͨ͠Rule (validateStringͷதΛมߋ)
FirestoreΛͬͨҰྫ • ͪΖΜ͜ΕͩͱɺEmailͷจࣈ্ݶ·Ͱ16จࣈʹͳͬͯ ͠·͍ɺ͜ͷঢ়ଶͰϦϦʔε͞ΕͨΒେมͳ͜ͱʹ • ݩͷRuleΛॻ͍ͨA͞Μ͕ѱ͍ͷ͔ʁ • ͦΕͱΑ͘νΣοΫΛͯ͠ͳ͔ͬͨB͞Μ͕ѱ͍ͷ͔ʁ
FirestoreΛͬͨҰྫ • ίʔυͷྑ͠ѱ͠ͱ͔͘ͱͯ͠ɺ ςετΛॻ͍͓͚ͯɺ࠷ѱͳঢ়ଶʢόά͕ଘࡏͨ͠ঢ়ଶʣ ͰͷϦϦʔεආ͚ΒΕͨͣ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • FirestoreͷςετϩʔΧϧʹΤϛϡϨʔλΛཱͯͯςετͰ͖Δʂ • ͳͷͰɺผ్FirestoreͷϓϩδΣΫτΛ࡞Δඞཁͳ͠ʂ • ΈΜͳผʑͷΤϛϡϨʔλΛར༻͢ΔͷͰɺςετ͕յΕΔ͜ͱͳ ͠ʂ • CIͰςετ͕؆୯ʹͰ͖ΔʂʢޙʑͷষͰʣ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • લ४උͱͯ͠ɺfirebase-toolsͱemulatorͷΠϯετʔϧɾى ಈΛ͓ͤͯ͘͞ • npm i firebase-tools --save •
node_modules/.bin/firebase setup:emulators:firestore • node_modules/.bin/firebase serve --only firestore • ΤϛϡϨʔλͷىಈ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • npm i mocha --save • test༻ͷϥΠϒϥϦΛՃ • npm
i @firebase/testing --save • FirebaseΛͬͨςετΛॻ͘ͱ͖ʹඞཁ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • A͞Μͷfirestore.rules ϑΝΠϧ Λ࡞
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • ςετΛ test/test.js ʹهड़͍ͯ͘͠
• A͞Μͷ࣮࣌Ͱͷςετέʔε FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
• A͞Μͷ࣮࣌Ͱͷςετέʔε FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
• ςετ࣮ߦʂ FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • B͞Μͷfirestore.rules ϑΝΠϧ Λ࡞
• B͞Μͷ࣮࣌Ͱͷςετέʔε FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
• ςετ࣮ߦʂ FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ • ςετ͕མͪͨͷͰɺਖ਼͍͠firestore.rules Λهड़͍ͯ͘͠ • ͬͱ͍͍Ruleͷॻ͖ํɺEmailͷࡉ͔͍ όϦσʔγϣϯͱ͔Ұ୴ແࢹͰ
• ςετ࣮ߦʂ FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
CircleCIͰςετΛճͦ͏ʂ
CircleCIͰςετΛճͦ͏ʂ • ϩʔΧϧͰΤϛϡϨʔλΛཱͯͯςετΛ͖ͯͨͬͯ͜͠ͱ ɺCIͰ͑Δͣ…! • ͱ͍͏͜ͱͰɺCircleCIͰಈ͔ͯ͠ΈΑ͏ʂ • ؆୯ʹͰ͖ΔͷͰɺίʔυ͚ͩͬ͟ͱઆ໌͠·͢
CircleCIͰςετΛճͦ͏ʂ • Ωϟογϡઓུͱ͔Կͯ͠ͳ͍ ͚Ͳڐͯ͠ • ಛච͖͢ɺΤϛϡϨʔλʹ java͕ඞཁͳͷͰimageʹ Λࢦఆͯ͠Δ͘Β͍Ͱ͢ circleci/openjdk:stretch-node-browsers-legacy
͓ΘΓʹ
͓ΘΓʹ • Firestore؆୯ʹ࣮Ͱ͖ɺ؆୯ʹར༻Ͱ͖Δ໘ɺ͔ͬ͠Γͱ RuleΛॻ͔ͳ͚Εɺσʔλ͕յΕͯ͠·͏͜ͱΛೝࣝ͠ͳ͍ͱ ͍͚ͳ͍ • ͜ͷεϥΠυͰհ͖͠Εͳ͔ͬͨFirestoreͷػೳͨ͘͞Μ͋ Γ·͕͢ɺ·ͨػձ͕͋Ε͝հ͍ͨ͠ͱࢥ͍·͢ ʢFieldValueͱ͔Firebase AuthͷCustomClaimͱͷ࿈ܞͱ͔…ʣ
͋Γ͕ͱ͏͍͟͝·ͨ͠