Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggerEmailUtils_Tests failed #276

Closed
Firtzberg opened this issue Jan 26, 2022 · 9 comments · Fixed by #274 or #314
Closed

LoggerEmailUtils_Tests failed #276

Firtzberg opened this issue Jan 26, 2022 · 9 comments · Fixed by #274 or #314
Labels
Feature: Email Notifications tests Relates to Apex or LWC jest tests Type: Bug Something isn't working

Comments

@Firtzberg
Copy link

Package Edition of Nebula Logger

Unlocked Package

Package Version of Nebula Logger

https://github.com/jongpie/NebulaLogger/releases/tag/v4.6.16

New Bug Summary

After a refresh of the full and partial sandbox two tests are failing.

System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile.: []
--
Stack trace: | Class.LoggerEmailUtils.sendEmail: line 111, column 1 Class.LoggerEmailUtils.sendErrorEmail: line 81, column 1 Class.LoggerEmailUtils.sendErrorEmail: line 63, column 1 Class.LoggerEmailUtils_Tests.it_should_send_email_notification_for_upsertResult_errors_when_enabled: line 63, column 1
System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile.: []
--
Stack trace: | Class.LoggerEmailUtils.sendEmail: line 111, column 1 Class.LoggerEmailUtils.sendErrorEmail: line 81, column 1 Class.LoggerEmailUtils.sendErrorEmail: line 47, column 1 Class.LoggerEmailUtils_Tests.it_should_send_email_notification_for_saveResult_errors_when_enabled: line 16, column 1
@Firtzberg Firtzberg added the Type: Bug Something isn't working label Jan 26, 2022
@jongpie
Copy link
Owner

jongpie commented Jan 26, 2022

@Firtzberg thanks for reporting this! This should be a fairly quick fix - I'll include a bugfix for this in the next release, v4.7.0 (PR #274). The next release will be out in about 2 weeks (once all orgs have been upgraded to the Spring '22 release)

jongpie added a commit that referenced this issue Jan 26, 2022
…verability is enabled before sending an email [skip ci]
jongpie added a commit that referenced this issue Mar 11, 2022
[LoggerSettings__c changes]

* Closed #279 by adding a new settings field DefaultLogScenario__c and new method Logger.getScenario()

* Closed #258 by adding 2 new fields to LoggerSettings__c (IsSavingEnabled__c and IsPlatformEventStorageEnabled__c)

* Cleaned up help text in several LoggerSettings__c fields

* Added new field LoggerSettings__c.DefaultLogOwner__c that can be used to specify a default owner of Log__c records, using a user ID, username, queue ID or queue developer name

* Renamed LoggerSettings__c field StripInaccessibleRecordFields__c to IsRecordFieldStrippingEnabled__c for consistency



[Log__c UI changes]

* Renamed "View JSON" quickAction to "Open Viewer", and added tabs within logViewer lwc to provide views for both JSON (existing) and log file (new) - a new 'download' button now allows exporting the content to a file

  - For the unlocked package, the logJSON lwc was renamed back to logViewer

* Fixed a conditional render rule on LogEntryRecordpage.flexipage, added an extra check in parseStackTrace() method to handle some problematic lines within a string that is otherwise valid, removed namespace filter when querying ApexClass in LogEntryHandler

* Added picklist values for API Versions in calendar year 2022



[Managed Package changes]

* Changed visibility of LoggerParameter__mdt object from 'Protected' to 'Public'

* Made most LoggerParameter__mdt records non-protected so they can be updated in the managed package

* Worked with @jamessimone to implement a custom approach for dynamically retrieving objects & fields (including namespace) in loggerSettings and logEntryEventStream LWCs, using the new Apex class LoggerSObjectMetadata

  - LWC does not officially support platform events, custom settings, or custom metadata types, so LoggerSObjectMetadata will be used instead

* Re-added skeleton of the deprecated quick action ViewJSON and aura cmp logJSONViewer for the managed package



[Bugfixes]

