Skip to content

Conversation

@xsahil03x
Copy link
Member

Description of the pull request

This PR introduces a new declarative testers (feedTest, activityTest, activityListTest, etc.) to streamline tests for state management classes like Feed, Activity, and ActivityList.

The new testers simplifies test structure by abstracting away boilerplate setup for clients, API mocks, and WebSocket connections. It provides a consistent, BDD-style (build, setUp, body, verify) for writing tests.

Key changes:

  • Refactored feed_test.dart, activity_test.dart, and activity_list_test.dart to use the new testing harness.
  • Removed redundant setup/teardown code and manual mock/event handling in favor of the tester's helper methods (e.g., tester.get(), tester.emitEvent()).
  • Added state and stream accessors (e.g., tester.feedState, tester.feedStateStream) to the testers for easier assertions.
  • Removed the tester.expect() method in favor of using standard expect() from package:test for better consistency.
  • Standardized test utilities, including EventTypes constants and default response creators.

This PR regenerates the client-side API models and endpoints, incorporating numerous additions and breaking changes from a recent backend API update.

### Breaking Changes
- **`queryFollowSuggestions`:** The method signature and return type have changed. It now returns a `Result<List<FeedSuggestionData>>` instead of `Result<List<FeedData>>`. The new `FeedSuggestionData` model includes additional metadata like `reason`, `recommendationScore`, and `algorithmScores`.
- **`FeedsReactionData.id`:** The logic for generating a reaction's unique ID has been updated to correctly include the `commentId` when present, ensuring proper identification for comment reactions.

### Features
- **Collections API:** Added full support for the Collections API, including new request/response models and endpoints for creating, reading, updating, and deleting collections (`CreateCollections`, `ReadCollections`, `UpdateCollections`, `DeleteCollections`).
- **`ActivityData` Enhancements:** Added `hidden` and `preview` boolean fields to the `ActivityData` model to support content hiding and previewing functionalities.
- **`FeedSuggestionData` Model:** Introduced a new `FeedSuggestionData` model to encapsulate feed suggestions, providing richer context with algorithmic scores and reasons.
- **Moderation and Deletion Reasons:** Added an optional `reason` field to various deletion and moderation requests (`DeleteActivityRequest`, `DeleteCommentRequest`, `DeleteReactionRequest`, `DeleteUserRequest`, `BlockActionRequest`, `ShadowBlockActionRequest`) to provide context for moderation actions.

### Other Key Changes
- **API Model Updates:**
  - `ActivityRequest` and `UpdateActivityRequest` now include `collectionRefs`, `restrictReplies`, and `skipEnrichUrl`.
  - `ActivityResponse` now includes `collections`, `moderationAction`, `preview`, `hidden`, and `restrictReplies`.
  - `ChannelMemberResponse` and related models have been significantly expanded with new fields like `banned`, `createdAt`, `custom`, `role`, and more.
  - `ChannelResponse` and `Channel` models now include `filterTags`.
  - Introduced `ActivityFeedbackEvent` for real-time feedback updates.
  - Deprecated `muteUser` and `report` from `ActivityFeedbackRequest`.
- **Endpoint and Request Adjustments:**
  - Made `addCommentRequest` in the `addComment` endpoint nullable.
  - Removed the deprecated `activitySelectorOptions` from `FeedQuery` and `GetOrCreateFeedRequest`.
- **Testing:** Added tests for the new `queryFollowSuggestions` functionality to validate the handling of `FeedSuggestionData`.
This commit pins the `retrofit` dependency to a version range of `>=4.6.0 <=4.9.0`.

This change is necessary to avoid a breaking change introduced in `retrofit` version 4.10.0. The version constraint is applied in the root `melos.yaml` and the `packages/stream_feeds/pubspec.yaml` file.
This commit introduces the ability to submit feedback for activities, such as marking an activity as hidden. It adds an `activityFeedback` method to the `Activity` and `Feed` classes and handles real-time state updates via WebSocket events.

Key changes:
- **API**: Added `activityFeedback` method to `ActivitiesRepository`, `Activity`, and `Feed` to allow submitting feedback (e.g., hide/unhide).
- **State Management**: Implemented `onActivityHidden` handlers in `ActivityState`, `ActivityListState`, and `FeedState` to update the `hidden` status of activities in response to `ActivityFeedbackEvent` from WebSockets.
- **Event Handling**: `ActivityEventHandler`, `ActivityListEventHandler`, and `FeedEventHandler` now process `ActivityFeedbackEvent` to trigger state updates, ensuring the UI reflects whether an activity is hidden.
- **Testing**:
    - Introduced a new suite of test utilities (`BaseTester`, `ActivityTester`, `FeedTester`, `ActivityListTester`, `ApiMockerMixin`) to streamline testing of stateful objects with API and WebSocket interactions.
    - Added comprehensive tests for the new activity feedback functionality, covering both API calls and real-time event handling.
- **Refactor**: Minor refactoring in test helpers (`fakes.dart`) to improve consistency.
This commit introduces a new declarative testers (`feedTest`, `activityTest`, `activityListTest`, etc.) to streamline tests for state management classes like `Feed`, `Activity`, and `ActivityList`.

The new testers simplifies test structure by abstracting away boilerplate setup for clients, API mocks, and WebSocket connections. It provides a consistent, BDD-style (`build`, `setUp`, `body`, `verify`) for writing tests.

Key changes:
- Refactored `feed_test.dart`, `activity_test.dart`, and `activity_list_test.dart` to use the new testing harness.
- Removed redundant setup/teardown code and manual mock/event handling in favor of the tester's helper methods (e.g., `tester.get()`, `tester.emitEvent()`).
- Added state and stream accessors (e.g., `tester.feedState`, `tester.feedStateStream`) to the testers for easier assertions.
- Deprecated the `tester.expect()` method in favor of using standard `expect()` from `package:test` for better consistency.
- Standardized test utilities, including `EventTypes` constants and default response creators.
@xsahil03x xsahil03x requested a review from a team as a code owner November 25, 2025 06:38
This commit refactors the WebSocket testing utilities to simplify test setup and enhance maintainability.

The `ws_test_helpers.dart` file has been removed, and its functionality is replaced by a new, more streamlined `whenListenWebSocket` function in `web_socket_mocks.dart`. This function encapsulates the mock setup for `WebSocketChannel`, including handling authentication responses.

Key changes:
- **Replaced `WsTestConnection` with `whenListenWebSocket`**: Simplified the setup for mocking WebSocket channels in tests.
- **Improved test token generation**: Replaced a hardcoded JWT with a `generateTestUserToken` function for creating test tokens dynamically.
- **Relocated `api_mocker_mixin.dart`**: Moved the file for better organization within the test utilities.
- **Removed unused mocks**: Cleaned up the `mocks.dart` file by removing `MockFeedsRepository`, `MockFeedsClient`, `MockWebSocketClient`, `MockWebSocketSink`, and `FakeFeedsClient`.
- **Updated test implementation**: All tests now use the new `whenListenWebSocket` helper and dynamic token generation, reducing boilerplate and improving clarity.
@xsahil03x xsahil03x requested a review from Copilot November 25, 2025 07:55
Copilot finished reviewing on behalf of xsahil03x November 25, 2025 07:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a comprehensive refactoring of the test infrastructure for state management classes in the stream_feeds package. It replaces manual test setup/teardown with declarative testers (feedTest, activityTest, activityListTest, etc.) that provide a consistent BDD-style API (build, setUp, body, verify).

