git.iko.soy/typeable/bloodhound
on ff6abcb help sign in
51 lines 2.4 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module Test.Documents where
5import Test.Common
6import Test.Import
8spec :: Spec
9spec =
10 describe "document API" $ do
11 it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do
12 _ <- insertData
13 _ <- updateData
14 docInserted <- getDocument testIndex testMapping (DocId "1")
15 let newTweet = eitherDecode
16 (responseBody docInserted) :: Either String (EsResult Tweet)
17 liftIO $ fmap getSource newTweet `shouldBe` Right (Just patchedTweet)
19 it "indexes, gets, and then deletes the generated document with a DocId containing a space" $ withTestEnv $ do
20 _ <- insertWithSpaceInId
21 docInserted <- getDocument testIndex testMapping (DocId "Hello World")
22 let newTweet = eitherDecode
23 (responseBody docInserted) :: Either String (EsResult Tweet)
24 liftIO $ fmap getSource newTweet `shouldBe` Right (Just exampleTweet)
26 it "produces a parseable result when looking up a bogus document" $ withTestEnv $ do
27 doc <- getDocument testIndex testMapping (DocId "bogus")
28 let noTweet = eitherDecode
29 (responseBody doc) :: Either String (EsResult Tweet)
30 liftIO $ fmap foundResult noTweet `shouldBe` Right Nothing
32 it "can use optimistic concurrency control" $ withTestEnv $ do
33 let ev = ExternalDocVersion minBound
34 let cfg = defaultIndexDocumentSettings { idsVersionControl = ExternalGT ev }
35 resetIndex
36 res <- insertData' cfg
37 liftIO $ isCreated res `shouldBe` True
38 res' <- insertData' cfg
39 liftIO $ isVersionConflict res' `shouldBe` True
41 it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
42 resetIndex
43 _ <- putMapping testIndex (MappingName "child") ChildMapping
44 _ <- putMapping testIndex (MappingName "parent") ParentMapping
45 _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
46 let parent = (Just . DocumentParent . DocId) "1"
47 ids = IndexDocumentSettings NoVersionControl parent
48 _ <- indexDocument testIndex (MappingName "child") ids otherTweet (DocId "2")
49 _ <- refreshIndex testIndex
50 exists <- documentExists testIndex (MappingName "child") parent (DocId "2")
51 liftIO $ exists `shouldBe` True