-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUpdateCMDTest.cls
133 lines (105 loc) · 4.91 KB
/
UpdateCMDTest.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@isTest
public class UpdateCMDTest {
@IsTest
public static void configSetupTest(){
String fullName = 'Email_To_Lead__mdt.Email_To_Lead_Config';
String label = 'Email To Lead Config';
String values = '{' +
' "Lead_Source__c": "Email",' +
' "Lead_Status__c": "NEW",' +
' "Record_Type_Name__c":"Email_To_Lead",' +
' "Task_Subject__c" : "Test"' + '}';
Map < String, Object > deployedValue = (Map < String, Object > ) JSON.deserializeUntyped(values);
Test.startTest();
UpdateCMD.createCustomMetadata(fullName, label, deployedValue);
Test.stopTest();
}
@IsTest
public static void configSetupTestUpdate(){
String fullName = 'Email_To_Lead__mdt';
String label = 'Email To Lead Config';
String devName = 'Email_To_Lead_Config';
String values = '{' +
' "Lead_Source__c": "Email",' +
' "Lead_Status__c": "NEW",' +
' "Record_Type_Name__c":"Email_To_Lead",' +
' "Task_Subject__c" : "Test"' + '}';
Map < String, Object > deployedValue = (Map < String, Object > ) JSON.deserializeUntyped(values);
Test.startTest();
UpdateCMD.updateCustomMetadata(fullName, devName, label, deployedValue);
Test.stopTest();
}
@IsTest
public static void UpdateMetadataUtilsTest(){
// Mock input data
UpdateCMD.ActionRequest request = new UpdateCMD.ActionRequest();
sObject sObj = Schema.getGlobalDescribe().get('Email_To_Lead__mdt').newSObject();
sObj.put('DeveloperName', 'Email_To_Lead_Config');
sObj.put('Label', 'Email_To_Lead_Config');
sObj.put('Task_Subject__c','Test');
request.data = new List<sObject>{sObj};
Test.startTest();
UpdateCMD.invokeService(new List<UpdateCMD.ActionRequest>{request});
Test.stopTest();
}
@IsTest
public static void CreateMetadataUtilsTest(){
// Mock input data
UpdateCMD.ActionRequest request = new UpdateCMD.ActionRequest();
sObject sObj = Schema.getGlobalDescribe().get('Email_To_Lead__mdt').newSObject();
//sObj.put('DeveloperName', 'Email_To_Lead_Config');
sObj.put('Label', 'Email_To_Lead_Config');
sObj.put('Task_Subject__c','Test');
request.data = new List<sObject>{sObj};
Test.startTest();
UpdateCMD.invokeService(new List<UpdateCMD.ActionRequest>{request});
Test.stopTest();
}
@IsTest
public static void CustomExceptionTest(){
// Mock input data
UpdateCMD.ActionRequest request = new UpdateCMD.ActionRequest();
sObject sObj = Schema.getGlobalDescribe().get('Email_To_Lead__mdt').newSObject();
//sObj.put('DeveloperName', 'Email_To_Lead_Config');
//sObj.put('Label', 'Email_To_Lead_Config');
sObj.put('Task_Subject__c','Test');
request.data = new List<sObject>{sObj};
Exception unexpectedException;
Test.startTest();
try{
UpdateCMD.invokeService(new List<UpdateCMD.ActionRequest>{request});
} catch (Exception ex){
unexpectedException = ex;
system.assertEquals('Make sure to add "Label" attribute in assignemnt for Create and "DeveloperName" for update.', ex.getMessage(), 'Exceptions should be handled by the method');
}
Test.stopTest();
}
@isTest
static void testHandleResult() {
// Instantiate the UpdateCMD class
UpdateCMD callback = new UpdateCMD();
// Mock Metadata.DeployResult for success
Metadata.DeployResult successResult = new Metadata.DeployResult();
successResult.status = Metadata.DeployStatus.Succeeded;
// Mock Metadata.DeployCallbackContext
Metadata.DeployCallbackContext context = new Metadata.DeployCallbackContext();
// Test success scenario
Test.startTest();
callback.handleResult(successResult, context);
Test.stopTest();
/*// Assert success (no exception should be thrown)
System.assertEquals(Metadata.DeployStatus.Succeeded, successResult.status);
// Mock Metadata.DeployResult for failure
Metadata.DeployResult failureResult = new Metadata.DeployResult();
failureResult.status = Metadata.DeployStatus.Failed;
// Test failure scenario
Test.startTest();
try {
callback.handleResult(failureResult, context);
System.assert(false, 'Expected exception was not thrown.');
} catch (UpdateCMD.CustomException ex) {
System.assertEquals(String.valueOf(failureResult), ex.getMessage());
}
Test.stopTest();*/
}
}