Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. global class setExams2Expired implements Schedulable {
  2. global void execute(SchedulableContext ctx) {
  3.  
  4. List<Certification__c> objects = [
  5. SELECT Id, Expiration_Date__c, Exam_state__c
  6. FROM Certification__c
  7. WHERE Exam_state__c in ('Active')];
  8.  
  9. for(Certification__c c : objects){
  10. if(c.Expiration_Date__c < date.today()){
  11. c.Exam_state__c = 'Expired';
  12. }
  13. else if(c.Expiration_Date__c == date.today().addDays(+7)){
  14. c.Day7ExpiryAlert__c = True;
  15. }
  16. }
  17. update objects;
  18. }
  19. }
  20.  
  21. @isTest
  22. public class setExams2ExpiredTest {
  23. @isTest
  24. public static void ifNotExpired() {
  25.  
  26. Account acc1 = new Account(name='Test Account 1',phone='121212', Global_POD__c ='AP');
  27. insert acc1;
  28. Account acc2 = new Account(name='Test Account 2',phone='343434', Global_POD__c ='AP');
  29. insert acc2;
  30.  
  31. Contact con1 = new Contact(accountid=acc1.id,lastname='Test Contact 1',email='abcd@gmail.com');
  32. insert con1;
  33. Contact con2 = new Contact(accountid=acc2.id,lastname='Test Contact 2',email='efgh@gmail.com');
  34. insert con2;
  35.  
  36. Certification__c c = new Certification__c(Contact__c=con1.id, Name = 'abcd', Expiration_Date__c = Date.today().addDays(+2), Exam_state__c = 'Active');
  37. insert c;
  38.  
  39. Test.startTest();
  40. setExams2Expired ctx = new setExams2Expired();
  41. ctx.execute(null);
  42. System.assertEquals('Active','Active','ifNotExpired doesn't work - meaning an exam is either set to expired when it shouldn't have been or nothing happenend for a certain record');
  43. Test.stopTest();
  44. }
  45. @isTest
  46. public static void sendEmail(){
  47.  
  48. Account acc5 = new Account(name='Test Account 5',phone='787878', Global_POD__c ='AP');
  49. insert acc5;
  50. Account acc6 = new Account(name='Test Account 6',phone='898989', Global_POD__c ='AP');
  51. insert acc6;
  52.  
  53. Contact con5 = new Contact(accountid=acc5.id,lastname='Test Contact 5',email='qrstuv@gmail.com');
  54. insert con5;
  55. Contact con6 = new Contact(accountid=acc6.id,lastname='Test Contact 6',email='wxyz@gmail.com');
  56. insert con6;
  57.  
  58. Certification__c c = new Certification__c(Contact__c=con5.id, Name = 'efgh', Expiration_Date__c = Date.today().addDays(+7), Exam_state__c = 'Active', Day7ExpiryAlert__c = false);
  59. insert c;
  60.  
  61. Test.startTest();
  62. setExams2Expired ctx = new setExams2Expired();
  63. ctx.execute(null);
  64. System.assertEquals(false, false,'No alert was sent here');
  65. Test.stopTest();
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement