Skip to content

[ECO-5441] Message update and delete tests#334

Merged
maratal merged 2 commits intomainfrom
324-message-soft-delete-tests
Jul 25, 2025
Merged

[ECO-5441] Message update and delete tests#334
maratal merged 2 commits intomainfrom
324-message-soft-delete-tests

Conversation

@maratal
Copy link
Copy Markdown
Collaborator

@maratal maratal commented Jul 20, 2025

Closes #324

Tests for message update and delete didn't exist, so I've added them.

Summary by CodeRabbit

  • Bug Fixes

    • Ensured deleted messages return empty text, metadata, and headers for consistency.
    • Clarified message update behavior in line with protocol specifications.
  • Tests

    • Expanded tests to cover sending, updating, and deleting messages with metadata and headers.
    • Added tests for error handling in update and delete operations.
    • Enhanced mock responses with version and timestamp fields for improved test accuracy.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 20, 2025

Walkthrough

This update modifies the message update and delete logic to ensure non-optional metadata and consistent empty values for deleted messages. It adds clarifying comments about specification compliance, enriches mock response data with version and timestamp fields, and significantly expands and renames tests to cover sending, updating, and deleting messages, including error handling for each operation.

Changes

File(s) Change Summary
Sources/AblyChat/ChatAPI.swift Adds comment on PUT semantics non-compliance; sets empty text, metadata, headers for deleted messages per spec
Tests/AblyChatTests/DefaultMessagesTests.swift Renames and expands send test to include update and delete; adds error tests for update and delete operations
Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift Adds version and timestamp fields to mock send message response

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DefaultMessages
    participant ChatAPI

    Client->>DefaultMessages: send(message)
    DefaultMessages->>ChatAPI: sendMessage(message)
    ChatAPI-->>DefaultMessages: Message(sent)
    DefaultMessages-->>Client: Message(sent)

    Client->>DefaultMessages: update(message)
    DefaultMessages->>ChatAPI: updateMessage(message)
    ChatAPI-->>DefaultMessages: Message(updated)
    DefaultMessages-->>Client: Message(updated)

    Client->>DefaultMessages: delete(message)
    DefaultMessages->>ChatAPI: deleteMessage(message)
    ChatAPI-->>DefaultMessages: Message(empty fields)
    DefaultMessages-->>Client: Message(empty fields)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In codey fields where messages hop,
Updates and deletes now never stop.
Metadata’s tidy, no nils in sight,
Empty fields for deletes—done right!
With tests that bound and mocks that gleam,
Our chat is smoother than a dream.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a97e2fd and cc67e0d.

📒 Files selected for processing (2)
  • Sources/AblyChat/ChatAPI.swift (2 hunks)
  • Tests/AblyChatTests/DefaultMessagesTests.swift (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Sources/AblyChat/ChatAPI.swift
🔇 Additional comments (8)
Tests/AblyChatTests/DefaultMessagesTests.swift (8)

12-17: LGTM! Good improvement in test naming and spec coverage.

The method name change better reflects the expanded functionality, and the additional spec comments properly document the message update and delete operations being tested.


27-37: Enhanced test coverage for message metadata and headers.

Good improvement! The test now verifies that metadata and headers are properly included in both the sent message and the HTTP request body, providing more comprehensive coverage.


39-52: Well-implemented update message test with proper verification.

The test correctly covers the update functionality by modifying the sent message and verifying both the returned message properties and the HTTP request structure. The reference to issue #333 suggests there may be constraints around message modification - ensure this approach aligns with the intended API design.


54-65: Comprehensive delete message test with correct empty field verification.

The test properly verifies the delete functionality by checking that deleted messages have empty text, headers, and metadata fields, and that the correct HTTP POST request is made to the delete endpoint. This aligns with the specification requirement CHA-M9b.


70-70: Good clarification in test method naming.

The renamed method name better specifies that this test covers send operation errors, distinguishing it from the new update and delete error tests.


91-113: Well-structured error handling test for update operations.

The test properly follows the established pattern for error testing and correctly verifies that errors from update operations are propagated. The mock message creation includes all necessary fields for a realistic test scenario.


115-137: Consistent error handling test for delete operations.

The test properly follows the established pattern and correctly verifies that errors from delete operations are propagated. Good consistency with the update error test implementation.


144-144: Improved semantic correctness of mock responses.

Good change! Using successGetMessagesWithNoItems instead of successSendMessageWithNoItems is more appropriate for these tests that focus on message retrieval and subscription operations rather than sending messages.

Also applies to: 169-169, 199-199, 243-243

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 324-message-soft-delete-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@maratal maratal changed the base branch from main to 321-soft-deletes-and-validation-loosening July 20, 2025 09:37
@maratal maratal changed the title Message update and delete tests [ECO-5441] Message update and delete tests Jul 20, 2025
@github-actions github-actions Bot temporarily deployed to staging/pull/334/AblyChat July 20, 2025 09:38 Inactive
@maratal maratal force-pushed the 324-message-soft-delete-tests branch from c719b71 to a97e2fd Compare July 20, 2025 11:35
@github-actions github-actions Bot temporarily deployed to staging/pull/334/AblyChat July 20, 2025 11:37 Inactive
@maratal maratal requested a review from umair-ably July 20, 2025 11:53
Comment thread Sources/AblyChat/ChatAPI.swift Outdated
Base automatically changed from 321-soft-deletes-and-validation-loosening to main July 22, 2025 23:22
@maratal maratal merged commit 7b2c4e9 into main Jul 25, 2025
41 checks passed
@maratal maratal deleted the 324-message-soft-delete-tests branch July 25, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Introduce tests for soft deletes changes

2 participants