Skip to content

Commit

Permalink
Fixed some test failures in the async-failure & big-object plugins an…
Browse files Browse the repository at this point in the history
…d extra-tests, caused by the changes to how CMDT records are now loaded in core during tests
  • Loading branch information
jongpie committed Dec 4, 2024
1 parent d599a62 commit 5f3c4e7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private class NebulaLogger_E2E_Tests {
System.JSON.serialize(untypedRequestBody.get('records')),
List<LogEntryEvent__e>.class
);
System.Assert.areEqual(1, requestRecords.size());
System.Assert.isFalse(requestRecords.isEmpty(), System.JSON.serializePretty(requestRecords));
System.Assert.areEqual(message, builder.getLogEntryEvent().Message__c);
System.Assert.areEqual(message, requestRecords.get(0).Message__c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private class Logger_Tests_InboundEmailHandler {
List<Log__c> logs = [SELECT Id, TransactionId__c FROM Log__c];
System.Assert.areEqual(1, logs.size(), 'Logs size did not match expected value of 1.');
System.Assert.areEqual(transactionId, logs.get(0).TransactionId__c, 'Transaction Id does match expected value');
List<LogEntry__c> logEntries = [SELECT Id, Message__c FROM LogEntry__c];
List<LogEntry__c> logEntries = [SELECT Id, Message__c FROM LogEntry__c WHERE LoggingLevelOrdinal__c >= :System.LoggingLevel.INFO.ordinal()];
System.Assert.areEqual(2, logEntries.size(), 'Log entries size did not match expected value of 2 ' + System.JSON.serializePretty(logEntries));
System.Assert.areEqual(ExampleInboundEmailHandler.logEntryMessage, logEntries.get(0).Message__c, 'Log entries message did not match expected value');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public without sharing virtual class LogFinalizer implements System.Finalizer {
* @param finalizerContext The `System.FinalizerContext` associated with the finalizer
*/
public void execute(System.FinalizerContext finalizerContext) {
Logger.setAsyncContext(finalizerContext);
switch on finalizerContext.getResult() {
when UNHANDLED_EXCEPTION {
Logger.setAsyncContext(finalizerContext);
Logger.error('There was an error during this queueable job');
Logger.error('Error details', finalizerContext.getException());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private class LogFinalizer_Tests {
}
System.Test.getEventBus().deliver();

List<LogEntry__c> logEntries = [SELECT Message__c, ExceptionMessage__c FROM LogEntry__c];
List<LogEntry__c> logEntries = [SELECT Message__c, ExceptionMessage__c FROM LogEntry__c WHERE LoggingLevel__c = :System.LoggingLevel.ERROR.name()];
System.Assert.areEqual(2, logEntries.size(), 'Should log for errors');
LogEntry__c firstEntry = logEntries.get(0);
System.Assert.areEqual('There was an error during this queueable job', firstEntry.Message__c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ private class LogFlowExecutionErrorEventHandler_Tests {
RecordId__c,
Timestamp__c
FROM LogEntry__c
WHERE LoggingLevel__c = :System.LoggingLevel.ERROR.name()
];
// LogEntry__c related asserts
System.Assert.areEqual(System.LoggingLevel.ERROR.name(), entry.LoggingLevel__c, 'Logging level should be set correctly');
System.Assert.areEqual(
String.format(
LogFlowExecutionErrorEventHandler.LOG_STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private class LogEntryArchivePlugin_Tests {
'Last save method used should have been set to BIG_OBJECT_EVENT_BUS'
);
System.Test.stopTest();
System.Assert.areEqual(1, LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.size(), 'Should have been put into big object buffer');
System.Assert.isFalse(LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.isEmpty(), 'Should have been put into big object buffer');
System.Assert.isNotNull(transactionId, 'Should have a value for transaction ID');
System.Assert.areEqual(transactionId, LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.get(0).TransactionId__c, 'Transaction ID should match');
System.Assert.areEqual(0, [SELECT COUNT() FROM Log__c WHERE TransactionId__c = :transactionId], 'No custom object data should have been created');
Expand All @@ -182,7 +182,7 @@ private class LogEntryArchivePlugin_Tests {
'Should not have actually used any DML statements in tests because big objects actually get inserted, yikes'
);
System.Assert.areEqual(0, Logger.getBufferSize(), 'Should not have been put into Logger\'s platform event buffer');
System.Assert.areEqual(1, LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.size(), 'Should have been put into big object buffer');
System.Assert.isFalse(LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.isEmpty(), 'Should have been put into big object buffer');
System.Assert.areEqual(
'BIG_OBJECT_IMMEDIATE',
LogEntryArchivePlugin.lastSaveMethodUsed,
Expand Down Expand Up @@ -210,7 +210,7 @@ private class LogEntryArchivePlugin_Tests {
'Should not have actually used any DML statements in tests because big objects actually get inserted, yikes'
);
System.Assert.areEqual(0, Logger.getBufferSize(), 'Should not have been put into Logger\'s platform event buffer');
System.Assert.areEqual(1, LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.size(), 'Should have been put into big object buffer');
System.Assert.isFalse(LogEntryArchivePlugin.LOG_ENTRY_ARCHIVES_TO_SAVE.isEmpty(), 'Should have been put into big object buffer');
System.Assert.areEqual(
'BIG_OBJECT_QUEUEABLE',
LogEntryArchivePlugin.lastSaveMethodUsed,
Expand Down
16 changes: 8 additions & 8 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
"path": "./nebula-logger/plugins/async-failure-additions/plugin",
"dependencies": [
{
"package": "Nebula Logger - Core@4.7.2-parent-log-transaction-id-bugfix"
"package": "Nebula Logger - Core@4.15.2-improved-testability-of-query-selectors"
}
],
"versionNumber": "1.0.2.NEXT",
"versionName": "Added logging for Screen Flow failures",
"versionDescription": "Allows unhandled exceptions within screen flows to be automatically logged (toggleable, default off)",
"versionNumber": "1.0.3.NEXT",
"versionName": "Logging & Testing Improvements",
"versionDescription": "Updated LogFinalizer to skip logging the async context when no error has occurred, and corrected some test issues caused by changes in core v4.15.2 unhandled exceptions within screen flows to be automatically logged (toggleable, default off)",
"default": false
},
{
"package": "Nebula Logger - Core Plugin - Big Object Archiving",
"path": "./nebula-logger/plugins/big-object-archiving/plugin",
"dependencies": [
{
"package": "Nebula Logger - Core@4.7.1-plugin-framework-overhaul"
"package": "Nebula Logger - Core@4.15.2-improved-testability-of-query-selectors"
}
],
"versionNumber": "0.9.0.NEXT",
"versionName": "Beta Release",
"versionDescription": "Initial beta version of new plugin",
"versionNumber": "0.9.1.NEXT",
"versionName": "Testing Improvements",
"versionDescription": "Corrected some test issues caused by changes in core v4.15.2",
"default": false
},
{
Expand Down

0 comments on commit 5f3c4e7

Please sign in to comment.