Skip to content

Commit 205db55

Browse files
committed
feat: PE template tests
1 parent eade911 commit 205db55

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/main/default/classes/StreamingMonitorController.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public abstract class StreamingMonitorController {
3939
'eventuuid'
4040
};
4141

42+
@TestVisible
4243
private final static Map<Schema.SOAPType, Object> DEFAULT_FIELD_VALUES = new Map<Schema.SOAPType, Object>{
4344
Schema.SOAPType.STRING => '',
4445
Schema.SOAPType.DATE => '2025-01-01',

src/test/default/classes/StreamingMonitorControllerTest.cls

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,54 @@ public class StreamingMonitorControllerTest {
142142
Assert.areEqual('TestSC', channels.get(0).value);
143143
}
144144

145+
@isTest
146+
static void getBlankPlatformEvent_works() {
147+
// Using standard SObject here instead of Platform Event because we can't create Platform Events in tests
148+
Map<String, Object> event = StreamingMonitorController.getBlankPlatformEvent(
149+
'Contact'
150+
);
151+
152+
Assert.isFalse(event.containsKey('createddate'));
153+
Assert.areEqual(
154+
StreamingMonitorController.DEFAULT_FIELD_VALUES.get(
155+
Schema.SOAPType.DATE
156+
),
157+
event.get('birthdate')
158+
);
159+
Assert.areEqual(
160+
StreamingMonitorController.DEFAULT_FIELD_VALUES.get(
161+
Schema.SOAPType.STRING
162+
),
163+
event.get('name')
164+
);
165+
Assert.areEqual(
166+
StreamingMonitorController.DEFAULT_FIELD_VALUES.get(
167+
Schema.SOAPType.BOOLEAN
168+
),
169+
event.get('isdeleted')
170+
);
171+
Assert.areEqual(
172+
StreamingMonitorController.DEFAULT_FIELD_VALUES.get(
173+
Schema.SOAPType.DATETIME
174+
),
175+
event.get('lastcurequestdate')
176+
);
177+
}
178+
179+
@isTest
180+
static void getBlankPlatformEvent_fails_when_eventName_is_unknown_sObject() {
181+
try {
182+
StreamingMonitorController.getBlankPlatformEvent('unknown');
183+
Assert.fail('Exception was expected');
184+
} catch (Exception e) {
185+
Assert.isInstanceOfType(
186+
e,
187+
StreamingMonitorController.StreamingException.class
188+
);
189+
assertContains(e.getMessage(), 'Unknown platform event type');
190+
}
191+
}
192+
145193
private static void assertContains(String actual, String expectedContent) {
146194
System.assert(
147195
actual?.contains(expectedContent),

0 commit comments

Comments
 (0)