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

Add support for editing expenses #199

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Add support for editing expenses #199

merged 1 commit into from
Jun 26, 2024

Conversation

Hrishabh17
Copy link
Contributor

@Hrishabh17 Hrishabh17 commented Jun 26, 2024

Summary by CodeRabbit

  • New Features
    • Introduced update_non_exported_expenses function to handle non-exported expenses.
  • Improvements
    • Enhanced error handling with new validation logic in various modules.
    • Added detailed logging for better traceability in webhook processing.
  • Bug Fixes
    • Improved validation to ensure requests contain valid workspace and organization IDs.
  • Dependencies
    • Updated fyle to version 0.37.0.
    • Updated fyle-integrations-platform-connector to version 1.38.1.
  • Tests
    • Added extensive test fixtures and test cases to improve coverage.

@Hrishabh17 Hrishabh17 requested a review from ashwin1111 June 26, 2024 10:45
Copy link

Tests Skipped Failures Errors Time
136 0 💤 0 ❌ 0 🔥 10.645s ⏱️

Copy link

coderabbitai bot commented Jun 26, 2024

Walkthrough

The recent changes introduce new functionalities and improvements across several modules. These include enhanced exception handling and validation in exceptions.py and helpers.py, enriched logging and task handling in queue.py, and additions to testing data and logic in fixtures.py and test_tasks.py. Furthermore, the WebhookCallbackView view now supports workspace IDs, and updates to package dependencies reflect improved capabilities.

Changes

File Path Change Summary
apps/fyle/exceptions.py Added import and handler for ValidationError. Logs exception and returns error response.
apps/fyle/helpers.py Imported ValidationError, Workspace, and added assert_valid_request function.
apps/fyle/queue.py Added logging, changed async_handle_webhook_callback to include workspace_id.
apps/fyle/tasks.py Added update_non_exported_expenses function to update expenses based on state.
apps/fyle/views.py Updated WebhookCallbackView to pass workspace_id to async_handle_webhook_callback.
requirements.txt Updated fyle and fyle-integrations-platform-connector to newer versions.
tests/test_fyle/fixtures.py Enhanced fixtures with detailed expense data structures for testing purposes.
tests/test_fyle/test_tasks.py Added test_update_non_exported_expenses for testing the expense update functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant WebhookView as WebhookCallbackView
    participant Queue as async_handle_webhook_callback
    participant Logger as Logger
    participant Tasks as update_non_exported_expenses

    User ->> WebhookView: POST /webhook with workspace_id
    WebhookView ->> Queue: Call async_handle_webhook_callback with body, workspace_id
    Queue ->> Logger: Log the webhook call details
    Queue ->> Tasks: Update non-exported expenses
    Tasks ->> Logger: Log expense update details
    Tasks ->> Queue: Return result of update
    Queue ->> WebhookView: Return response

    alt Validation Error
        WebhookView ->> Logger: Log error details
        WebhookView ->> User: Return error response
    else Success
        WebhookView ->> User: Return success response
    end
Loading

Poem

In fields of code where bytes do play,
A rabbit hops without delay. 🐇
Logs and errors now in hand,
Webhooks dance to our command.
Tasks update with gentle care,
Bringing joy beyond compare.
With each test, we're soaring high,
Our software reaches to the sky! ☁️

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2b2740d and 63ab1a1.

Files selected for processing (8)
  • apps/fyle/exceptions.py (2 hunks)
  • apps/fyle/helpers.py (2 hunks)
  • apps/fyle/queue.py (4 hunks)
  • apps/fyle/tasks.py (2 hunks)
  • apps/fyle/views.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/test_fyle/fixtures.py (1 hunks)
  • tests/test_fyle/test_tasks.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • requirements.txt
Additional comments not posted (7)
tests/test_fyle/test_tasks.py (1)

12-62: Comprehensive Test Coverage for update_non_exported_expenses

The test function test_update_non_exported_expenses adequately covers various scenarios including state changes and error handling. This ensures robustness in the feature's behavior under different conditions.

apps/fyle/queue.py (1)

6-6: Enhancements to Webhook Handling and Logging

The addition of workspace_id to async_handle_webhook_callback and the integration of logging and validation checks are significant improvements. These changes enhance the robustness and traceability of the webhook handling mechanism.

Also applies to: 15-18, 69-88

apps/fyle/views.py (1)

143-143: Correct Integration of workspace_id in Webhook Callback

The update to include workspace_id in the post method of WebhookCallbackView ensures that the webhook handling is consistent with the workspace-specific enhancements made in other parts of the application.

apps/fyle/exceptions.py (1)

8-8: Enhanced Error Handling for Validation Errors

The addition of a handling block for ValidationError improves the application's robustness by ensuring that such errors are logged and appropriately communicated to the client.

Also applies to: 94-96

apps/fyle/tasks.py (1)

127-149: Implementation of update_non_exported_expenses

The new function update_non_exported_expenses is implemented to handle updates to expenses based on their current state, ensuring that only eligible expenses are updated. This is a critical enhancement for the feature of editing expenses.

apps/fyle/helpers.py (1)

8-10: Imports are correctly used.

The ValidationError is used for raising exceptions in the new function, and Workspace is used to fetch workspace details, validating their necessity.

tests/test_fyle/fixtures.py (1)

2-267: Test fixtures expanded to support new functionalities.

The additions to the test fixtures are comprehensive and seem well-designed to support the new functionalities related to expense management and validation.

Comment on lines +261 to +268
def assert_valid_request(workspace_id:int, org_id:str):
"""
Assert if the request is valid by checking
the url_workspace_id and fyle_org_id workspace
"""
workspace = Workspace.objects.get(org_id=org_id)
if workspace.id != workspace_id:
raise ValidationError('Workspace mismatch')
Copy link

Choose a reason for hiding this comment

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

Consider handling the case where no workspace matches the given org_id.

Currently, if no workspace is found, a Workspace.DoesNotExist exception will be raised. It would be more user-friendly to catch this exception and raise a ValidationError with a clear message.

- workspace = Workspace.objects.get(org_id=org_id)
+ try:
+     workspace = Workspace.objects.get(org_id=org_id)
+ except Workspace.DoesNotExist:
+     raise ValidationError(f"No workspace found for org_id {org_id}")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def assert_valid_request(workspace_id:int, org_id:str):
"""
Assert if the request is valid by checking
the url_workspace_id and fyle_org_id workspace
"""
workspace = Workspace.objects.get(org_id=org_id)
if workspace.id != workspace_id:
raise ValidationError('Workspace mismatch')
def assert_valid_request(workspace_id:int, org_id:str):
"""
Assert if the request is valid by checking
the url_workspace_id and fyle_org_id workspace
"""
try:
workspace = Workspace.objects.get(org_id=org_id)
except Workspace.DoesNotExist:
raise ValidationError(f"No workspace found for org_id {org_id}")
if workspace.id != workspace_id:
raise ValidationError('Workspace mismatch')

elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE':
org_id = body['data']['org_id']
logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data')))
assert_valid_request(workspace_id=workspace_id, org_id=org_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

move out

@Hrishabh17 Hrishabh17 merged commit 92b33ce into master Jun 26, 2024
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
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