From 1fc006f639c291d7ffd5cec1b47de35fdd24c27f Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Tue, 5 Mar 2024 15:54:23 +0400
Subject: [PATCH 1/4] Deduplicated test data in two test points
This was mainly done to prevent further duplication of test data as more
test points around the same query are added next but is also useful on
its own.
---
test/server_search.cpp | 51 +++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/test/server_search.cpp b/test/server_search.cpp
index de8cd9046..6d57e1f8d 100644
--- a/test/server_search.cpp
+++ b/test/server_search.cpp
@@ -194,6 +194,23 @@ struct SearchResult
SearchResult{LINK, TITLE, SNIPPET, BOOK_TITLE, WORDCOUNT}
+const SearchResult SEARCH_RESULT_FOR_TRAVEL_IN_RAYCHARLESZIM {
+ /*link*/ "/ROOT%23%3F/content/zimfile/A/If_You_Go_Away",
+ /*title*/ "If You Go Away",
+ /*snippet*/ R"SNIPPET(...Travel On" (1965) "If You Go Away" (1966) "Walk Away" (1967) Damita Jo reached #10 on the Adult Contemporary chart and #68 on the Billboard Hot 100 in 1966 for her version of the song. Terry Jacks recorded a version of the song which was released as a single in 1974 and reached #29 on the Adult Contemporary chart, #68 on the Billboard Hot 100, and went to #8 in the UK. The complex melody is partly derivative of classical music - the poignant "But if you stay..." passage comes from Franz Liszt's......)SNIPPET",
+ /*bookTitle*/ "Ray Charles",
+ /*wordCount*/ "204"
+};
+
+
+const SearchResult SEARCH_RESULT_FOR_TRAVEL_IN_EXAMPLEZIM {
+ /*link*/ "/ROOT%23%3F/content/example/Wikibooks.html",
+ /*title*/ "Wikibooks",
+ /*snippet*/ R"SNIPPET(...Travel guide Wikidata Knowledge database Commons Media repository Meta Coordination MediaWiki MediaWiki software Phabricator MediaWiki bug tracker Wikimedia Labs MediaWiki development The Wikimedia Foundation is a non-profit organization that depends on your voluntarism and donations to operate. If you find Wikibooks or other projects hosted by the Wikimedia Foundation useful, please volunteer or make a donation. Your donations primarily helps to purchase server equipment, launch new projects......)SNIPPET",
+ /*bookTitle*/ "Wikibooks",
+ /*wordCount*/ "538"
+};
+
const std::vector LARGE_SEARCH_RESULTS = {
SEARCH_RESULT(
@@ -1342,21 +1359,8 @@ TEST(ServerSearchTest, searchResults)
/* totalResultCount */ 2,
/* firstResultIndex */ 1,
/* results */ {
- SEARCH_RESULT(
- /*link*/ "/ROOT%23%3F/content/zimfile/A/If_You_Go_Away",
- /*title*/ "If You Go Away",
- /*snippet*/ R"SNIPPET(...Travel On" (1965) "If You Go Away" (1966) "Walk Away" (1967) Damita Jo reached #10 on the Adult Contemporary chart and #68 on the Billboard Hot 100 in 1966 for her version of the song. Terry Jacks recorded a version of the song which was released as a single in 1974 and reached #29 on the Adult Contemporary chart, #68 on the Billboard Hot 100, and went to #8 in the UK. The complex melody is partly derivative of classical music - the poignant "But if you stay..." passage comes from Franz Liszt's......)SNIPPET",
- /*bookTitle*/ "Ray Charles",
- /*wordCount*/ "204"
- ),
-
- SEARCH_RESULT(
- /*link*/ "/ROOT%23%3F/content/example/Wikibooks.html",
- /*title*/ "Wikibooks",
- /*snippet*/ R"SNIPPET(...Travel guide Wikidata Knowledge database Commons Media repository Meta Coordination MediaWiki MediaWiki software Phabricator MediaWiki bug tracker Wikimedia Labs MediaWiki development The Wikimedia Foundation is a non-profit organization that depends on your voluntarism and donations to operate. If you find Wikibooks or other projects hosted by the Wikimedia Foundation useful, please volunteer or make a donation. Your donations primarily helps to purchase server equipment, launch new projects......)SNIPPET",
- /*bookTitle*/ "Wikibooks",
- /*wordCount*/ "538"
- )
+ SEARCH_RESULT_FOR_TRAVEL_IN_RAYCHARLESZIM,
+ SEARCH_RESULT_FOR_TRAVEL_IN_EXAMPLEZIM
},
/* pagination */ {}
},
@@ -1369,21 +1373,8 @@ TEST(ServerSearchTest, searchResults)
/* totalResultCount */ 2,
/* firstResultIndex */ 1,
/* results */ {
- SEARCH_RESULT(
- /*link*/ "/ROOT%23%3F/content/zimfile/A/If_You_Go_Away",
- /*title*/ "If You Go Away",
- /*snippet*/ R"SNIPPET(...Travel On" (1965) "If You Go Away" (1966) "Walk Away" (1967) Damita Jo reached #10 on the Adult Contemporary chart and #68 on the Billboard Hot 100 in 1966 for her version of the song. Terry Jacks recorded a version of the song which was released as a single in 1974 and reached #29 on the Adult Contemporary chart, #68 on the Billboard Hot 100, and went to #8 in the UK. The complex melody is partly derivative of classical music - the poignant "But if you stay..." passage comes from Franz Liszt's......)SNIPPET",
- /*bookTitle*/ "Ray Charles",
- /*wordCount*/ "204"
- ),
-
- SEARCH_RESULT(
- /*link*/ "/ROOT%23%3F/content/example/Wikibooks.html",
- /*title*/ "Wikibooks",
- /*snippet*/ R"SNIPPET(...Travel guide Wikidata Knowledge database Commons Media repository Meta Coordination MediaWiki MediaWiki software Phabricator MediaWiki bug tracker Wikimedia Labs MediaWiki development The Wikimedia Foundation is a non-profit organization that depends on your voluntarism and donations to operate. If you find Wikibooks or other projects hosted by the Wikimedia Foundation useful, please volunteer or make a donation. Your donations primarily helps to purchase server equipment, launch new projects......)SNIPPET",
- /*bookTitle*/ "Wikibooks",
- /*wordCount*/ "538"
- )
+ SEARCH_RESULT_FOR_TRAVEL_IN_RAYCHARLESZIM,
+ SEARCH_RESULT_FOR_TRAVEL_IN_EXAMPLEZIM
},
/* pagination */ {}
},
From d8b4c1584c3687ad7a6d0dc29b2afdb83bd84576 Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Tue, 5 Mar 2024 16:41:35 +0400
Subject: [PATCH 2/4] Testing of filtering during search by books.name
---
test/data/lib_for_server_search_test.xml | 2 +-
test/server_search.cpp | 30 ++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/test/data/lib_for_server_search_test.xml b/test/data/lib_for_server_search_test.xml
index 994c6a6fa..019d46aba 100644
--- a/test/data/lib_for_server_search_test.xml
+++ b/test/data/lib_for_server_search_test.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/test/server_search.cpp b/test/server_search.cpp
index 6d57e1f8d..37c001141 100644
--- a/test/server_search.cpp
+++ b/test/server_search.cpp
@@ -1379,6 +1379,36 @@ TEST(ServerSearchTest, searchResults)
/* pagination */ {}
},
+ // books.name filters by the name of the ZIM file
+ {
+ /* query */ "pattern=travel"
+ "&books.name=zimfile",
+ /* start */ 0,
+ /* resultsPerPage */ 10,
+ /* totalResultCount */ 1,
+ /* firstResultIndex */ 1,
+ /* results */ {
+ SEARCH_RESULT_FOR_TRAVEL_IN_RAYCHARLESZIM
+ },
+
+ /* pagination */ {}
+ },
+
+ // books.name filters by the name of the ZIM file
+ {
+ /* query */ "pattern=travel"
+ "&books.name=example",
+ /* start */ 0,
+ /* resultsPerPage */ 10,
+ /* totalResultCount */ 1,
+ /* firstResultIndex */ 1,
+ /* results */ {
+ SEARCH_RESULT_FOR_TRAVEL_IN_EXAMPLEZIM
+ },
+
+ /* pagination */ {}
+ },
+
// Adding a book (without match) doesn't change the results
{
/* query */ "pattern=jazz"
From 6ef4f6396ee6d09d43884f3f117b67d85ce8be5e Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Tue, 5 Mar 2024 16:42:14 +0400
Subject: [PATCH 3/4] Testing of filtering during search by books.filter.name
---
test/server_search.cpp | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/test/server_search.cpp b/test/server_search.cpp
index 37c001141..06f35aba7 100644
--- a/test/server_search.cpp
+++ b/test/server_search.cpp
@@ -1409,6 +1409,36 @@ TEST(ServerSearchTest, searchResults)
/* pagination */ {}
},
+ // books.filter.name filters by the book name
+ {
+ /* query */ "pattern=travel"
+ "&books.filter.name=wikipedia_en_ray_charles",
+ /* start */ 0,
+ /* resultsPerPage */ 10,
+ /* totalResultCount */ 1,
+ /* firstResultIndex */ 1,
+ /* results */ {
+ SEARCH_RESULT_FOR_TRAVEL_IN_RAYCHARLESZIM
+ },
+
+ /* pagination */ {}
+ },
+
+ // books.filter.name filters by the book name
+ {
+ /* query */ "pattern=travel"
+ "&books.filter.name=bookname_of_example_zim",
+ /* start */ 0,
+ /* resultsPerPage */ 10,
+ /* totalResultCount */ 1,
+ /* firstResultIndex */ 1,
+ /* results */ {
+ SEARCH_RESULT_FOR_TRAVEL_IN_EXAMPLEZIM
+ },
+
+ /* pagination */ {}
+ },
+
// Adding a book (without match) doesn't change the results
{
/* query */ "pattern=jazz"
From e3fffd9b234eb83ad2719d20b6876e312785da8d Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Tue, 5 Mar 2024 17:18:31 +0400
Subject: [PATCH 4/4] Negative tests for books selection during search
---
test/server_search.cpp | 69 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 4 deletions(-)
diff --git a/test/server_search.cpp b/test/server_search.cpp
index 06f35aba7..4759a0c36 100644
--- a/test/server_search.cpp
+++ b/test/server_search.cpp
@@ -1572,7 +1572,10 @@ TEST(ServerSearchTest, searchResults)
}
}
-std::string expectedConfusionOfTonguesErrorHtml(std::string url)
+std::string invalidRequestErrorHtml(std::string url,
+ std::string errorMsgId,
+ std::string errorMsgParamsJSON,
+ std::string errorText)
{
return R"(
@@ -1581,7 +1584,7 @@ std::string expectedConfusionOfTonguesErrorHtml(std::string url)
Invalid request
@@ -1590,19 +1593,30 @@ std::string expectedConfusionOfTonguesErrorHtml(std::string url)
The requested URL ")" + url + R"(" is not a valid request.
- Two or more books in different languages would participate in search, which may lead to confusing results.
+ )" + errorText + R"(