Skip to content

Commit

Permalink
Add groupByDate test
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlic committed Oct 22, 2021
1 parent 0a71ffc commit 8d4c39b
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private class SObjectCollectionTest {
}

@IsTest
private static void pluckIdsWithARelationReturnsIds() {
private static void pluckIdsWithRelationReturnsIds() {
Account fooAccount = new Account(Id = TestUtility.getTestId(Account.SObjectType));
Account barAccount = new Account(Id = TestUtility.getTestId(Account.SObjectType));
List<Opportunity> opportunities = new List<Opportunity>{
Expand All @@ -49,6 +49,38 @@ private class SObjectCollectionTest {
System.assertEquals(barAccount.Id, accountIds[1]);
}

@IsTest
private static void groupByDatesGroupsWithApiFieldName() {
Date today = Date.today();
SObjectCollection c = SObjectCollection.of(new List<Opportunity>{
new Opportunity(
CloseDate = today,
Name = 'Today'
),
new Opportunity(
CloseDate = today,
Name = 'Today'
),
new Opportunity(
CloseDate = today.addDays(1),
Name = 'Tomorrow'
)
});
Map<Date, List<Opportunity>> oppsByDate = c.groupByDates(Opportunity.CloseDate);
System.assertEquals(2, oppsByDate.size());
List<Opportunity> todaysOpps = oppsByDate.get(today);
System.assertEquals(2, todaysOpps.size());
for (Opportunity o : todaysOpps) {
System.assertEquals('Today', o.Name);
}

List<Opportunity> tomorrowsOpps = oppsByDate.get(today.addDays(1));
System.assertEquals(1, tomorrowsOpps.size());
for (Opportunity o : tomorrowsOpps) {
System.assertEquals('Tomorrow', o.Name);
}
}

@IsTest
private static void testAsMap() {
Map<Id, SObject> recordMap = SObjectCollection.of(testAccounts()).asMap();
Expand Down

0 comments on commit 8d4c39b

Please sign in to comment.