git.iko.soy/typeable/bloodhound
on master help sign in
Added unit test for documentExists

This tests that the parent/child relationship is working properly.

commitb6904b2cea91cc8514858fbea6cef9957f9f156a authorJohn Galt <centromere@users.noreply.github.com> dateFri 2 Oct 2015, 18:38 (11 years ago) parentceba885
1 file changed+26
tests/tests.hs+26
tests/tests.hs+26
@@ -116,6 +116,20 @@ instance FromJSON Tweet
116116instance ToJSON Location
117117instance FromJSON Location
118118
119+data ParentMapping = ParentMapping deriving (Eq, Show)
120+
121+instance ToJSON ParentMapping where
122+ toJSON ParentMapping =
123+ object ["parent" .= Null ]
124+
125+data ChildMapping = ChildMapping deriving (Eq, Show)
126+
127+instance ToJSON ChildMapping where
128+ toJSON ChildMapping =
129+ object ["child" .=
130+ object ["_parent" .= object ["type" .= ("parent" :: Text)]]
131+ ]
132+
119133data TweetMapping = TweetMapping deriving (Eq, Show)
120134
121135instance ToJSON TweetMapping where
@@ -330,6 +344,18 @@ main = hspec $ do
330344 res' <- insertData' cfg
331345 liftIO $ isVersionConflict res' `shouldBe` True
332346
347+ it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
348+ resetIndex
349+ _ <- putMapping testIndex (MappingName "parent") ParentMapping
350+ _ <- putMapping testIndex (MappingName "child") ChildMapping
351+ _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
352+ let parent = (Just . DocumentParent . DocId) "1"
353+ ids = IndexDocumentSettings NoVersionControl parent
354+ _ <- indexDocument testIndex (MappingName "child") ids otherTweet (DocId "2")
355+ _ <- refreshIndex testIndex
356+ exists <- documentExists testIndex (MappingName "child") parent (DocId "2")
357+ liftIO $ exists `shouldBe` True
358+
333359 describe "template API" $ do
334360 it "can create a template" $ withTestEnv $ do
335361 let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]