Last active
April 27, 2023 13:09
-
-
Save asmitakhare/9680b371da636cb13a0e7d00e889d828 to your computer and use it in GitHub Desktop.
WeekFiveHomework
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 { | |
@isTest | |
static void testBeforeRecipeInsertOrUpdateWithDraftTrue(){ | |
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' ]; | |
system.assert(r.Draft__c == true, 'Draft not true'); | |
} | |
@isTest | |
static void testBeforeRecipeInsertOrUpdateWithDraftFalse(){ | |
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, | |
Description__c = 'first time making' | |
); | |
relist.add(rec); | |
insert relist; | |
Recipe__c r = [Select Id, Complexity__c, Draft__c From Recipe__c Where Name = 'Fist Test' ]; | |
system.assert(r.Draft__c == false, 'Draft not false'); | |
system.assert(r.Complexity__c =='Simple', 'Complexity is not simple'); | |
} | |
@isTest | |
static void testAfterRecipeUpdate(){ | |
//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.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' ]; | |
System.assert(recipeUsage.Recipe__r.Name == 'Chicken parme' && recipeUsage.Cookbook__r.Name == 'Second cook book', 'recipe usage record' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment