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

Feat/custom assertions #110

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Feat/custom assertions #110

wants to merge 16 commits into from

Conversation

codefriar
Copy link
Owner

@codefriar codefriar commented Oct 4, 2023

Adds a 'shadow' Assert class that facilitates developers adding custom assertion methods that can still be cleanly read as Assert.methodName

Closes #104

Summary by CodeRabbit

  • New Feature: Introduced a new Assert class with custom assertion methods for various conditions, enhancing the testing capabilities.
  • Refactor: Updated return types of several methods across multiple classes to improve type safety and clarity.
  • Documentation: Revised documentation for numerous classes, improving descriptions of methods and their return types.
  • Test: Added visibility to certain enum constants for testing purposes.
  • Chore: Minor changes in formatting and phrasing in the codebase's documentation.

Signed-off-by: kpoorman <kjp@codefriar.com>
introduces an Org level Assert class that passes through the standard Assert methods by calling `System.Assert.MethodName`. This includes a number of example custom assertions that can all be used by calling Assert.MethodName

Signed-off-by: kpoorman <kjp@codefriar.com>
@codefriar codefriar requested a review from dschach October 4, 2023 07:13
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (671272e) 95.00% compared to head (a5b7261) 95.00%.
Report is 23 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #110   +/-   ##
=======================================
  Coverage   95.00%   95.00%           
=======================================
  Files          32       32           
  Lines        2002     2002           
=======================================
  Hits         1902     1902           
  Misses        100      100           
Flag Coverage Δ
Apex 95.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dschach dschach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class name requires all other Assert statements to use System.Assert? If so, it probably needs a new name.

force-app/main/default/classes/test utilities/Assert.cls Outdated Show resolved Hide resolved
@codefriar
Copy link
Owner Author

codefriar commented Oct 4, 2023 via email

Signed-off-by: kpoorman <kjp@codefriar.com>
introduces an Org level Assert class that passes through the standard Assert methods by calling `System.Assert.MethodName`. This includes a number of example custom assertions that can all be used by calling Assert.MethodName

Signed-off-by: kpoorman <kjp@codefriar.com>
codefriar and others added 3 commits October 4, 2023 22:59
Adding the new Assert method isNotJanky.
Hint. if you have to ask, it is.

Signed-off-by: kpoorman <kjp@codefriar.com>
Adding the new Assert method isNotJanky.
Hint. if you have to ask, it is.

Signed-off-by: kpoorman <kjp@codefriar.com>
@dschach dschach self-requested a review October 5, 2023 18:46
codefriar and others added 7 commits October 5, 2023 14:31
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
And CI-pr.yml

Signed-off-by: kpoorman <kjp@codefriar.com>
that has 4 parameters.

Signed-off-by: kpoorman <kjp@codefriar.com>
@github-actions
Copy link

github-actions bot commented Oct 18, 2023

Image description CodeRabbit

Walkthrough

This pull request introduces a new Assert class with custom assertion methods for various conditions, and modifies the return types of several methods across multiple classes to improve type safety. It also includes updates to the documentation reflecting these changes.

Changes

Files Summary
CAssert.md, CAssert.cls, CAssert.cls-meta.xml Added a new Assert class with custom assertion methods for validating different conditions.
BulkCallable.md, CustomInvocable.md, FeatureFlag.md, HttpCalloutMockFactory.md, CanTheUserTests.md, FeatureFlagCommonTests.md, FeatureFlagDataProvider.md, MetadataTriggerQueryService.md, MockedMethod.md, Query.md, SOQL.md, SOQLAgregate.md, SOSL.md, Safely.md, StubUtilities.md, TestFactory.md, QueueableProcess.md, RestClientLib.md, UFInvocable.md, UniversalBulkInvocable.md, UniversalFlowInputOutput.md, UniversalInvocable.md Modified the return types of several methods in various classes to improve type safety.
RestLib.md, RestLibApiCall.md, TriggerContext.md, TriggerFrameworkLoopCount.md Updated the documentation to reflect the changes in method return types.
home.md Mentioned the addition of a 'shadow' Assert class and two other classes, AsyncRestApi and CachePartitionType.

🐇💻

"In the land of code where the shadows lie,
An Assert class was born under the AI's eye.
With custom methods, it stands tall,
Ensuring type safety for one and all.
The docs were updated, the changes were made,
In the realm of code, the rabbit played.
Celebrate these changes, for they are neat,
Making our codebase incredibly sweet!" 🎉🥕


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

@codefriar
Copy link
Owner Author

@dschach - I've refactored this into a new class name and reverted the shadowing work. It shows I have an outstanding request for change, but I can't find it. Thoughts on this?

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between b36452f and dc2ea9e commits.
Files selected (4)
  • docs/CAssert.md (1)
  • docs/home.md (1)
  • force-app/main/default/classes/test utilities/CAssert.cls (1)
  • force-app/main/default/classes/test utilities/CAssert.cls-meta.xml (1)
