Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
jongpie committed Oct 27, 2022

Verified

This commit was signed with the committer’s verified signature.
jongpie Jonathan Gillespie
1 parent 4aae893 commit 77f2e1f
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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];
}

/**
@@ -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];
}

/**
@@ -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];
}

/**
@@ -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];
}

/**
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}

@@ -313,11 +317,13 @@ 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);
}

@@ -328,24 +334,27 @@ private class LogManagementDataSelector_Tests {
SELECT Id, Name, Username, SmallPhotoUrl
FROM User
WHERE Name LIKE :searchTerm OR Username LIKE :searchTerm
ORDER BY Username
];

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);
}

0 comments on commit 77f2e1f

Please sign in to comment.