Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今日から始めるFirestoreのテスト

oliver
August 24, 2019

 今日から始めるFirestoreのテスト

「Firebase Hands-on @BEENOS」にて登壇した発表資料です。

https://firebase-community.connpass.com/event/140369/

oliver

August 24, 2019
Tweet

More Decks by oliver

Other Decks in Programming

Transcript

  1. ࠓ೔͔Β࢝ΊΔFirestoreͷςετ
    ͓Γ͹ʔʢ@oliver_diaryʣ

    View full-size slide

  2. ࣗݾ঺հ
    # Daiki Minakawa ( @oliver_diary )
    - ৽ଔ1೥໨
    - ݸਓͰ͸Rails࢖ͬͯͨΓ

    ৬৔Ͱ͸Elm৮ͬͯͨΓ
    - αʔόʔαΠυϝΠϯͩͬͨ͸͕ͣ࠷ۙͰ͸ϑϩϯτΛ৮Δ͜ͱ͕ଟ͍…
    - झຯ͸ΧϝϥͱԻήʔͱΞχϝ

    View full-size slide

  3. ͲΜͳ͜ͱ࿩͢ʁ
    • Firestoreʹ͍ͭͯͬ͟ͱ
    • FirestoreΛ࢖ͬͨҰྫ
    • FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • CircleCIͰςετΛճͦ͏ʂ
    • ͓ΘΓʹ

    View full-size slide

  4. Firestoreʹ͍ͭͯͬ͟ͱ

    View full-size slide

  5. Firestoreʹ͍ͭͯͬ͟ͱ
    • ެࣜʹ͸ʮRealtime Database ΑΓ΋ଟ࠼Ͱߴ଎ͳΫΤϦͱߴੑೳͳε
    έʔϦϯά͕ಛ௃ʯͱॻ͔Ε͍ͯΔ
    • https://firebase.google.com/docs/database/rtdb-vs-firestore
    • ཁ͢Δʹʮ͛͢ʔ࢖͍΍͘͢ʯͯʮ͛͢ʔߴ଎ʯͰʮ͛͢ʔεέʔϦϯά
    ͢ΔʯNoSQLσʔλϕʔε
    • σʔλϞσϧͱͯ͠͸ʮσʔλΛυΩϡϝϯτͷίϨΫγϣϯͱͯ͠อ
    ଘʯ͍ͯ͠Δ

    View full-size slide

  6. FirestoreΛ࢖ͬͨҰྫ

    View full-size slide

  7. FirestoreΛ࢖ͬͨҰྫ
    • Έͳ͞Μ͸FirestoreΛ࢖ͬͨ͜ͱ͋Γ·͔͢ʁ
    • ࢖ͬͨ͜ͱ͕͋ΔͷͰ͋Ε͹ɺςετΛॻ͍ͨ͜ͱ͋Γ·͢
    ͔ʁ

    View full-size slide

  8. FirestoreΛ࢖ͬͨҰྫ
    • Ұྫ
    • UserίϨΫγϣϯ͕ଘࡏ͠ɺΞΧ΢ϯτొ࿥࣌ʹυΩϡϝ
    ϯτʹEmailͱName͕ɺͦΕͧΕ࠷খ4จࣈɺ࠷େ256จ
    ࣈͰอଘ͞ΕΔ
    • ͦͷ࢓༷ͰA͞Μ͕·ͣRuleΛॻ͍ͨ

    View full-size slide

  9. FirestoreΛ࢖ͬͨҰྫ
    • Rules of A͞Μ
    • A͞Μ͕هड़ͨ͠Rule

    (ࡉ͔͍෦෼͸ࠓճؾʹ͠ͳ͍)

    View full-size slide

  10. FirestoreΛ࢖ͬͨҰྫ
    • Ұྫ
    • ޙ͔ΒNameΛ࠷খ4จࣈɺ࠷େ16จࣈʹ͍ͨ͠ͱ͍͏ཁ
    ๬͕͖ͨ
    • B͞Μ͕Ҿ͖ܧ͍ͰRuleΛߋ৽ͨ͠

    View full-size slide

  11. FirestoreΛ࢖ͬͨҰྫ
    • Rules of B͞Μ
    • B͞Μ͕มߋͨ͠Rule

    (validateStringͷத਎Λมߋ)

    View full-size slide

  12. FirestoreΛ࢖ͬͨҰྫ
    • ΋ͪΖΜ͜ΕͩͱɺEmailͷจࣈ਺্ݶ·Ͱ16จࣈʹͳͬͯ
    ͠·͍ɺ͜ͷঢ়ଶͰϦϦʔε͞ΕͨΒେมͳ͜ͱʹ
    • ݩͷRuleΛॻ͍ͨA͞Μ͕ѱ͍ͷ͔ʁ
    • ͦΕͱ΋Α͘νΣοΫΛͯ͠ͳ͔ͬͨB͞Μ͕ѱ͍ͷ͔ʁ

    View full-size slide

  13. FirestoreΛ࢖ͬͨҰྫ
    • ίʔυͷྑ͠ѱ͠͸ͱ΋͔͘ͱͯ͠ɺ

    ςετΛॻ͍͓͚ͯ͹ɺ࠷ѱͳঢ়ଶʢόά͕ଘࡏͨ͠ঢ়ଶʣ

    ͰͷϦϦʔε͸ආ͚ΒΕͨ͸ͣ

    View full-size slide

  14. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  15. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • Firestoreͷςετ͸ϩʔΧϧʹΤϛϡϨʔλΛཱͯͯςετͰ͖Δʂ
    • ͳͷͰɺผ్FirestoreͷϓϩδΣΫτΛ࡞Δඞཁ͸ͳ͠ʂ
    • ΈΜͳผʑͷΤϛϡϨʔλΛར༻͢ΔͷͰɺςετ͕յΕΔ͜ͱ΋ͳ
    ͠ʂ
    • CIͰςετ͕؆୯ʹͰ͖ΔʂʢޙʑͷষͰʣ

    View full-size slide

  16. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • લ४උͱͯ͠ɺfirebase-toolsͱemulatorͷΠϯετʔϧɾى
    ಈΛ͓ͤͯ͘͞
    • npm i firebase-tools --save
    • node_modules/.bin/firebase setup:emulators:firestore
    • node_modules/.bin/firebase serve --only firestore
    • ΤϛϡϨʔλͷىಈ

    View full-size slide

  17. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • npm i mocha --save
    • test༻ͷϥΠϒϥϦΛ௥Ճ
    • npm i @firebase/testing --save
    • FirebaseΛ࢖ͬͨςετΛॻ͘ͱ͖ʹඞཁ

    View full-size slide

  18. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • A͞Μͷfirestore.rules ϑΝΠϧ
    Λ࡞੒

    View full-size slide

  19. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • ςετΛ test/test.js ʹهड़͍ͯ͘͠

    View full-size slide

  20. • A͞Μͷ࣮૷࣌఺Ͱͷςετέʔε
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  21. • A͞Μͷ࣮૷࣌఺Ͱͷςετέʔε
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  22. • ςετ࣮ߦʂ
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  23. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • B͞Μͷfirestore.rules ϑΝΠϧ
    Λ࡞੒

    View full-size slide

  24. • B͞Μͷ࣮૷࣌఺Ͱͷςετέʔε
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  25. • ςετ࣮ߦʂ
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  26. FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ
    • ςετ͕མͪͨͷͰɺਖ਼͍͠firestore.rules
    Λهड़͍ͯ͘͠
    • ΋ͬͱ͍͍Ruleͷॻ͖ํ΍ɺEmailͷࡉ͔͍
    όϦσʔγϣϯͱ͔͸Ұ୴ແࢹͰ

    View full-size slide

  27. • ςετ࣮ߦʂ
    FirestoreͷςετΛॻ͍ͯΈΑ͏ʂ

    View full-size slide

  28. CircleCIͰςετΛճͦ͏ʂ

    View full-size slide

  29. CircleCIͰςετΛճͦ͏ʂ
    • ϩʔΧϧͰΤϛϡϨʔλΛཱͯͯςετΛ͖ͯͨͬͯ͜͠ͱ
    ͸ɺCIͰ΋࢖͑Δ͸ͣ…!
    • ͱ͍͏͜ͱͰɺCircleCIͰಈ͔ͯ͠ΈΑ͏ʂ
    • ؆୯ʹͰ͖ΔͷͰɺίʔυ͚ͩͬ͟ͱઆ໌͠·͢

    View full-size slide

  30. CircleCIͰςετΛճͦ͏ʂ
    • Ωϟογϡઓུͱ͔Կ΋ͯ͠ͳ͍
    ͚Ͳڐͯ͠
    • ಛච͢΂͖఺͸ɺΤϛϡϨʔλʹ
    java͕ඞཁͳͷͰimageʹ


    Λࢦఆͯ͠Δ͘Β͍Ͱ͢
    circleci/openjdk:stretch-node-browsers-legacy

    View full-size slide

  31. ͓ΘΓʹ
    • Firestore͸؆୯ʹ࣮૷Ͱ͖ɺ؆୯ʹར༻Ͱ͖Δ൓໘ɺ͔ͬ͠Γͱ
    RuleΛॻ͔ͳ͚Ε͹ɺσʔλ͕յΕͯ͠·͏͜ͱΛೝࣝ͠ͳ͍ͱ
    ͍͚ͳ͍
    • ͜ͷεϥΠυͰ঺հ͖͠Εͳ͔ͬͨFirestoreͷػೳ͸ͨ͘͞Μ͋
    Γ·͕͢ɺ·ͨػձ͕͋Ε͹͝঺հ͍ͨ͠ͱࢥ͍·͢

    ʢFieldValueͱ͔Firebase AuthͷCustomClaimͱͷ࿈ܞͱ͔…ʣ

    View full-size slide

  32. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide