Skip to content

Commit

Permalink
Bugfix for Logger.setScenario() (#327)
Browse files Browse the repository at this point in the history
* Fixed #326 by correcting a typo in a comparison operator used within Logger.setScenario()

* Made a few small optimizations to Logger_Tests so it can run tests in parallel

* Temporarily adding some Apex files to .forceignore until I have more time to finish adding System namespace throughout the codebase
  • Loading branch information
jongpie authored Jun 8, 2022
1 parent e120ff1 commit 8d00cf5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .forceignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ nebula-logger/managed-package/**/*.testSuite-meta.xml
# LWC Jest
**/__tests__/**
**/jest-mocks/**

# Temporarily ignoring of some files - will remove in a future release
nebula-logger/extra-tests/classes/FieldSet.cls
nebula-logger/extra-tests/classes/FieldSet.cls-meta.xml
nebula-logger/extra-tests/classes/FieldSetMember.cls
nebula-logger/extra-tests/classes/FieldSetMember.cls-meta.xml
nebula-logger/extra-tests/classes/SObjectField.cls
nebula-logger/extra-tests/classes/SObjectField.cls-meta.xml
nebula-logger/extra-tests/classes/SObjectType.cls
nebula-logger/extra-tests/classes/SObjectType.cls-meta.xml
nebula-logger/extra-tests/classes/Test.cls
nebula-logger/extra-tests/classes/Test.cls-meta.xml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

Designed for Salesforce admins, developers & architects. A robust logger for Apex, Lightning Components, Flow, Process Builder & Integrations.

## Unlocked Package - v4.7.6
## Unlocked Package - v4.7.7

[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lkmQAA)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lkmQAA)
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015llLQAQ)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015llLQAQ)
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)

## Managed Package - v4.7.0
Expand Down
22 changes: 15 additions & 7 deletions nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.7.6';
private static final String CURRENT_VERSION_NUMBER = 'v4.7.7';
private static final LoggingLevel DEFAULT_LOGGING_LEVEL = LoggingLevel.DEBUG;
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
private static final Map<String, LogScenarioRule__mdt> MOCK_SCENARIO_TO_SCENARIO_RULE = new Map<String, LogScenarioRule__mdt>();
Expand Down Expand Up @@ -2700,7 +2700,7 @@ global with sharing class Logger {

LogScenarioRule__mdt matchingScenarioRule;
for (LogScenarioRule__mdt scenarioRule : LogScenarioRule__mdt.getAll().values()) {
if (scenarioRule.IsEnabled__c = true && scenarioRule.Scenario__c == scenario) {
if (scenarioRule.IsEnabled__c == true && scenarioRule.Scenario__c == scenario) {
matchingScenarioRule = scenarioRule;
break;
}
Expand All @@ -2715,11 +2715,6 @@ global with sharing class Logger {
}
}

@TestVisible
private static void setMockScenarioRule(LogScenarioRule__mdt scenarioRule) {
MOCK_SCENARIO_TO_SCENARIO_RULE.put(scenarioRule.Scenario__c, scenarioRule);
}

/**
* @description Returns the default save method used when calling saveLog() - set via LoggerSettings__c or by calling setSaveMethod(SaveMethod saveMethod)
* @return The enum value of Logger.SaveMethod to use for any calls to saveLog() in the current transaction
Expand Down Expand Up @@ -2918,6 +2913,19 @@ global with sharing class Logger {
}
}

@TestVisible
private static void setMockScenarioRule(LogScenarioRule__mdt scenarioRule) {
// TODO Add validation for DeveloperName and Scenario__c fields != null
// if (String.isBlank(scenarioRule.DeveloperName) == true) {
// throw new IllegalArgumentException('DeveloperName is required on `LogScenarioRule__mdt: \n' + JSON.serializePretty(scenarioRule));
// }
// if (String.isBlank(scenarioRule.Scenario__c) == true) {
// throw new IllegalArgumentException('Scenario__c is required on `LogScenarioRule__mdt: \n' + JSON.serializePretty(scenarioRule));
// }

MOCK_SCENARIO_TO_SCENARIO_RULE.put(scenarioRule.Scenario__c, scenarioRule);
}

private static SaveMethod getSaveMethod(String saveMethodName) {
try {
return SaveMethod.valueOf(saveMethodName);
Expand Down
19 changes: 9 additions & 10 deletions nebula-logger/core/tests/logger-engine/classes/Logger_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//------------------------------------------------------------------------------------------------//

@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount, PMD.NcssTypeCount')
@IsTest(IsParallel=false)
@IsTest(IsParallel=true)
private class Logger_Tests {
@IsTest
static void it_should_return_version_number() {
Expand Down Expand Up @@ -427,34 +427,33 @@ private class Logger_Tests {

@IsTest
static void it_should_save_accurate_timestamp_when_logging_user_has_different_time_zone() {
// TODO Move this test to LogEntryEventBuilder_Tests, see if there's a way to eliminate creating a user
// TODO Move this test to LogEntryEventBuilder_Tests
User automatedProcessUser = [SELECT Id, TimeZoneSidKey FROM User WHERE Name = 'Automated Process' AND Profile.Name = NULL];
User testStandardUser = LoggerMockDataCreator.createUser();
User currentUser = new User(Id = UserInfo.getUserId());
// Make sure that the test user has a different time zone from the automated process user
if (automatedProcessUser.TimeZoneSidKey == testStandardUser.TimeZoneSidKey) {
if (automatedProcessUser.TimeZoneSidKey == currentUser.TimeZoneSidKey) {
switch on automatedProcessUser.TimeZoneSidKey {
when 'America/Los_Angeles' {
testStandardUser.TimeZoneSidKey = 'America/New_York';
currentUser.TimeZoneSidKey = 'America/New_York';
}
when else {
testStandardUser.TimeZoneSidKey = 'America/Los_Angeles';
currentUser.TimeZoneSidKey = 'America/Los_Angeles';
}
}
System.assertNotEquals(automatedProcessUser.TimeZoneSidKey, testStandardUser.TimeZoneSidKey);
System.assertNotEquals(automatedProcessUser.TimeZoneSidKey, currentUser.TimeZoneSidKey);
}

Datetime originalTimestamp;
System.runAs(testStandardUser) {
System.runAs(currentUser) {
Logger.getUserSettings().IsEnabled__c = true;
Logger.getUserSettings().LoggingLevel__c = LoggingLevel.INFO.name();

LogEntryEventBuilder builder = Logger.info('test log entry');

originalTimestamp = builder.getLogEntryEvent().TimeStamp__c;
System.assertNotEquals(null, originalTimestamp);

System.assertEquals(1, Logger.getBufferSize());
Logger.saveLog();

System.Test.getEventBus().deliver();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nebula-logger",
"version": "4.7.6",
"version": "4.7.7",
"description": "Designed for Salesforce admins, developers & architects. A robust logger for Apex, Flow, Process Builder & Integrations.",
"author": "Jonathan Gillespie",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"package": "Nebula Logger - Core",
"path": "./nebula-logger/core",
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
"versionNumber": "4.7.6.NEXT",
"versionName": "Support for Component Logging of Apex Controller Errors",
"versionDescription": "Added support for logging in LWC/Aura of error objects returned from Apex controller methods (which have a different structure from a native JavaScript Error)",
"versionNumber": "4.7.7.NEXT",
"versionName": "Bugfix in Logger.setScenario()",
"versionDescription": "Fixed a typo in Logger.setScenario() that had the wrong comparison operator, made a few small changes to Logger_Tests so it can run tests in parallel",
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
"default": true
},
Expand Down Expand Up @@ -127,6 +127,7 @@
"Nebula Logger - Core@4.7.4-3-new-method-logger.logdatabaseerrors()": "04t5Y0000015ligQAA",
"Nebula Logger - Core@4.7.5-3-configurable-logger.setscenario()-behavior": "04t5Y0000015lkcQAA",
"Nebula Logger - Core@4.7.6-NEXT-support-for-component-logging-of-apex-controller-errors": "04t5Y0000015lkmQAA",
"Nebula Logger - Core@4.7.7-NEXT-bugfix-in-logger.setscenario()": "04t5Y0000015llLQAQ",
"Nebula Logger - Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
"Nebula Logger - Plugin - Async Failure Additions@1.0.0-3": "04t5Y0000015lhiQAA",
"Nebula Logger - Plugin - Async Failure Additions@1.0.1-1": "04t5Y0000015lhsQAA",
Expand Down

0 comments on commit 8d00cf5

Please sign in to comment.