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.8k
テキストエディタのブラウザ実装 / tokyo_study
oliver_diary
0
250
迫り来る絶望的状況からの脱却物語 / #CEDEC2021
oliver_diary
7
15k
PWAとクラウドゲーミングの現状そしてPWAとOOParts
oliver_diary
3
11k
OOPartsによるPWA事例紹介
oliver_diary
2
8.7k
クラウドゲーミング最新開発事例 - #CEDEC2020
oliver_diary
6
16k
クラウドゲーミング時代のPWA
oliver_diary
0
11k
OOPartsが切り開く クラウドゲーミング ✖︎ PWA
oliver_diary
4
15k
やっていこう。PWA
oliver_diary
13
16k
Other Decks in Programming
See All in Programming
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
flutterkaigi_2024.pdf
kyoheig3
0
150
Jakarta EE meets AI
ivargrimstad
0
210
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
CSC509 Lecture 12
javiergs
PRO
0
160
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
役立つログに取り組もう
irof
28
9.6k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
CSC509 Lecture 11
javiergs
PRO
0
180
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Scaling GitHub
holman
458
140k
Typedesign – Prime Four
hannesfritz
40
2.4k
GraphQLとの向き合い方2022年版
quramy
43
13k
Six Lessons from altMBA
skipperchong
27
3.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
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ͱͷ࿈ܞͱ͔…ʣ
͋Γ͕ͱ͏͍͟͝·ͨ͠