Fix getting default group when no metadata is loaded

This commit is contained in:
Oliver Hamlet
2018-03-18 08:55:33 +00:00
parent e7526b2ac4
commit a178bf3adb
2 changed files with 16 additions and 1 deletions
+6 -1
View File
@@ -163,7 +163,12 @@ std::vector<Message> ApiDatabase::GetGeneralMessages(
std::unordered_set<Group> ApiDatabase::GetGroups(bool includeUserMetadata) const {
if (!includeUserMetadata) {
return masterlist_.Groups();
auto groups = masterlist_.Groups();
//Insert the default group in case the masterlist hasn't been loaded.
groups.insert(Group());
return groups;
}
std::unordered_set<Group> mergedGroups;
@@ -460,6 +460,16 @@ TEST_P(DatabaseInterfaceTest,
EXPECT_EQ(std::unordered_set<std::string>({ "group1" }), groups.find(Group("group2"))->GetAfterGroups());
}
TEST_P(DatabaseInterfaceTest,
getGroupsShouldReturnDefaultGroupIfNoMasterlistIsLoadedAndUserlistMetadataIsNotIncluded) {
auto groups = db_->GetGroups(false);
EXPECT_EQ(1, groups.size());
EXPECT_EQ("default", groups.begin()->GetName());
EXPECT_TRUE(groups.begin()->GetAfterGroups().empty());
}
TEST_P(DatabaseInterfaceTest,
getUserGroupsShouldReturnOnlyGroupMetadataFromTheUserlist) {
ASSERT_NO_THROW(GenerateMasterlist());