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: add specs for trigger errors #1151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

himanshu-dixit
Copy link
Collaborator

@himanshu-dixit himanshu-dixit commented Jan 3, 2025

🔍 Review Summary

This update adds two test cases to triggers.spec.ts for error handling and includes a minor formatting tweak in formatter.ts. These are minor adjustments with minimal impact on the overall codebase.

Original Description

[!IMPORTANT]
Add tests for trigger errors and refine error message formatting in triggers.spec.ts and formatter.ts.

  • Tests:
    • Add test in triggers.spec.ts to throw TriggerNotFoundError when an invalid trigger ID is used.
    • Add test in triggers.spec.ts to throw BadRequestError for invalid connected account IDs.
  • Error Handling:
    • Refine error message formatting in getAPIErrorDetails() in formatter.ts to include error name and type more clearly.

This description was created by Ellipsis for 80ca3b4. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 7:40am

Copy link

Walkthrough

The PR introduces two new test cases in triggers.spec.ts to handle error scenarios and a minor formatting change in formatter.ts. These changes are minor and do not significantly impact the codebase.

🔗 Related PRs

Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @bot + *your message*
Example: @bot Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @bot + *feedback*
Example: @bot Do not comment on `save_auth` function !

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 80ca3b4 in 12 seconds

More details
  • Looked at 56 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js/src/sdk/models/triggers.spec.ts:103
  • Draft comment:
    Duplicate test case for "should throw an error if trigger not found". Consider removing this to avoid redundancy.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_pQ7kd59Lr8ahBT61


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

const error = e as ComposioError;
expect(error.message).toContain("BadRequestError");
expect(error.description).toContain(
"Invalid connected account ids provi"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error description appears to be truncated. Consider using the complete error message in the test assertion to ensure we're testing against the full expected error message. This will make the test more robust and easier to debug if it fails.

Copy link

github-actions bot commented Jan 3, 2025

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12647203702/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12647203702/html-report/report.html

@@ -100,6 +100,37 @@ describe("Apps class tests subscribe", () => {
expect(res.config.title).toBe("GmailNewMessageConfigSchema");
});

it("should throw an error if trigger not found", async () => {
let isErrorThrown = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider extracting the error testing pattern into a helper function since it's repeated in both test cases. This would reduce code duplication and make the tests more maintainable. Example:

async function expectErrorToBeThrown(asyncFn: () => Promise<any>, expectedError: string) {
  let isErrorThrown = false;
  try {
    await asyncFn();
  } catch (e: unknown) {
    isErrorThrown = true;
    const error = e as ComposioError;
    expect(error.message).toContain(expectedError);
  }
  expect(isErrorThrown).toBe(true);
}

@shreysingla11
Copy link
Collaborator

Code Review Summary

Changes Overview

  • Added test coverage for error scenarios in triggers functionality
  • Modified error message formatting in formatter.ts for better readability
  • Added two new test cases for invalid trigger ID and invalid connected account ID

Positive Aspects

✅ Good test coverage for error scenarios
✅ Improved error message formatting
✅ Consistent error handling pattern
✅ Good use of TypeScript type assertions

Suggestions for Improvement

  1. Complete the truncated error message in test assertion
  2. Consider extracting repeated error testing pattern into a helper function
  3. Consider adding JSDoc comments for the test cases to document the error scenarios being tested

Overall Assessment

The changes are well-structured and improve the error handling test coverage. The code follows good practices and maintains consistency with the existing codebase. With the suggested minor improvements, this PR is ready to be merged.

Rating: 8/10 👍

Comment on lines 100 to +107
expect(res.config.title).toBe("GmailNewMessageConfigSchema");
});

it("should throw an error if trigger not found", async () => {
let isErrorThrown = false;
try {
await triggers.getTriggerConfig({
triggerId: "INVALID_TRIGGER_ID",

Choose a reason for hiding this comment

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

Code Quality: The added test case for error handling is a positive addition, ensuring that the system behaves correctly when an invalid trigger ID is provided. However, the test could be improved by using a more descriptive variable name for isErrorThrown and by asserting the error message to ensure the correct error is thrown.

🔧 Suggested Code Diff:
 it("should throw an error if trigger not found", async () => {
-    let isErrorThrown = false;
+    let errorOccurred = false;
    try {
      await triggers.getTriggerConfig({
        triggerId: "INVALID_TRIGGER_ID",
      });
    } catch (error) {
-      isErrorThrown = true;
+      errorOccurred = true;
+      expect(error.message).toBe("Expected error message");
    }
-    expect(isErrorThrown).toBe(true);
+    expect(errorOccurred).toBe(true);
  });
📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
expect(res.config.title).toBe("GmailNewMessageConfigSchema");
});
it("should throw an error if trigger not found", async () => {
let isErrorThrown = false;
try {
await triggers.getTriggerConfig({
triggerId: "INVALID_TRIGGER_ID",
it("should throw an error if trigger not found", async () => {
let errorOccurred = false;
try {
await triggers.getTriggerConfig({
triggerId: "INVALID_TRIGGER_ID",
});
} catch (error) {
errorOccurred = true;
expect(error.message).toBe("Expected error message");
}
expect(errorOccurred).toBe(true);
});

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.

2 participants