From 37fd4fff73e8b251c06e23c9cf2e3276a8ce5def Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Tue, 5 Nov 2024 17:08:21 +0100 Subject: [PATCH 1/2] chore: Add test to check response predicates Some cases weren't tested. --- tests/Test/DocumentsSpec.hs | 15 +++++++++++++++ tests/TestsUtils/Common.hs | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/tests/Test/DocumentsSpec.hs b/tests/Test/DocumentsSpec.hs index d55fa38..8bd70ce 100644 --- a/tests/Test/DocumentsSpec.hs +++ b/tests/Test/DocumentsSpec.hs @@ -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 diff --git a/tests/TestsUtils/Common.hs b/tests/TestsUtils/Common.hs index c45ab9d..14d7237 100644 --- a/tests/TestsUtils/Common.hs +++ b/tests/TestsUtils/Common.hs @@ -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 From d6d914a5717f056d5b11316a4869b1defaf1f10b Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Tue, 5 Nov 2024 17:09:20 +0100 Subject: [PATCH 2/2] chore: Improve Haddock of isVersionConflict Describe which HTTP status code we're checking against. --- src/Database/Bloodhound/Internal/Client/BHRequest.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Bloodhound/Internal/Client/BHRequest.hs b/src/Database/Bloodhound/Internal/Client/BHRequest.hs index 2f5af8a..bd8b360 100644 --- a/src/Database/Bloodhound/Internal/Client/BHRequest.hs +++ b/src/Database/Bloodhound/Internal/Client/BHRequest.hs @@ -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)