Skip to content

Commit

Permalink
A few more changes related to fixing #393 - the ORDER BY statements h…
Browse files Browse the repository at this point in the history
…ave 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
  • Loading branch information
jongpie committed Oct 28, 2022
1 parent 4aae893 commit 48a97bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return The list of matching `Profile` records
*/
public virtual List<Profile> getProfilesById(List<Id> profileIds) {
return [SELECT Id, Name FROM Profile WHERE Id IN :profileIds ORDER BY Name];
return [SELECT Id, Name FROM Profile WHERE Id IN :profileIds];
}

/**
Expand All @@ -240,7 +240,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return The list of matching `Profile` records
*/
public virtual List<Profile> 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];
}

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return The list of matching `User` records
*/
public virtual List<User> getUsersById(List<Id> userIds) {
return [SELECT Id, Username FROM User WHERE Id IN :userIds ORDER BY Username];
return [SELECT Id, Username FROM User WHERE Id IN :userIds];
}

/**
Expand All @@ -308,7 +308,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return The list of matching `User` records
*/
public virtual List<User> 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];
}

/**
Expand All @@ -317,7 +317,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return Tje list of matching `User` records
*/
public virtual List<User> getUsersByUsername(List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -212,21 +212,25 @@ private class LogManagementDataSelector_Tests {

@IsTest
static void it_returns_profiles_for_specified_profile_ids() {
List<Profile> expectedResults = [SELECT Id, Name FROM Profile ORDER BY Name LIMIT 3];
List<Profile> expectedResults = [SELECT Id, Name FROM Profile LIMIT 10];
List<Id> targetProfileIds = new List<Id>(new Map<Id, Profile>(expectedResults).keySet());

List<Profile> 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<Profile> expectedResults = [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm ORDER BY Name];
List<Profile> expectedResults = [SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE :searchTerm];

List<Profile> returnedResults = LogManagementDataSelector.getInstance().getProfilesByNameSearch(searchTerm);

expectedResults.sort();
returnedResults.sort();
System.assertEquals(expectedResults, returnedResults);
}

Expand Down Expand Up @@ -313,39 +317,40 @@ private class LogManagementDataSelector_Tests {

@IsTest
static void it_returns_users_for_user_ids() {
List<User> expectedResults = [SELECT Id, Username FROM User ORDER BY Username LIMIT 3];
List<User> expectedResults = [SELECT Id, Username FROM User LIMIT 3];
List<Id> targetUserIds = new List<Id>(new Map<Id, User>(expectedResults).keySet());

List<User> 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<User> expectedResults = [
SELECT Id, Name, Username, SmallPhotoUrl
FROM User
WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm
ORDER BY Username
];
List<User> expectedResults = [SELECT Id, Name, Username, SmallPhotoUrl FROM User WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm];

List<User> returnedResults = LogManagementDataSelector.getInstance().getUsersByNameSearch(searchTerm);

expectedResults.sort();
returnedResults.sort();
System.assertEquals(expectedResults, returnedResults);
}

@IsTest
static void it_returns_users_for_user_usernames() {
List<User> expectedResults = [SELECT Id, Username FROM User ORDER BY Username LIMIT 3];
List<User> expectedResults = [SELECT Id, Username FROM User LIMIT 3];
List<String> targetUserUsernames = new List<String>();
for (User user : expectedResults) {
targetUserUsernames.add(user.Username);
}

List<User> returnedResults = LogManagementDataSelector.getInstance().getUsersByUsername(targetUserUsernames);

expectedResults.sort();
returnedResults.sort();
System.assertEquals(expectedResults, returnedResults);
}

Expand Down

0 comments on commit 48a97bb

Please sign in to comment.