Files skipped from review due to trivial changes (3)
  • docs/home.md
  • force-app/main/default/classes/test utilities/CAssert.cls
  • force-app/main/default/classes/test utilities/CAssert.cls-meta.xml
Review comments generated (1)
  • Review: 0
  • LGTM: 1

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Signed-off-by: kpoorman <kjp@codefriar.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between dc2ea9e and 7897308 commits.
Files selected (49)
  • docs/BulkCallable.md (2)
  • docs/CanTheUser.md (24)
  • docs/CanTheUserTests.md (1)
  • docs/CustomInvocable.md (5)
  • docs/ExampleQueueableProcessSteps.md (1)
  • docs/FF.md (3)
  • docs/FailsafeExceptionHandler.md (1)
  • docs/FeatureFlag.md (6)
  • docs/FeatureFlagCommonTests.md (4)
  • docs/FeatureFlagDataProvider.md (5)
  • docs/HttpCalloutMockFactory.md (2)
  • docs/IdFactory.md (6)
  • docs/Log.md (1)
  • docs/LogMessage.md (1)
  • docs/LogTriggerHandler.md (3)
  • docs/MetadataTriggerFramework.md (3)
  • docs/MetadataTriggerQueryService.md (3)
  • docs/MethodSignature.md (8)
  • docs/MockedMethod.md (16)
  • docs/OrgShape.md (5)
  • docs/Ouroboros.md (2)
  • docs/OuroborosFinalizer.md (1)
  • docs/OuroborosTests.md (1)
  • docs/Polyfills.md (10)
  • docs/Query.md (1)
  • docs/QueueableProcess.md (3)
  • docs/QueueableProcessDataProvider.md (1)
  • docs/QueueableProcessTests.md (1)
  • docs/QuiddityGuard.md (2)
  • docs/RestClient.md (1)
  • docs/RestClientLib.md (13)
  • docs/RestLib.md (1)
  • docs/RestLibApiCall.md (1)
  • docs/SOQL.md (1)
  • docs/SOQLAgregate.md (1)
  • docs/SOSL.md (1)
  • docs/Safely.md (12)
  • docs/SampleHandler.md (3)
  • docs/Stub.md (9)
  • docs/StubUtilities.md (2)
  • docs/TestFactory.md (16)
  • docs/TriggerContext.md (1)
  • docs/TriggerFramework.md (3)
  • docs/TriggerFrameworkLoopCount.md (1)
  • docs/UFInvocable.md (7)
  • docs/ULID.md (3)
  • docs/UniversalBulkInvocable.md (2)
  • docs/UniversalFlowInputOutput.md (1)
  • docs/UniversalInvocable.md (2)
Files ignored due to filter (1)
  • config/project-scratch-def.json
Files not summarized due to errors (1)
  • docs/CanTheUser.md (diff tokens exceeds limit)
Files not reviewed due to errors (12)
  • docs/HttpCalloutMockFactory.md (no response)
  • docs/FeatureFlagCommonTests.md (no response)
  • docs/LogTriggerHandler.md (no response)
  • docs/CanTheUser.md (no response)
  • docs/MockedMethod.md (no response)
  • docs/Query.md (no response)
  • docs/QuiddityGuard.md (no response)
  • docs/QueueableProcess.md (no response)
  • docs/Safely.md (no response)
  • docs/TestFactory.md (no response)
  • docs/UniversalBulkInvocable.md (no response)
  • docs/UniversalInvocable.md (no response)
Files skipped from review due to trivial changes (31)
  • docs/CanTheUserTests.md
  • docs/CustomInvocable.md
  • docs/ExampleQueueableProcessSteps.md
  • docs/FF.md
  • docs/FailsafeExceptionHandler.md
  • docs/FeatureFlag.md
  • docs/IdFactory.md
  • docs/Log.md
  • docs/LogMessage.md
  • docs/MetadataTriggerFramework.md
  • docs/MethodSignature.md
  • docs/OrgShape.md
  • docs/Ouroboros.md
  • docs/OuroborosFinalizer.md
  • docs/Polyfills.md
  • docs/QueueableProcessDataProvider.md
  • docs/QueueableProcessTests.md
  • docs/RestClient.md
  • docs/RestClientLib.md
  • docs/RestLib.md
  • docs/RestLibApiCall.md
  • docs/SOQL.md
  • docs/SOQLAgregate.md
  • docs/SOSL.md
  • docs/SampleHandler.md
  • docs/Stub.md
  • docs/StubUtilities.md
  • docs/TriggerContext.md
  • docs/TriggerFrameworkLoopCount.md
  • docs/ULID.md
  • docs/UniversalFlowInputOutput.md
Review comments generated (22)
  • Review: 5
  • LGTM: 17

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

docs/BulkCallable.md Outdated Show resolved Hide resolved
docs/FeatureFlagDataProvider.md Outdated Show resolved Hide resolved
docs/FeatureFlagDataProvider.md Outdated Show resolved Hide resolved
docs/TriggerFramework.md Outdated Show resolved Hide resolved
docs/UFInvocable.md Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 7897308 and a5b7261 commits.
Files selected (2)
  • docs/CAssert.md (1)
  • force-app/main/default/classes/test utilities/CAssert.cls (1)
