Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Oct 15, 2024
1 parent 9f27335 commit 2fc4d05
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex -- --synchronous

- name: 'Delete Scratch Org'
run: npx sf org delete scratch --no-prompt
if: ${{ always() }}
Expand Down Expand Up @@ -252,12 +252,13 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

# This intentionally does NOT use test:apex:nocoverage, since code coverage results are uploaded below to codecov.io
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex

# This is the only scratch org that's used for uploading code coverage
- name: 'Upload Apex test code coverage to Codecov.io'
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -328,12 +329,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Delete Scratch Org'
run: npx sf org delete scratch --no-prompt
if: ${{ always() }}
Expand Down Expand Up @@ -399,12 +400,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Delete Scratch Org'
run: npx sf org delete scratch --no-prompt
if: ${{ always() }}
Expand Down Expand Up @@ -474,12 +475,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Delete Base Scratch Org'
run: npx sf org delete scratch --no-prompt
if: ${{ always() }}
Expand Down Expand Up @@ -542,12 +543,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Delete Scratch Org'
run: npx sf org delete scratch --no-prompt
if: ${{ always() }}
Expand Down Expand Up @@ -657,12 +658,12 @@ jobs:
# This is done because, based on how you execute Apex tests, the running user may have an active session (synchrously) or not (asynchronously).
# Utlimately, this could/should probably be better mocked during tests, but the AuthSession is read-only in Apex, so it's a bit difficult to work with.
# Running the Apex tests sync & async serves as an extra level of integration testing in the meantime to ensure that everything works with or without an active session.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage -- --targetusername nebula-logger-package-demo

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --targetusername nebula-logger-package-demo --synchronous

- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage -- --targetusername nebula-logger-package-demo

- name: 'Commit New Package Version'
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@
@SuppressWarnings('PMD.ApexDoc, PMD.ApexAssertionsShouldIncludeMessage, PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LoggerConfigurationDataSelector_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
@IsTest
static void it_initializes_mock_lists_when_use_mocks_is_called() {
System.Assert.isNull(LoggerConfigurationDataSelector.mockLogEntryDataMaskRules);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLogEntryTagRules);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLoggerFieldMappings);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLoggerParameters);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLoggerPlugins);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLoggerScenarioRules);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLoggerSObjectHandlers);
System.Assert.isNull(LoggerConfigurationDataSelector.mockLogStatuses);

LoggerConfigurationDataSelector.useMocks();

System.Assert.areEqual(new List<LogEntryDataMaskRule__mdt>(), LoggerConfigurationDataSelector.mockLogEntryDataMaskRules);
System.Assert.areEqual(new List<LogEntryTagRule__mdt>(), LoggerConfigurationDataSelector.mockLogEntryTagRules);
System.Assert.areEqual(new List<LoggerFieldMapping__mdt>(), LoggerConfigurationDataSelector.mockLoggerFieldMappings);
System.Assert.areEqual(new Map<String, LoggerParameter__mdt>(), LoggerConfigurationDataSelector.mockLoggerParameters);
System.Assert.areEqual(new List<LoggerPlugin__mdt>(), LoggerConfigurationDataSelector.mockLoggerPlugins);
System.Assert.areEqual(new List<LoggerScenarioRule__mdt>(), LoggerConfigurationDataSelector.mockLoggerScenarioRules);
System.Assert.areEqual(new List<LoggerSObjectHandler__mdt>(), LoggerConfigurationDataSelector.mockLoggerSObjectHandlers);
System.Assert.areEqual(new List<LogStatus__mdt>(), LoggerConfigurationDataSelector.mockLogStatuses);
}

@IsTest
Expand Down Expand Up @@ -86,7 +104,7 @@ private class LoggerConfigurationDataSelector_Tests {

@IsTest
static void it_returns_logger_parameters_from_database() {
Map<String, LoggerParameter__mdt> expectedValues = LoggerParameter__mdt.getAll();
Map<String, LoggerParameter__mdt> expectedValues = LoggerParameter__mdt.getAll().deepClone();

Map<String, LoggerParameter__mdt> returnedValues = LoggerConfigurationDataSelector.getInstance().getLoggerParameters();

Expand Down Expand Up @@ -149,11 +167,9 @@ private class LoggerConfigurationDataSelector_Tests {
FROM LoggerSObjectHandler__mdt
WHERE IsEnabled__c = TRUE
];
System.Assert.isFalse(expectedValues.isEmpty());

List<LoggerSObjectHandler__mdt> returnedValues = LoggerConfigurationDataSelector.getInstance().getLoggerSObjectHandlers();

System.Assert.isFalse(returnedValues.isEmpty());
System.Assert.areEqual(expectedValues, returnedValues);
}

Expand All @@ -171,11 +187,9 @@ private class LoggerConfigurationDataSelector_Tests {
@IsTest
static void it_returns_log_statuses_from_database() {
List<LogStatus__mdt> expectedValues = LogStatus__mdt.getAll().values().deepClone();
System.Assert.isFalse(expectedValues.isEmpty());

List<LogStatus__mdt> returnedValues = LoggerConfigurationDataSelector.getInstance().getLogStatuses();

System.Assert.isFalse(returnedValues.isEmpty());
System.Assert.areEqual(expectedValues, returnedValues);
}

Expand Down

0 comments on commit 2fc4d05

Please sign in to comment.