Skip to content

Commit f30b1d2

Browse files
author
James Simone
committed
removing custom field and fleshed out tests
1 parent 9cff426 commit f30b1d2

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

src/classes/AccountRepository_Tests.cls

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ public class AccountRepository_Tests {
77
Account account = new Account();
88
account.FirstName = 'George' + i;
99
account.LastName = 'Washington';
10-
account.AladdinCustomerId__c = (Decimal)RandomizerUtils.generateInteger(10) + i;
1110

1211
accounts.add(account);
1312
}
1413

1514
insert accounts;
1615
}
1716

18-
@isTest
17+
@isTest
1918
static void it_should_return_an_account_by_id() {
19+
//Given I have a known account Id
20+
//When I query for that record in particular
21+
//Then it should be returned
2022
Account account = [SELECT Id FROM Account LIMIT 1];
2123

2224
Test.startTest();
@@ -25,4 +27,92 @@ public class AccountRepository_Tests {
2527

2628
System.assertEquals(account.Id,returnedAccount.Id);
2729
}
30+
31+
@isTest
32+
static void it_should_return_accounts_by_id_list() {
33+
//Given that I have known accounts
34+
//When I query for them by Id
35+
//Then the accounts should be returned
36+
37+
List<Account> expectedAccounts = [SELECT Id FROM Account];
38+
List<Id> expectedAccountIds = new List<Id>(new Map<Id, Account>(expectedAccounts).keySet());
39+
40+
Test.startTest();
41+
Map<Id,Account> returnedAccountsMap = new Map<Id,Account>(new AccountRepository().getById(expectedAccountIds));
42+
Test.stopTest();
43+
44+
System.assertEquals(expectedAccounts.size(),returnedAccountsMap.size());
45+
}
46+
47+
@isTest
48+
static void it_should_return_accounts_for_a_given_time_period() {
49+
//Given that I have accounts
50+
//When I query for them with a given field and time range
51+
//Then only accounts that match both those criteria should be returned
52+
List<Account> expectedAccounts = [SELECT Id FROM Account];
53+
54+
//Now create an account that should not be returned.
55+
Account account = TestDataGenerator.createPersonAccount();
56+
account.CreatedDate = System.today().addDays(-1);
57+
insert account;
58+
59+
Test.startTest();
60+
Schema.SObjectField source = Schema.Account.AccountSource;
61+
Map<Id,Account> returnedAccountsMap = new Map<Id,Account>(new AccountRepository().getByFieldAndTypeForGivenTimePeriod(source, 'Web', new DateLiterals().TODAY));
62+
Test.stopTest();
63+
64+
System.assertEquals(expectedAccounts.size(),returnedAccountsMap.size());
65+
for(Account acc : returnedAccountsMap.values()) {
66+
System.assertNotEquals(account.Id,acc.Id);
67+
}
68+
}
69+
70+
@isTest
71+
static void it_should_return_accounts_by_field_for_a_set_of_ids() {
72+
//Given I have a set of account Ids
73+
//When I query for those accounts and a specific field
74+
//Then the matching accounts should be returned
75+
List<Account> expectedAccounts = [SELECT Id FROM Account];
76+
Set<Id> accountIds = new Set<Id>(new List<Id>(new Map<Id,Account>(expectedAccounts).keySet()));
77+
78+
Test.startTest();
79+
Schema.SObjectField source = Schema.Account.AccountSource;
80+
List<Account> returnedAccounts = new AccountRepository().getByFieldForIds(source,'Web',accountIds);
81+
Test.stopTest();
82+
83+
System.assertEquals(expectedAccounts.size(),returnedAccounts.size());
84+
}
85+
86+
@isTest
87+
static void it_should_return_accounts_by_field_for_a_list_of_ids() {
88+
//Given I have a list of account Ids
89+
//When I query for those accounts and a specific field
90+
//Then the matching accounts should be returned
91+
List<Account> expectedAccounts = [SELECT Id FROM Account];
92+
List<Id> accountIds = new List<Id>(new Map<Id,Account>(expectedAccounts).keySet());
93+
94+
Test.startTest();
95+
Schema.SObjectField source = Schema.Account.AccountSource;
96+
List<Account> returnedAccounts = new AccountRepository().getByFieldForIds(source,'Web',accountIds);
97+
Test.stopTest();
98+
99+
System.assertEquals(expectedAccounts.size(),returnedAccounts.size());
100+
}
101+
102+
@isTest
103+
static void it_should_return_accounts_that_match_sosl_search_term() {
104+
//Given that I have a string
105+
//When I search accounts for that string
106+
//Then the accounts with a matching string should be returned
107+
108+
List<Account> expectedAccounts = (List<Account>)[FIND 'Web' IN ALL FIELDS RETURNING Account][0];
109+
110+
Test.startTest();
111+
Map<Id,Account> returnedAccountsMap = new Map<Id,Account>(new AccountRepository().searchInAllFields('Web'));
112+
Test.stopTest();
113+
114+
for(Account account : expectedAccounts) {
115+
System.assert(returnedAccountsMap.containsKey(account.Id));
116+
}
117+
}
28118
}

0 commit comments

Comments
 (0)