From d47c4fa72f94dd360be8cc2259cbf227fb4d9dff Mon Sep 17 00:00:00 2001
From: Nikhil Tanwar <2002nikhiltanwar@gmail.com>
Date: Sun, 23 Jul 2023 19:54:07 +0530
Subject: [PATCH] Unit tests for OPDS filtering by category
Added tests for multiple category filtering for zims
Added new test: catalog_v2_entries_filtered_by_category for entry filtering by category.
---
test/library_server.cpp | 83 ++++++++++++++++++++++++++++++++++-------
1 file changed, 69 insertions(+), 14 deletions(-)
diff --git a/test/library_server.cpp b/test/library_server.cpp
index 2274ccf4c..c9c34e367 100644
--- a/test/library_server.cpp
+++ b/test/library_server.cpp
@@ -301,20 +301,41 @@ TEST_F(LibraryServerTest, catalog_search_by_tag)
TEST_F(LibraryServerTest, catalog_search_by_category)
{
- const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?category=jazz");
- EXPECT_EQ(r->status, 200);
- EXPECT_EQ(maskVariableOPDSFeedData(r->body),
- OPDS_FEED_TAG
- " 12345678-90ab-cdef-1234-567890abcdef\n"
- "
Filtered zims (category=jazz)\n"
- " YYYY-MM-DDThh:mm:ssZ\n"
- " 1\n"
- " 0\n"
- " 1\n"
- CATALOG_LINK_TAGS
- CHARLES_RAY_CATALOG_ENTRY
- "\n"
- );
+
+ {
+ const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?category=jazz");
+ EXPECT_EQ(r->status, 200);
+ EXPECT_EQ(maskVariableOPDSFeedData(r->body),
+ OPDS_FEED_TAG
+ " 12345678-90ab-cdef-1234-567890abcdef\n"
+ " Filtered zims (category=jazz)\n"
+ " YYYY-MM-DDThh:mm:ssZ\n"
+ " 1\n"
+ " 0\n"
+ " 1\n"
+ CATALOG_LINK_TAGS
+ CHARLES_RAY_CATALOG_ENTRY
+ "\n"
+ );
+ }
+
+ {
+ const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?category=jazz,wikipedia");
+ EXPECT_EQ(r->status, 200);
+ EXPECT_EQ(maskVariableOPDSFeedData(r->body),
+ OPDS_FEED_TAG
+ " 12345678-90ab-cdef-1234-567890abcdef\n"
+ " Filtered zims (category=jazz%2Cwikipedia)\n"
+ " YYYY-MM-DDThh:mm:ssZ\n"
+ " 2\n"
+ " 0\n"
+ " 2\n"
+ CATALOG_LINK_TAGS
+ RAY_CHARLES_CATALOG_ENTRY
+ CHARLES_RAY_CATALOG_ENTRY
+ "\n"
+ );
+ }
}
TEST_F(LibraryServerTest, catalog_search_by_language)
@@ -793,6 +814,40 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_language)
}
}
+TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_category)
+{
+ {
+ const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?category=jazz");
+ EXPECT_EQ(r->status, 200);
+ EXPECT_EQ(maskVariableOPDSFeedData(r->body),
+ CATALOG_V2_ENTRIES_PREAMBLE("?category=jazz")
+ " Filtered Entries (category=jazz)\n"
+ " YYYY-MM-DDThh:mm:ssZ\n"
+ " 1\n"
+ " 0\n"
+ " 1\n"
+ CHARLES_RAY_CATALOG_ENTRY
+ "\n"
+ );
+ }
+
+ {
+ const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?category=jazz,wikipedia");
+ EXPECT_EQ(r->status, 200);
+ EXPECT_EQ(maskVariableOPDSFeedData(r->body),
+ CATALOG_V2_ENTRIES_PREAMBLE("?category=jazz%2Cwikipedia")
+ " Filtered Entries (category=jazz%2Cwikipedia)\n"
+ " YYYY-MM-DDThh:mm:ssZ\n"
+ " 2\n"
+ " 0\n"
+ " 2\n"
+ RAY_CHARLES_CATALOG_ENTRY
+ CHARLES_RAY_CATALOG_ENTRY
+ "\n"
+ );
+ }
+}
+
TEST_F(LibraryServerTest, catalog_v2_entries_multiple_filters)
{
{