Last active
May 4, 2023 01:06
-
-
Save asmitakhare/fa257906e369cfa9b2f951debbfcbca1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private with sharing class RecipeTriggerHandler_Test { | |
//showing an error message when Draft__c is not true. | |
@isTest | |
static void testNegativeBeforeRecipeInsertOrUpdate(){ | |
List<Recipe__c> relist = new List<Recipe__c>(); | |
Recipe__c rec = new Recipe__c(Name = 'Fist Test', | |
Active_Time__c = 20, | |
Active_Time_Units__c = 'Minutes', | |
Servings__c = 2 | |
); | |
relist.add(rec); | |
insert relist; | |
Recipe__c r = [Select Id, Draft__c From Recipe__c Where Name = 'Fist Test' ]; | |
if(r.Draft__c == true){ | |
r.addError ('Draft is not checked because required field Description__c is missing value'); | |
} | |
} | |
@isTest | |
static void testNegativeAfterRecipeUpdate(){ | |
//create Recipe__c record | |
Recipe__c r = new Recipe__c ( | |
Name = 'Chicken parme', | |
Active_Time__c = 60, | |
Active_Time_Units__c = 'Minutes', | |
Servings__c = 3, | |
Description__c = 'first time making' | |
); | |
insert r; | |
//create cookbook__c record and have that use in Recipe_Usage__c | |
Cookbook__c c = new Cookbook__c(Name= 'Second cook book'); | |
insert c; | |
//create Recipe_Usage__c record and have same id from recipe and cookbook__c record you created | |
Recipe_Usage__c recUsage = new Recipe_Usage__c(); | |
recUsage.Cookbook__c = c.Id; | |
recUsage.Recipe__c = r.Id; | |
insert recUsage; | |
Recipe_Usage__c recipeUsage = [ SELECT Recipe__r.Id, Recipe__r.Draft__c, Recipe__r.Name, Cookbook__r.Name, Cookbook__r.Id, Cookbook__r.OwnerId | |
FROM Recipe_Usage__c Where Recipe__r.Name= 'Chicken parme' And Cookbook__r.Name = 'Second cook book' ]; | |
if(recipeUsage.Recipe__r.Draft__c == true){ | |
recipeUsage.addError('Task will not get created as Draft is true'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment