git.iko.soy/typeable/bloodhound
on 8daeabb help sign in
36 lines 1.2 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module Test.Script where
5import Test.Common
6import Test.Import
8import qualified Data.HashMap.Strict as HM
9import qualified Data.Map as M
11spec :: Spec
12spec =
13 describe "Script" $
14 it "returns a transformed document based on the script field" $ withTestEnv $ do
15 _ <- insertData
16 let query = MatchAllQuery Nothing
17 sfv = toJSON $
18 Script
19 (Just (ScriptLanguage "painless"))
20 (Just (ScriptInline "doc['age'].value * 2"))
21 Nothing
22 Nothing
23 sf = ScriptFields $
24 HM.fromList [("test1", sfv)]
25 search' = mkSearch (Just query) Nothing
26 search = search' { scriptFields = Just sf }
27 resp <- searchByIndex testIndex search
28 parsed <- parseEsResponse resp :: BH IO (Either EsError (SearchResult Value))
29 case parsed of
30 Left e ->
31 liftIO $ expectationFailure ("Expected a script-transformed result but got: " <> show e)
32 Right sr -> do
33 let Just results =
34 hitFields (head (hits (searchHits sr)))
35 liftIO $
36 results `shouldBe` HitFields (M.fromList [("test1", [Number 20000.0])])