Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve response predicates #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Database/Bloodhound/Internal/Client/BHRequest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ eitherDecodeResponse ::
eitherDecodeResponse = eitherDecode . responseBody . getResponse

-- | Was there an optimistic concurrency control conflict when
-- indexing a document?
-- indexing a document? (Check '409' status code.)
isVersionConflict :: BHResponse parsingContext a -> Bool
isVersionConflict = statusCheck (== 409)

Expand Down
15 changes: 15 additions & 0 deletions tests/Test/DocumentsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ spec =
Right (res', _) -> liftIO $ isVersionConflict res' `shouldBe` True
Left e -> liftIO $ errorStatus e `shouldBe` Just 409

it "can use predicates on the response" $
withTestEnv $ do
let ev = ExternalDocVersion minBound
let cfg = defaultIndexDocumentSettings {idsVersionControl = ExternalGT ev}
resetIndex
(res, _) <- insertData' cfg
liftIO $ isCreated res `shouldBe` True
liftIO $ isSuccess res `shouldBe` True
liftIO $ isVersionConflict res `shouldBe` False

res' <- insertData'' cfg
liftIO $ isCreated res' `shouldBe` False
liftIO $ isSuccess res' `shouldBe` False
liftIO $ isVersionConflict res' `shouldBe` True

it "indexes two documents in a parent/child relationship and checks that the child exists" $
withTestEnv $ do
resetIndex
Expand Down
7 changes: 7 additions & 0 deletions tests/TestsUtils/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ insertData' ids = do
_ <- performBHRequest $ refreshIndex testIndex
return r

-- | Returns the `BHResponse` of `indexDocument` without any parsing
insertData'' :: IndexDocumentSettings -> BH IO (BHResponse StatusDependant IndexedDocument)
insertData'' ids = do
r <- dispatch $ indexDocument testIndex ids exampleTweet (DocId "1")
_ <- performBHRequest $ refreshIndex testIndex
return r

insertTweetWithDocId :: Tweet -> Text -> BH IO IndexedDocument
insertTweetWithDocId tweet docId = do
let ids = defaultIndexDocumentSettings
Expand Down
Loading