|
|
@@ -929,6 +929,39 @@ TEST_F(ApiFixture, IndexCreateRequiresField) {
|
|
|
ASSERT_TRUE(bad); EXPECT_EQ(bad->status, 422);
|
|
|
}
|
|
|
|
|
|
+TEST_F(ApiFixture, IndexValuesReturnsFacetCounts) {
|
|
|
+ auto c = admin();
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","facets"},{"kind","json"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ std::string docs = base + "/facets/documents";
|
|
|
+ for (const char* st : {"open", "open", "closed"})
|
|
|
+ ASSERT_EQ(c.Post(docs.c_str(), nlohmann::json{{"status", st}}.dump(), "application/json")->status, 201);
|
|
|
+ ASSERT_EQ(c.Post((base + "/facets/indexes").c_str(),
|
|
|
+ nlohmann::json{{"field","status"}}.dump(), "application/json")->status, 201);
|
|
|
+
|
|
|
+ auto r = c.Get((base + "/facets/indexes/status/values").c_str());
|
|
|
+ ASSERT_TRUE(r); EXPECT_EQ(r->status, 200);
|
|
|
+ auto body = nlohmann::json::parse(r->body);
|
|
|
+ uint64_t open = 0, closed = 0;
|
|
|
+ for (auto& e : body["values"]) {
|
|
|
+ if (e["value"] == "open") open = e["count"].get<uint64_t>();
|
|
|
+ if (e["value"] == "closed") closed = e["count"].get<uint64_t>();
|
|
|
+ }
|
|
|
+ EXPECT_EQ(open, 2u);
|
|
|
+ EXPECT_EQ(closed, 1u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(ApiFixture, IndexValuesEmptyForUnindexedField) {
|
|
|
+ auto c = admin();
|
|
|
+ std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(), nlohmann::json{{"name","nofacet"},{"kind","json"}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ auto r = c.Get((base + "/nofacet/indexes/whatever/values").c_str());
|
|
|
+ ASSERT_TRUE(r); EXPECT_EQ(r->status, 200);
|
|
|
+ EXPECT_TRUE(nlohmann::json::parse(r->body)["values"].empty());
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(ApiFixture, UniqueIndexRejectsExistingDuplicates) {
|
|
|
auto c = admin();
|
|
|
std::string base = "/api/v1/projects/" + project_ + "/collections";
|