Skip to content

Commit 3bd926b

Browse files
committed
[#12] test clearing of a collection
1 parent 8502d65 commit 3bd926b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Web/Firestore.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Web.Firestore
1616
, DocumentSnapshot
1717
, Firestore
1818
, add
19+
, clearCollection
1920
, collection
2021
, delete
2122
, deleteApp

test/Web/FirestoreCollectionSpec.purs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Test.Spec (Spec, describe, it)
1313
import Test.Spec.Assertions (fail, shouldSatisfy)
1414

1515
import Test.Web.Firestore.OptionsUtils (buildTestOptions)
16-
import Web.Firestore (add, collection, deleteApp, firestore, getCollection, initializeApp)
16+
import Web.Firestore (add, clearCollection, collection, deleteApp, firestore, getCollection, initializeApp)
1717
import Web.Firestore.Blob (blob)
1818
import Web.Firestore.CollectionPath (pathFromString)
1919
import Web.Firestore.DocumentData (DocumentData(..))
@@ -203,3 +203,28 @@ suite = do
203203
forEach querySnapshot (const $ pure unit)
204204
deletePromise <- liftEffect $ deleteApp app
205205
toAff deletePromise
206+
207+
it "clears a collection" do
208+
testOptions <- buildTestOptions
209+
eitherErrorApp <- liftEffect $ initializeApp testOptions (Just "firestore-test")
210+
case eitherErrorApp of
211+
Left error -> fail $ show error
212+
Right app -> do
213+
eitherFirestoreInstance <- liftEffect $ firestore app
214+
case eitherFirestoreInstance of
215+
Left error -> fail $ show error
216+
Right firestoreInstance -> do
217+
maybeCollectionRef <- liftEffect $ sequence $ collection firestoreInstance <$> (pathFromString "collection")
218+
case maybeCollectionRef of
219+
Nothing -> fail "invalid path"
220+
Just collectionRef -> do
221+
addPromise1 <- liftEffect $ add collectionRef document1
222+
_ <- toAff addPromise1
223+
addPromise2 <- liftEffect $ add collectionRef document2
224+
_ <- toAff addPromise2
225+
clearCollection collectionRef
226+
getPromise <- liftEffect $ getCollection collectionRef Nothing
227+
querySnapshot <- toAff getPromise
228+
forEach querySnapshot (const $ fail "no document should be present now!")
229+
deletePromise <- liftEffect $ deleteApp app
230+
toAff deletePromise

0 commit comments

Comments
 (0)