git.iko.soy/typeable/bloodhound
on 28386b0 help sign in
32 lines 1.0 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module Test.Highlights where
5import Test.Common
6import Test.Import
8import qualified Data.Map as M
10initHighlights :: Text -> BH IO (Either EsError (Maybe HitHighlight))
11initHighlights fieldName = do
12 _ <- insertData
13 _ <- insertOther
14 let query = QueryMatchQuery $ mkMatchQuery (FieldName fieldName) (QueryString "haskell")
15 let testHighlight = Highlights Nothing [FieldHighlight (FieldName fieldName) Nothing]
16 let search = mkHighlightSearch (Just query) testHighlight
17 searchTweetHighlight search
19spec :: Spec
20spec =
21 describe "Highlights API" $ do
22 it "returns highlight from query when there should be one" $ withTestEnv $ do
23 myHighlight <- initHighlights "message"
24 liftIO $
25 myHighlight `shouldBe`
26 Right (Just (M.fromList [("message", ["Use <em>haskell</em>!"])]))
28 it "doesn't return highlight from a query when it shouldn't" $ withTestEnv $ do
29 myHighlight <- initHighlights "user"
30 liftIO $
31 myHighlight `shouldBe`
32 Right Nothing