M module-db/Tables/ContactsTable.cpp => module-db/Tables/ContactsTable.cpp +10 -19
@@ 277,16 277,17 @@ std::vector<std::uint32_t> ContactsTable::GetIDsSortedByField(
"contact_match_groups.group_id = " +
std::to_string(groupId);
+ constexpr auto exclude_temporary = " WHERE contacts._id not in ( "
+ " SELECT cmg.contact_id "
+ " FROM contact_match_groups cmg, contact_groups cg "
+ " WHERE cmg.group_id = cg._id "
+ " AND cg.name = 'Temporary' "
+ " ) ";
+
switch (matchType) {
case MatchType::Name: {
+ query += exclude_temporary;
if (!name.empty()) {
- query += " WHERE contacts._id not in ( "
- " SELECT cmg.contact_id "
- " FROM contact_match_groups cmg, contact_groups cg "
- " WHERE cmg.group_id = cg._id "
- " AND cg.name = 'Temporary' "
- " ) ";
-
query += " AND ( contact_name.name_primary || ' ' || contact_name.name_alternative LIKE '" + name + "%%'";
query += " OR contact_name.name_alternative || ' ' || contact_name.name_primary LIKE '" + name + "%%')";
}
@@ 297,13 298,8 @@ std::vector<std::uint32_t> ContactsTable::GetIDsSortedByField(
query += " INNER JOIN contact_number ON contact_number.contact_id == contacts._id AND "
"contact_number.number_user LIKE '%%" +
name + "%%'";
- query += " WHERE contacts._id not in ( "
- " SELECT cmg.contact_id "
- " FROM contact_match_groups cmg, contact_groups cg "
- " WHERE cmg.group_id = cg._id "
- " AND cg.name = 'Temporary' "
- " ) ";
}
+ query += exclude_temporary;
} break;
case MatchType::Group:
@@ 311,12 307,7 @@ std::vector<std::uint32_t> ContactsTable::GetIDsSortedByField(
break;
case MatchType::None: {
- query += " WHERE contacts._id not in ( "
- " SELECT cmg.contact_id "
- " FROM contact_match_groups cmg, contact_groups cg "
- " WHERE cmg.group_id = cg._id "
- " AND cg.name = 'Temporary' "
- " ) ";
+ query += exclude_temporary;
} break;
}
M module-db/tests/ContactsTable_tests.cpp => module-db/tests/ContactsTable_tests.cpp +12 -5
@@ 21,11 21,11 @@ TEST_CASE("Contacts Table tests")
REQUIRE(contactsdb.isInitialized());
ContactsTableRow testRow1 = {{.ID = DB_ID_NONE},
- .nameID = DB_ID_NONE,
- .numbersID = "0 1 2 3 4",
- .ringID = DB_ID_NONE,
- .addressID = DB_ID_NONE,
- .speedDial = "666"
+ .nameID = DB_ID_NONE,
+ .numbersID = "0 1 2 3 4",
+ .ringID = DB_ID_NONE,
+ .addressID = DB_ID_NONE,
+ .speedDial = "666"
};
@@ 62,6 62,13 @@ TEST_CASE("Contacts Table tests")
auto retOffsetLimitBigger = contactsdb.contacts.getLimitOffset(0, 100);
REQUIRE(retOffsetLimitBigger.size() == 4);
+ auto sortedRetOffsetLimitBigger =
+ contactsdb.contacts.GetIDsSortedByField(ContactsTable::MatchType::Name, "", 1, 100, 0);
+ REQUIRE(sortedRetOffsetLimitBigger.size() == 4);
+
+ sortedRetOffsetLimitBigger = contactsdb.contacts.GetIDsSortedByName(1, 100);
+ REQUIRE(sortedRetOffsetLimitBigger.size() == 4);
+
// Get table rows using invalid offset/limit parameters(should return empty object)
auto retOffsetLimitFailed = contactsdb.contacts.getLimitOffset(5, 4);
REQUIRE(retOffsetLimitFailed.size() == 0);
M test/pytest/service-desktop/test_contacts.py => test/pytest/service-desktop/test_contacts.py +11 -0
@@ 25,6 25,17 @@ def test_contacts(harness):
assert contacts_length
assert contacts_length == count
+ # try to get more than available
+ body = {"count": 10 + count}
+ ret = harness.endpoint_request("contacts", "get", body)
+ assert ret["status"] == status["OK"]
+
+ contacts = ret["body"]
+ contacts_length = len(contacts)
+ assert contacts_length
+ assert contacts_length == count
+
+
# adding new contact
body = {"address": "6 Czeczota St.\n02600 Warsaw",
"altName": "Testowy",