git.iko.soy/typeable/bloodhound
on master help sign in
Added a test for the script field
94bf2e4Chris Allen
tests/V5/tests.hs+25−1
@@ -1687,7 +1687,7 @@ main = hspec $ do
1687 resetIndex
1687 resetIndex
1688 resp <- updateIndexAliases (action :| [])
1688 resp <- updateIndexAliases (action :| [])
1689 liftIO $ validateStatus resp 200
1689 liftIO $ validateStatus resp 200
1690− deleteIndexAlias aname
1690+ _ <- deleteIndexAlias aname
1691 getIndexAliases
1691 getIndexAliases
1692 -- let expected = IndexAliasSummary alias create
1692 -- let expected = IndexAliasSummary alias create
1693 case aliases of
1693 case aliases of
@@ -1792,6 +1792,30 @@ main = hspec $ do
1792 Left e -> liftIO $ expectationFailure ("Expected an search suggestion but got " <> show e)
1792 Left e -> liftIO $ expectationFailure ("Expected an search suggestion but got " <> show e)
1793 Right sr -> liftIO $ (suggestOptionsText . head . suggestResponseOptions . head . nsrResponses <$> suggest sr) `shouldBe` expectedText
1793 Right sr -> liftIO $ (suggestOptionsText . head . suggestResponseOptions . head . nsrResponses <$> suggest sr) `shouldBe` expectedText
1794
1794
1795+ describe "Script" $ do
1796+ it "returns a transformed document based on the script field" $ withTestEnv $ do
1797+ _ <- insertData
1798+ let query = MatchAllQuery Nothing
1799+ sfv = toJSON $
1800+ Script
1801+ (Just (ScriptLanguage "painless"))
1802+ (Just (ScriptInline "doc['age'].value * 2"))
1803+ Nothing
1804+ Nothing
1805+ sf = ScriptFields $
1806+ HM.fromList [("test1", sfv)]
1807+ search' = mkSearch (Just query) Nothing
1808+ search = search' { scriptFields = Just sf }
1809+ resp <- searchByIndex testIndex search
1810+ parsed <- parseEsResponse resp :: BH IO (Either EsError (SearchResult Value))
1811+ case parsed of
1812+ Left e ->
1813+ liftIO $ expectationFailure ("Expected a script-transformed result but got: " <> show e)
1814+ Right sr -> do
1815+ let Just results =
1816+ hitFields (head (hits (searchHits sr)))
1817+ liftIO $ results `shouldBe` (HitFields (M.fromList [("test1", [Number 20000.0])]))
1818+
1795 describe "Exact isomorphism JSON instances" $ do
1819 describe "Exact isomorphism JSON instances" $ do
1796 propJSON (Proxy :: Proxy Version)
1820 propJSON (Proxy :: Proxy Version)
1797 propJSON (Proxy :: Proxy IndexName)
1821 propJSON (Proxy :: Proxy IndexName)