diff --git a/config/scripts/build/generate-lwc-docs.ps1 b/config/scripts/build/generate-lwc-docs.ps1 index d68c6249b..544a763a4 100644 --- a/config/scripts/build/generate-lwc-docs.ps1 +++ b/config/scripts/build/generate-lwc-docs.ps1 @@ -1,6 +1,6 @@ # This script is used to generate the markdown files used by Github pages for lightning component jsdocs -npx jsdoc2md nebula-logger/main/logger-engine/lwc/logger/logger.js > ./docs/lightning-components/Logger.md -npx jsdoc2md nebula-logger/main/logger-engine/lwc/logger/logEntryBuilder.js > ./docs/lightning-components/LogEntryBuilder.md +npx jsdoc2md nebula-logger/core/main/logger-engine/lwc/logger/logger.js > ./docs/lightning-components/Logger.md +npx jsdoc2md nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js > ./docs/lightning-components/LogEntryBuilder.md $docsSubdirectories = "docs/lightning-components/*.*" foreach($file in Get-ChildItem $docsSubdirectories) { diff --git a/nebula-logger/core/tests/common/classes/LoggerTestUtils.cls b/nebula-logger/core/tests/common/classes/LoggerTestUtils.cls index ae58b94d7..b3e68450a 100644 --- a/nebula-logger/core/tests/common/classes/LoggerTestUtils.cls +++ b/nebula-logger/core/tests/common/classes/LoggerTestUtils.cls @@ -3,13 +3,12 @@ // See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // //------------------------------------------------------------------------------------------------// -@SuppressWarnings('PMD.PropertyNamingConventions') +@SuppressWarnings('PMD.MethodNamingConventions, PMD.PropertyNamingConventions') @IsTest public class LoggerTestUtils { private static final Map SOBJECT_TYPE_TO_MOCK_ID_COUNT = new Map(); - private static final Profile STANDARD_USER_PROFILE = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1]; - // Lazy-load & cache permission sets + // Lazy-load & cache permission sets & profiles private static final Map PERMISSION_SETS_BY_NAME { get { if (PERMISSION_SETS_BY_NAME == null) { @@ -60,6 +59,16 @@ public class LoggerTestUtils { private set; } + private static final Profile STANDARD_USER_PROFILE { + get { + if (STANDARD_USER_PROFILE == null) { + STANDARD_USER_PROFILE = queryStandardUserProfile(); + } + return STANDARD_USER_PROFILE; + } + private set; + } + /** * @description Assigns the permission set `LoggerAdmin` to the specified user ID * @param userId The ID of the user that should be assigned the permission set @@ -228,4 +237,60 @@ public class LoggerTestUtils { } return results; } + + private static Profile queryStandardUserProfile() { + // The Profile object does not have a DeveloperName field, and tandard profile names are (annoyingly) translated + // to the current user's language - to ensure that this // query works for all languages, the translated names + // have been included for these languages: + // 'en_US', 'de', 'es', 'fr', 'it', 'ja', 'sv', 'ko', 'zh_TW', 'zh_CN', 'pt_BR', 'nl_NL', 'da', 'th', 'fi', 'ru', 'es_MX', 'no' + List translatedProfileNames = new List{ + 'Standard User', + 'Standardbenutzer', + 'Usuario estándar', + 'Utilisateur standard', + 'Utente standard', + '標準ユーザ', + 'Standardanvändare', + '표준 사용자', + '標準使用者', + '标准用户', + 'Usuário Padrão', + 'Standaardgebruiker', + 'Standardbruger', + 'ผู้ใช้มาตรฐาน', + 'Vakiokäyttäjä', + 'Стандартный пользователь', + 'Usuario estándar', + 'Standardbruker' + }; + return [SELECT Id FROM Profile WHERE Name IN :translatedProfileNames LIMIT 1]; + } + + // Actual test methods for LoggerTestUtils - the goal of this class is to be a utility class for other test classes, + // but this test ensures that this utility class is working as expected. Yes, this does DML in a for-loop, which is normally + // HORRIBLE to do, but in this case, it's the only way to ensure that the current user's language has been updated + // to ensure that the profile's name is using the expected language + @SuppressWarnings('PMD.OperationWithLimitsInLoop') + @IsTest + static void it_should_return_standard_user_profile_in_all_languages() { + User currentUser = new User(Id = UserInfo.getUserId(), LanguageLocaleKey = 'en_US'); + update currentUser; + Profile expectedProfile; + // Using 'en_US', get the expected profile using the name 'Standard Profile' + System.runAs(currentUser) { + currentUser = [SELECT Id, LanguageLocaleKey FROM User WHERE Id = :UserInfo.getUserId()]; + System.assertEquals('en_US', currentUser.LanguageLocaleKey); + expectedProfile = [SELECT Id, Name FROM Profile WHERE Name = 'Standard User']; + } + // Test that each value of LanguageLocaleKey returns a value for STANDARD_USER_PROFILE + for (PicklistEntry picklistEntry : Schema.User.LanguageLocaleKey.getDescribe().getPickListValues()) { + User user = new User(Id = UserInfo.getUserId(), LanguageLocaleKey = picklistEntry.getValue()); + update user; + System.runAs(user) { + currentUser = [SELECT Id, LanguageLocaleKey FROM User WHERE Id = :UserInfo.getUserId()]; + System.assertEquals(picklistEntry.getValue(), currentUser.LanguageLocaleKey); + System.assertEquals(expectedProfile.Id, STANDARD_USER_PROFILE.Id); + } + } + } }