Review comments generated (6)
  • Review: 5
  • LGTM: 1

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between b36452f and a5b7261 commits.
Files selected (4)
  • docs/CAssert.md (1)
  • docs/home.md (1)
  • force-app/main/default/classes/test utilities/CAssert.cls (1)
  • force-app/main/default/classes/test utilities/CAssert.cls-meta.xml (1)
Files ignored due to filter (1)
  • config/project-scratch-def.json
Files skipped from review due to trivial changes (1)
  • force-app/main/default/classes/test utilities/CAssert.cls-meta.xml
Review comments generated (7)
  • Review: 6
  • LGTM: 1

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +14 to +15
### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The new CAssert class is mentioned in the documentation, but there's no description provided for it. It would be helpful to include a brief explanation of what this class does and how it can be used.

### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert)
+ A 'shadow' Assert class that facilitates developers adding custom assertion methods that can still be cleanly read as `Assert.methodName`.

 ### [CachePartitionType](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CachePartitionType)

Comment on lines +1 to +266

/**
* @description An assertion to validate that the object is an SObject
*
* @param obj Object - the object to validate
* @param msg String - the message to display if the assertion fails
*/
public static void isSObject(Object obj, String msg) {
System.Assert.isInstanceOfType(obj, SObject.class, msg);
}

/**
* @description An assertion to validate that the exception is of the expected type
*
* @param incomingException Exception - the exception to validate
* @param expectedExceptionType Type - the expected type of the exception
* @param msg String - the message to display if the assertion fails
*/
public static void caughtExpectedException(
Exception incomingException,
Type expectedExceptionType,
String msg
) {
System.Assert.isInstanceOfType(
incomingException,
expectedExceptionType,
msg
);
}

/**
* @description An assertion to validate that the exception is of the expected type and contains the expected
* message
*
* @param incomingException Exception - the exception to validate
* @param expectedExceptionType Type - the expected type of the exception
* @param expectedExceptionMessage String - A string that must exist in the resulting exception message
* @param msg String - the message to display if the assertion fails
*/
public static void caughtExpectedException(
Exception incomingException,
Type expectedExceptionType,
String expectedExceptionMessage,
String msg
) {
System.Assert.isInstanceOfType(
incomingException,
expectedExceptionType,
msg
);
System.Assert.isTrue(
incomingException.getMessage()
.containsIgnoreCase(expectedExceptionMessage),
msg
);
}

/**
* @description An assertion that validates the given value is within a given range
*
* @param value Integer - the value to validate
* @param min Integer - the minimum value the value must be
* @param max Integer - the maximum value the value must be
* @param msg String - the message to display if the assertion fails
*/
public static void isInRange(
Integer value,
Integer min,
Integer max,
String msg
) {
System.Assert.isTrue(value >= min && value <= max, msg);
}

/**
* @description An Assertion that validates that LogEvent__c records were generated.
* Note: this relies on the Log class that's part of ApexKit
*
* @param msg String - the message to display if the assertion fails
*/
public static void logsWereGenerated(String msg) {
Integer logEvents = [
SELECT COUNT()
FROM LogEvent__c
WITH SYSTEM_MODE
];
System.Assert.isTrue(logEvents > 0, msg);
}

/**
* @description An assertion that validates that LogEvent__c records were generated.
* Note this relies on the Log class that's part of ApexKit. This method override accepts no parameters
* but delegates to the variant above by specifying a default message.
*/
public static void logsWereGenerated() {
logsWereGenerated(
'Though expected, no log events were generated - if youre not using test.StopTest the events will never publish'
);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The CAssert class seems to be well implemented with a variety of assertion methods for different conditions. However, there are some issues that need to be addressed.

Comment on lines +136 to +138
public static void isNotJanky(String msg) {
System.Assert.fail(msg);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The isNotJanky method always fails the assertion without checking any condition. If this is intended as a joke or placeholder, it might be better to add a more detailed comment explaining its purpose or remove it if it's not needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codefriar CodeRabbit wants to know if this method is some kind of joke.

Comment on lines +248 to +253
Integer logEvents = [
SELECT COUNT()
FROM LogEvent__c
WITH SYSTEM_MODE
];
System.Assert.isTrue(logEvents > 0, msg);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

In the logsWereGenerated method, you're querying all LogEvent__c records in the system. This could potentially return a large number of records and consume a lot of resources, especially in a production environment. It would be better to filter the query based on specific criteria relevant to the test context.

Comment on lines +262 to +265
logsWereGenerated(
'Though expected, no log events were generated - if youre not using test.StopTest the events will never publish'
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

In the overloaded logsWereGenerated method, the default message might be confusing for developers who are not familiar with the test.StopTest method. Consider revising the message to make it clearer or provide more context.

@dschach dschach self-requested a review April 3, 2024 17:09
@dschach
Copy link
Collaborator

dschach commented Apr 3, 2024

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Custom Assertions
2 participants