* Fixed #272 by explicitly delcaring the list as List<Schema.PicklistEntry> instead of just List<PicklistEntry>



[Improvements for Tests & Utilities]

* Added calls to Test.getEventBus().deliver() in Flow classes to try to resolve some inconsistent test failures in the pipeline

* Standardized calls to Database.query() to also use String.escapeSingleQuotes()

* Fixed #276 - Added a check in LoggerEmailUtils to check if email deliverability is enabled before sending an email [skip ci]

* Refactored some code in LogHandler, removed exclusion of PMD rule 'AvoidGlobalModifier'

* Added missing test in LogEntryTagHandler_Tests for updating records

* Fixed some test asserts for 'DUPLICATE_VALUE' error that didn't work correctly when the user's language was not English

* Updated LoggerTestUtils test method to create its own test user, instead of trying to update the current user's record

## Pipeline & Packaging

* Bumped package version to v4.7.0, added devDependencies for outdated packages reported by dependabot in GitHub

* Closed #263 by adding new keyword "ancestorVersion": "HIGHEST" in both sfdx-project.json files

* Updated mgd pkg creation script to use --codecoverage instead of --skipvalidation

* Updated codecov.yml so PR comments are deleted & readded, instead of updated

* Fixed error handling of package creation & installation in pwsh scripts

* Temporarily disabling pipeline check for updated docs due to an error in apexdocs package

* Switched to using JWT bearer flow in pipeline for dev hub auth

* Upgraded sfdx-cli, cleaned up package.json, cleaned up both sfdx-project.json files

* Removed local linking of sfdx-scanner in npm prepare script, added linking command to build.yml, added new sfdx plugin for prettier

* Moved scripts folder back to being a top-level folder

* Switched to using new packageAlias sorting feature in bummer sfdx plugin

* Switched from using sfdx force:community:create + a delay in the pipeline, to instead deploying metadata for a skeleton Experience Cloud site
  The pipeline has been having inconsistent failures because it previously had a 2 minute delay added to wait for force:community:create, but sometimes it took Salesforce longer to finish creating the site asynchronously. Using a deploy will make it a synchronous operation, so it should prevent the inconsistent failures.

Co-authored-by: James Simone <[email protected]>
@jongpie
Copy link
Owner

jongpie commented Mar 11, 2022

@Firtzberg this should be fixed in the new release v4.7.0.

@gjslagle12
Copy link

@jongpie After updating to v4.7.0, I still received errors when running unit tests on a sandbox org with email deliverability turned off.

Unit test error message:

LoggerEmailUtils_Tests.it_should_send_email_notification_for_saveResult_errors_when_enabled
Message: System.AssertException: Assertion Failed: Email should have been sent: Expected: 1, Actual: 0

LoggerEmailUtils_Tests.it_should_send_email_notification_for_upsertResult_errors_when_enabled
Message: System.AssertException: Assertion Failed: Email should have been sent: Expected: 1, Actual: 0

I see the fix in the LoggerEmailUtils class, but in the corresponding LoggerEmailUtils_Test class, it doesn't look like the logic was updated to use the fix. So, the assertions (on lines 18 and 65) only ever reflect "1", and not "0".

Wondering if [something like] this would work on the LoggerEmailUtils_Test class (in those two locations):

   if (LoggerEmailUtils.IS_EMAIL_DELIVERABILITY_ENABLED()) 
        {System.assertEquals(1, Limits.getEmailInvocations(), 'Email should have been sent');}
        {System.assertEquals(0, Limits.getEmailInvocations(), 'Deliverability is turned off');}
      )

(pardon the code - not a programmer)

@jongpie
Copy link
Owner

jongpie commented Apr 28, 2022

Hi @gjslagle12, that's embarrassing that I didn't fully fix it, thanks for letting me know that it's still causing issues! I'll get the test class fixed - I have a release coming out soon in PR #298 (which will be v4.7.1), I'll include this fix in that PR.

