From 49940a30d0b7a1dda6a39981a37232d1271b1c57 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 9 Apr 2021 16:15:59 +0400 Subject: [PATCH] XmlLibraryTest.removeBookByIdUpdatesTheSearchDB The new unit-test fails with a reason not expected before it was written. The `Library::filter()` operation returns a correct result after the call to `removeBookById()` (this was a surprise!) but it has a side-effect of re-adding an empty book with the id still surviving in the search DB (the emptiness of this re-created book doesn't allow it to pass the other filtering criteria, which explains why the result of `Library::filter()` is correct). Had to add a special check to the new unit-test against that hidden side-effect of `Library::removeBookById()` + `Library::filter()` combination. --- test/library.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/library.cpp b/test/library.cpp index beb6c2e6a..c19514163 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -310,4 +310,22 @@ TEST_F(XmlLibraryTest, removeBookByIdDropsTheReader) EXPECT_THROW(lib.getReaderById("raycharles"), std::out_of_range); }; +TEST_F(XmlLibraryTest, removeBookByIdUpdatesTheSearchDB) +{ + kiwix::Filter f; + f.local(true).valid(true).query(R"(title:"ray charles")", false); + + EXPECT_NO_THROW(lib.getBookById("raycharles")); + EXPECT_EQ(1U, lib.filter(f).size()); + + lib.removeBookById("raycharles"); + + EXPECT_THROW(lib.getBookById("raycharles"), std::out_of_range); + EXPECT_EQ(0U, lib.filter(f).size()); + + // make sure that Library::filter() doesn't add an empty book with + // an id surviving in the search DB + EXPECT_THROW(lib.getBookById("raycharles"), std::out_of_range); +}; + };