From f20a8b7f7dd8f55e365d7096d746499ecd81d4ae Mon Sep 17 00:00:00 2001 From: Dmitry Dzhus Date: Tue, 22 Dec 2015 17:28:23 +0000 Subject: [PATCH] Test _update API --- tests/tests.hs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/tests.hs b/tests/tests.hs index d032e0d..9c96089 100644 --- a/tests/tests.hs +++ b/tests/tests.hs @@ -180,6 +180,21 @@ exampleTweet = Tweet { user = "bitemyapp" , age = 10000 , location = Location 40.12 (-71.34) } +newAge :: Int +newAge = 31337 + +newUser :: Text +newUser = "someotherapp" + +tweetPatch :: Value +tweetPatch = + object [ "age" .= newAge + , "user" .= newUser + ] + +patchedTweet :: Tweet +patchedTweet = exampleTweet{age = newAge, user = newUser} + otherTweet :: Tweet otherTweet = Tweet { user = "notmyapp" , postDate = UTCTime @@ -207,6 +222,12 @@ insertData' ids = do _ <- refreshIndex testIndex return r +updateData :: BH IO Reply +updateData = do + r <- updateDocument testIndex testMapping defaultIndexDocumentSettings tweetPatch (DocId "1") + _ <- refreshIndex testIndex + return r + insertOther :: BH IO () insertOther = do _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings otherTweet (DocId "2") @@ -761,12 +782,13 @@ main = hspec $ do liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]")) describe "document API" $ do - it "indexes, gets, and then deletes the generated document" $ withTestEnv $ do + it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do _ <- insertData + _ <- updateData docInserted <- getDocument testIndex testMapping (DocId "1") let newTweet = eitherDecode (responseBody docInserted) :: Either String (EsResult Tweet) - liftIO $ (fmap getSource newTweet `shouldBe` Right (Just exampleTweet)) + liftIO $ (fmap getSource newTweet `shouldBe` Right (Just patchedTweet)) it "indexes, gets, and then deletes the generated document with a DocId containing a space" $ withTestEnv $ do _ <- insertWithSpaceInId