And just FYI, in the new release, the class is being renamed from LoggerEmailUtils/LoggerEmailUtils_Tests to LoggerEmailSender/LoggerEmailSender_Tests.

@gjslagle12
Copy link

@jongpie - Thanks!!

@jongpie
Copy link
Owner

jongpie commented May 3, 2022

@gjslagle12 the new v4.7.1 release was released yesterday, which should contain the fixes for those failing tests. Let me know if you encounter any more issues!

@gjslagle12
Copy link

@jongpie Still getting errors on the same two lines during unit tests, but the error message has changed:


Test: LoggerEmailSender_Tests.it_should_send_email_notification_for_saveResult_errors_when_enabled
Message: System.ListException: List index out of bounds: 0

Test: LoggerEmailSender_Tests.it_should_send_email_notification_for_upsertResult_errors_when_enabled
Message: System.ListException: List index out of bounds: 0

@jongpie
Copy link
Owner

jongpie commented May 11, 2022

@gjslagle12 that's double embarrassing that it's still broken! The last time that I tried to fix this, I unfortunately didn't have access to a sandbox to test in (and email deliverability can't be disabled in scratch orgs), so I didn't do as thorough testing as I should have. But, good news - I now have another sandbox that I can test it, and I was able to reproduce those test failures. I'll plan to re-re-fix this in the next release, v4.7.3.

@jongpie jongpie reopened this May 11, 2022
@jongpie jongpie added the tests Relates to Apex or LWC jest tests label May 20, 2022
jongpie added a commit that referenced this issue May 20, 2022
…constant SENT_EMAILS

Scratch orgs also can't have deliverability disabled (very frustrating), so I also separately changed email deliverability to 'System Email Only' in the pkg demo org that's used in the pipeline, which should help ensure everything is working going forward 🤞
jongpie added a commit that referenced this issue May 23, 2022
* Added new selector classes LoggerEngineDataSelector and LogManagementDataSelector to centralize (almost) all queries

* Added LoggerCache class for centralizing transaction caching

* Added LogViewerController.cls to use within logViewer LWC and removed Logger.getLog()

* Eliminated layer-specific test suites within core - as of v4.7.1, the tests are super fast anyway, so the LoggerCore test suite covers everything + makes maintenance easier

* Deleted some deprecated LoggerParameter__mdt records - these were deprecated in v4.7.1, but I forgot to remove them from the repo

* Possibly fixed an issue discussed in #310 by reverting to only using a UUID for the transaction ID (instead of using System.Request.getCurrent().getRequestId())

* Hopefully fixed #276 (again) by moving when an email is added to the constant SENT_EMAILS
Scratch orgs also can't have deliverability disabled (very frustrating), so I also separately changed email deliverability to 'System Email Only' in the pkg demo org that's used in the pipeline, which should help ensure everything is working going forward 🤞

* Added a missing CMDT record for the async failures plugin, created a new package version

* Added missing access to the class LoggerSObjectMetadata in perm sets LoggerAdmin and LoggerLogViewer, moved LoggerLogCreator perm set back to being part of the logger-engine layer

* Fixed #313 by switching to using Logger's txn ID + an incremented counter for dynamically creating unique usernames during tests

* Fixed #219 (again) - it seems like the original solution recently stopped working due to a change in some orgs of the value used for the Guester User LIcense field on the UserLicense object. I've switched to instead using the User Type (UserInfo.getUserType()), which seems to be a more stable option that's less likely to change
- I tried to find an option that didn't rely on a hardcoded String, but so far, have not found any other way to determine it

* Fixed a test that failed when running in a namespaced org

* Enabled running of tests in the pkg demo org within the pipeline, tweaked a few tests that failed only in the pkg demo org
@jongpie
Copy link
Owner

jongpie commented May 23, 2022

@gjslagle12 I've just released v4.7.3, which includes another set of fixes for this issue. Let me know if you still notice any issues with these tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Email Notifications tests Relates to Apex or LWC jest tests Type: Bug Something isn't working
Projects
None yet
3 participants