Key changes:

  • Introduces declarative test helpers for all state manager types (Feed, Activity, ActivityList, and various List types)
  • Replaces WsTestConnection with a simpler whenListenWebSocket function
  • Removes tester.expect() in favor of standard expect() for better consistency
  • Adds EventTypes constants and improved fake data creators

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web_socket_mocks.dart New simplified WebSocket mocking replacing ws_test_helpers.dart
base_tester.dart Removed custom expect() methods, simplified WebSocket setup, uses generated test tokens
mocks.dart Removed unused mocks, added generateTestUserToken() helper for dynamic JWT generation
fakes.dart Renamed and enhanced fake creators with optional parameters for flexibility
event_types.dart Expanded event type constants for comprehensive coverage
api_mocker_mixin.dart Fixed import path
poll_vote_list_tester.dart New declarative tester for poll vote list operations
poll_list_tester.dart New declarative tester for poll list operations
follow_list_tester.dart New declarative tester for follow list operations
feed_list_tester.dart New declarative tester for feed list operations
comment_list_tester.dart New declarative tester for comment list operations
bookmark_list_tester.dart New declarative tester for bookmark list operations
bookmark_folder_list_tester.dart New declarative tester for bookmark folder list operations
feed_tester.dart Added state accessors and uses query parameter instead of reconstructing
activity_tester.dart Added state accessors for consistency
activity_list_tester.dart Added state accessors for consistency
feed_test.dart Refactored to use new declarative test harness
activity_test.dart Refactored to use new declarative test harness
activity_list_test.dart Refactored to use new declarative test harness
poll_vote_list_test.dart Refactored to use new declarative test harness
poll_list_test.dart Refactored to use new declarative test harness
follow_list_test.dart Refactored to use new declarative test harness
feed_list_test.dart Refactored to use new declarative test harness
comment_list_test.dart Refactored to use new declarative test harness
bookmark_list_test.dart Refactored to use new declarative test harness
bookmark_folder_list_test.dart Refactored to use new declarative test harness
feeds_client_impl_test.dart Updated to use generated test token
lib/src/state.dart Added exports for state and list state classes
lib/src/models.dart Added exports for data model classes
dart_test.yaml Added test tags for all list types
test_utils.dart Updated exports to reflect new tester structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This commit refactors test utilities by moving `MockWebSocketSink` from `web_socket_mocks.dart` to the centralized `mocks.dart` file.

This change avoids duplicating mock definitions and improves the organization of test helper code. The `whenListenWebSocket` function has been updated to use the centrally defined mocks.
@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.79%. Comparing base (e705228) to head (5e47adb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   45.04%   45.79%   +0.75%     
==========================================
  Files         121      121              
  Lines        3730     3730              
==========================================
+ Hits         1680     1708      +28     
+ Misses       2050     2022      -28     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The `wsStreamController.stream` in `mockWebSocketChannel` is now converted to a broadcast stream using `asBroadcastStream()`.

This change allows the stream to be listened to multiple times, which is necessary for certain test scenarios involving WebSocket interactions.
Base automatically changed from feat/activity-feedback-operation to main November 25, 2025 13:23
# Conflicts:
#	packages/stream_feeds/dart_test.yaml
#	packages/stream_feeds/lib/src/state.dart
#	packages/stream_feeds/test/state/activity_list_test.dart
#	packages/stream_feeds/test/state/activity_test.dart
#	packages/stream_feeds/test/state/feed_test.dart
#	packages/stream_feeds/test/test_utils.dart
#	packages/stream_feeds/test/test_utils/event_types.dart
#	packages/stream_feeds/test/test_utils/fakes.dart
#	packages/stream_feeds/test/test_utils/testers/activity_list_tester.dart
#	packages/stream_feeds/test/test_utils/testers/activity_tester.dart
#	packages/stream_feeds/test/test_utils/testers/base_tester.dart
#	packages/stream_feeds/test/test_utils/testers/feed_tester.dart
@xsahil03x xsahil03x enabled auto-merge (squash) November 25, 2025 13:34
@xsahil03x xsahil03x merged commit d14ccba into main Nov 25, 2025
8 checks passed
@xsahil03x xsahil03x deleted the refactor/use-testers branch November 25, 2025 13:42
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.

3 participants