From 48a97bb6d188f5e7b613e7c10a0f3feb62219357 Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Thu, 27 Oct 2022 16:06:35 -0400 Subject: [PATCH] A few more changes related to fixing #393 - the ORDER BY statements have been removed in several queries because sorting didn't serve a functional purpose. Instead, the results are now sorted just in the tests to help with asserting on the returned values Thanks to @jamessimone for pointing out that the ORDER BY statements weren't really needed in the first place & have a QoL impact --- .../classes/LogManagementDataSelector.cls | 10 +++---- .../LogManagementDataSelector_Tests.cls | 27 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls b/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls index 486578114..70b957837 100644 --- a/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls +++ b/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls @@ -231,7 +231,7 @@ public without sharing virtual class LogManagementDataSelector { * @return The list of matching `Profile` records */ public virtual List getProfilesById(List profileIds) { - return [SELECT Id, Name FROM Profile WHERE Id IN :profileIds ORDER BY Name]; + return [SELECT Id, Name FROM Profile WHERE Id IN :profileIds]; } /** @@ -240,7 +240,7 @@ public without sharing virtual class LogManagementDataSelector { * @return The list of matching `Profile` records */ public virtual List getProfilesByNameSearch(String searchTerm) { - return [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm ORDER BY Name]; + return [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm]; } /** @@ -299,7 +299,7 @@ public without sharing virtual class LogManagementDataSelector { * @return The list of matching `User` records */ public virtual List getUsersById(List userIds) { - return [SELECT Id, Username FROM User WHERE Id IN :userIds ORDER BY Username]; + return [SELECT Id, Username FROM User WHERE Id IN :userIds]; } /** @@ -308,7 +308,7 @@ public without sharing virtual class LogManagementDataSelector { * @return The list of matching `User` records */ public virtual List getUsersByNameSearch(String searchTerm) { - return [SELECT Id, Name, Username, SmallPhotoUrl FROM User WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm ORDER BY Username]; + return [SELECT Id, Name, Username, SmallPhotoUrl FROM User WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm]; } /** @@ -317,7 +317,7 @@ public without sharing virtual class LogManagementDataSelector { * @return Tje list of matching `User` records */ public virtual List getUsersByUsername(List usernames) { - return [SELECT Id, Username FROM User WHERE Username IN :userNames ORDER BY Username]; + return [SELECT Id, Username FROM User WHERE Username IN :userNames]; } @TestVisible diff --git a/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls index 629447f06..e1dfc3335 100644 --- a/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls @@ -3,7 +3,7 @@ // See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // //------------------------------------------------------------------------------------------------// -@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions') +@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.MethodNamingConventions') @IsTest(IsParallel=false) private class LogManagementDataSelector_Tests { @IsTest @@ -212,21 +212,25 @@ private class LogManagementDataSelector_Tests { @IsTest static void it_returns_profiles_for_specified_profile_ids() { - List expectedResults = [SELECT Id, Name FROM Profile ORDER BY Name LIMIT 3]; + List expectedResults = [SELECT Id, Name FROM Profile LIMIT 10]; List targetProfileIds = new List(new Map(expectedResults).keySet()); List returnedResults = LogManagementDataSelector.getInstance().getProfilesById(targetProfileIds); + expectedResults.sort(); + returnedResults.sort(); System.assertEquals(expectedResults, returnedResults); } @IsTest static void it_returns_profiles_for_specified_search_term() { String searchTerm = 'Admin'; - List expectedResults = [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm ORDER BY Name]; + List expectedResults = [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm]; List returnedResults = LogManagementDataSelector.getInstance().getProfilesByNameSearch(searchTerm); + expectedResults.sort(); + returnedResults.sort(); System.assertEquals(expectedResults, returnedResults); } @@ -313,32 +317,31 @@ private class LogManagementDataSelector_Tests { @IsTest static void it_returns_users_for_user_ids() { - List expectedResults = [SELECT Id, Username FROM User ORDER BY Username LIMIT 3]; + List expectedResults = [SELECT Id, Username FROM User LIMIT 3]; List targetUserIds = new List(new Map(expectedResults).keySet()); List returnedResults = LogManagementDataSelector.getInstance().getUsersById(targetUserIds); + expectedResults.sort(); + returnedResults.sort(); System.assertEquals(expectedResults, returnedResults); } @IsTest static void it_returns_user_for_specified_search_term() { String searchTerm = UserInfo.getLastName(); - List expectedResults = [ - SELECT Id, Name, Username, SmallPhotoUrl - FROM User - WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm - ORDER BY Username - ]; + List expectedResults = [SELECT Id, Name, Username, SmallPhotoUrl FROM User WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm]; List returnedResults = LogManagementDataSelector.getInstance().getUsersByNameSearch(searchTerm); + expectedResults.sort(); + returnedResults.sort(); System.assertEquals(expectedResults, returnedResults); } @IsTest static void it_returns_users_for_user_usernames() { - List expectedResults = [SELECT Id, Username FROM User ORDER BY Username LIMIT 3]; + List expectedResults = [SELECT Id, Username FROM User LIMIT 3]; List targetUserUsernames = new List(); for (User user : expectedResults) { targetUserUsernames.add(user.Username); @@ -346,6 +349,8 @@ private class LogManagementDataSelector_Tests { List returnedResults = LogManagementDataSelector.getInstance().getUsersByUsername(targetUserUsernames); + expectedResults.sort(); + returnedResults.sort(); System.assertEquals(expectedResults, returnedResults); }