Skip to content

Commit

Permalink
FIX: Issue #438 (#446) where Logger.getUserSettings() did not work co…
Browse files Browse the repository at this point in the history
…rrectly when called from loggerSettings LWC
  • Loading branch information
chazwatkins authored Jan 27, 2023
1 parent 4ca9535 commit 122753b
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ global with sharing class Logger {
} else if (loggingUserSettings == null && loggingUser.ProfileId != null && LoggerSettings__c.getValues(loggingUser.ProfileId) != null) {
// Next, check for Profile-level settings
loggingUserSettings = LoggerSettings__c.getValues(loggingUser.ProfileId);
} else if (LoggerSettings__c.getOrgDefaults().Id != null) {
} else if (loggingUser.Id != null && LoggerSettings__c.getOrgDefaults().Id != null) {
// Next, use the org defaults (if configured)
loggingUserSettings = LoggerSettings__c.getOrgDefaults();
} else {
Expand Down
120 changes: 120 additions & 0 deletions nebula-logger/core/tests/logger-engine/classes/Logger_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,126 @@ private class Logger_Tests {
System.Assert.areEqual(expectedSettings.Id, returnedSettings.Id);
}


@IsTest
static void it_should_return_new_settings_when_org_default_exists_and_user_id_is_null_and_async_in_a_sandbox() {
LoggerParameter.setMock(
new LoggerParameter__mdt(
DeveloperName = 'QueryOrganizationDataSynchronously',
Value__c = String.valueOf(false)
)
);

Organization mockOrganization =
(Schema.Organization) LoggerMockDataCreator.setReadOnlyField(
new Organization(),
Schema.Organization.IsSandbox,
true
);

System.Assert.isTrue(mockOrganization.IsSandbox);

MockLoggerEngineDataSelector mockSelector = new MockLoggerEngineDataSelector();
mockSelector.setCachedOrganization(mockOrganization);
LoggerEngineDataSelector.setMock(mockSelector);

LoggerSettings__c expectedSettings = (LoggerSettings__c) LoggerSettings__c.SObjectType.newSObject(null, true);

LoggerSettings__c returnedSettings = Logger.getUserSettings(new User());

System.Assert.areEqual(expectedSettings, returnedSettings);
}

@IsTest
static void it_should_return_new_settings_when_org_default_exists_and_user_id_is_null_and_async_not_in_a_sandbox() {
LoggerParameter.setMock(
new LoggerParameter__mdt(
DeveloperName = 'QueryOrganizationDataSynchronously',
Value__c = String.valueOf(false)
)
);

Organization mockOrganization =
(Schema.Organization) LoggerMockDataCreator.setReadOnlyField(
new Organization(),
Schema.Organization.IsSandbox,
false
);

System.Assert.isFalse(mockOrganization.IsSandbox);

MockLoggerEngineDataSelector mockSelector = new MockLoggerEngineDataSelector();
mockSelector.setCachedOrganization(mockOrganization);
LoggerEngineDataSelector.setMock(mockSelector);

LoggerSettings__c expectedSettings = (LoggerSettings__c) LoggerSettings__c.SObjectType.newSObject(null, true);

LoggerSettings__c returnedSettings = Logger.getUserSettings(new User());

System.Assert.areEqual(expectedSettings, returnedSettings);
}

@IsTest
static void it_should_return_new_settings_with_defaults_when_org_default_exists_and_user_id_is_null_and_sync_in_a_sandbox() {
LoggerParameter.setMock(
new LoggerParameter__mdt(
DeveloperName = 'QueryOrganizationDataSynchronously',
Value__c = String.valueOf(true)
)
);

Organization mockOrganization =
(Schema.Organization) LoggerMockDataCreator.setReadOnlyField(
new Organization(),
Schema.Organization.IsSandbox,
true
);

System.Assert.isTrue(mockOrganization.IsSandbox);

MockLoggerEngineDataSelector mockSelector = new MockLoggerEngineDataSelector();
mockSelector.setCachedOrganization(mockOrganization);
LoggerEngineDataSelector.setMock(mockSelector);

LoggerSettings__c expectedSettings = (LoggerSettings__c) LoggerSettings__c.SObjectType.newSObject(null, true);
expectedSettings.LoggingLevel__c = System.LoggingLevel.FINEST.name();
expectedSettings.IsApexSystemDebugLoggingEnabled__c = true;
expectedSettings.IsJavaScriptConsoleLoggingEnabled__c = true;

LoggerSettings__c returnedSettings = Logger.getUserSettings(new User());

System.Assert.areEqual(expectedSettings, returnedSettings);
}

@IsTest
static void it_should_return_new_settings_when_org_default_exists_and_user_id_is_null_and_sync_not_in_a_sandbox() {
LoggerParameter.setMock(
new LoggerParameter__mdt(
DeveloperName = 'QueryOrganizationDataSynchronously',
Value__c = String.valueOf(true)
)
);

Organization mockOrganization =
(Schema.Organization) LoggerMockDataCreator.setReadOnlyField(
new Organization(),
Schema.Organization.IsSandbox,
false
);

System.Assert.isFalse(mockOrganization.IsSandbox);

MockLoggerEngineDataSelector mockSelector = new MockLoggerEngineDataSelector();
mockSelector.setCachedOrganization(mockOrganization);
LoggerEngineDataSelector.setMock(mockSelector);

LoggerSettings__c expectedSettings = (LoggerSettings__c) LoggerSettings__c.SObjectType.newSObject(null, true);

LoggerSettings__c returnedSettings = Logger.getUserSettings(new User());

System.Assert.areEqual(expectedSettings, returnedSettings);
}

@IsTest
static void it_should_generate_a_valid_uuid() {
Pattern pattern = Pattern.compile('[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}');
Expand Down

0 comments on commit 122753b

Please sign in to comment.