19bd8c1810
CI / flutter-gates (push) Successful in 2m26s
- community_models:community/media 域 DTO 逐字段照冻结契约手写 JSON 映射 (Post/FeedCard/PostComment/AuthorSummary 降级形态/媒体两步上传凭据等), 未知枚举抛 FormatException 暴露契约漂移;CursorPage 上移 core 复用 - community_repository:13 路径 19 操作全覆盖;createPost/createComment 必带 Idempotency-Key(每次逻辑提交换新键、刷新重放同键);点赞/收藏/ 关注走 PUT/DELETE 语义幂等 - community_exceptions:v1.3.0 新增 9 码 + 40902 共码类型化异常映射 - toggle_sync:乐观翻转 + 快照回滚 + 单飞合并最终意图 + 代次守卫, 点赞/收藏共用一套参数化状态机,权威终态对账收敛 - community_controller:Feed 多页缓存 + 首屏四态 + 尾部加载三态 + 游标拼接 + 刷新代次丢弃旧尾页;详情副本与卡片互动状态同源;reset 清态 - app.dart 装配:community 服务分端口直连(:8084),共享 TokenRefresher, 登出同步 reset - 测试 286 → 347(模型映射 / 19 操作线路 / 错误映射 / 竞态序列全覆盖) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
238 lines
6.6 KiB
Dart
238 lines
6.6 KiB
Dart
import 'package:patbond_flutter/features/community/community_models.dart';
|
|
import 'package:patbond_flutter/features/community/community_repository.dart';
|
|
|
|
/// community 域测试样本 JSON(字段与契约 v1.3.0 逐字一致)。
|
|
|
|
Map<String, dynamic> sampleAuthorJson({
|
|
String userId = 'u-1',
|
|
String? nickname = '毛毛的铲屎官',
|
|
String? avatarUrl = 'https://minio.local/avatar.jpg?X-Amz-Signature=sig',
|
|
}) => {'userId': userId, 'nickname': nickname, 'avatarUrl': avatarUrl};
|
|
|
|
Map<String, dynamic> samplePostMediaItemJson({
|
|
String assetId = 'a-1',
|
|
int position = 0,
|
|
bool isCover = true,
|
|
}) => {
|
|
'assetId': assetId,
|
|
'position': position,
|
|
'isCover': isCover,
|
|
'url': 'https://minio.local/p.jpg?X-Amz-Signature=sig',
|
|
'widthPx': 1080,
|
|
'heightPx': 810,
|
|
'caption': '晒太阳',
|
|
};
|
|
|
|
Map<String, dynamic> samplePostJson({
|
|
String id = 'p-1',
|
|
String status = 'published',
|
|
bool likedByMe = false,
|
|
int likeCount = 6,
|
|
bool bookmarkedByMe = false,
|
|
int bookmarkCount = 2,
|
|
int version = 1,
|
|
}) => {
|
|
'id': id,
|
|
'author': sampleAuthorJson(),
|
|
'petId': 'pet-1',
|
|
'category': 'general',
|
|
'title': '今天的豆豆',
|
|
'content': '晒了一下午太阳。',
|
|
'status': status,
|
|
'visibility': 'public',
|
|
'media': [samplePostMediaItemJson()],
|
|
'likeCount': likeCount,
|
|
'commentCount': 3,
|
|
'bookmarkCount': bookmarkCount,
|
|
'likedByMe': likedByMe,
|
|
'bookmarkedByMe': bookmarkedByMe,
|
|
'createdAt': '2026-09-08T10:00:00.000Z',
|
|
'updatedAt': '2026-09-08T10:05:00.000Z',
|
|
'publishedAt': status == 'published' ? '2026-09-08T10:05:00.000Z' : null,
|
|
'version': version,
|
|
};
|
|
|
|
Map<String, dynamic> sampleFeedCardJson({
|
|
String id = 'p-1',
|
|
bool likedByMe = false,
|
|
int likeCount = 6,
|
|
bool bookmarkedByMe = false,
|
|
int bookmarkCount = 2,
|
|
}) => {
|
|
'id': id,
|
|
'author': sampleAuthorJson(),
|
|
'category': 'general',
|
|
'title': '今天的豆豆',
|
|
'contentPreview': '晒了一下午太阳。',
|
|
'coverImage': samplePostMediaItemJson(),
|
|
'mediaCount': 1,
|
|
'likeCount': likeCount,
|
|
'commentCount': 3,
|
|
'bookmarkCount': bookmarkCount,
|
|
'likedByMe': likedByMe,
|
|
'bookmarkedByMe': bookmarkedByMe,
|
|
'publishedAt': '2026-09-08T10:05:00.000Z',
|
|
};
|
|
|
|
Map<String, dynamic> sampleCommentJson({
|
|
String id = 'c-1',
|
|
Map<String, dynamic>? replyToUser,
|
|
}) => {
|
|
'id': id,
|
|
'postId': 'p-1',
|
|
'author': sampleAuthorJson(),
|
|
'replyToUser': replyToUser,
|
|
'content': '好可爱!',
|
|
'createdAt': '2026-09-08T11:00:00.000Z',
|
|
};
|
|
|
|
Map<String, dynamic> sampleUploadCredentialsJson() => {
|
|
'assetId': 'a-1',
|
|
'uploadUrl':
|
|
'https://minio.local/patbond-media/post_image/a-1?X-Amz-Signature=sig',
|
|
'method': 'PUT',
|
|
'requiredHeaders': {'Content-Type': 'image/jpeg'},
|
|
'expiresAt': '2026-09-08T10:10:00.000Z',
|
|
};
|
|
|
|
Map<String, dynamic> sampleMediaAssetJson({String status = 'ready'}) => {
|
|
'id': 'a-1',
|
|
'kind': 'image',
|
|
'purpose': 'post_image',
|
|
'mimeType': 'image/jpeg',
|
|
'byteSize': 204800,
|
|
'widthPx': 1080,
|
|
'heightPx': 810,
|
|
'status': status,
|
|
'url': status == 'ready'
|
|
? 'https://minio.local/p.jpg?X-Amz-Signature=sig'
|
|
: null,
|
|
'readyAt': status == 'ready' ? '2026-09-08T10:06:00.000Z' : null,
|
|
'createdAt': '2026-09-08T10:00:00.000Z',
|
|
};
|
|
|
|
Map<String, Object?> cursorPageJson(
|
|
List<Map<String, dynamic>> items, {
|
|
String? nextCursor,
|
|
bool hasMore = false,
|
|
}) => {'items': items, 'nextCursor': nextCursor, 'hasMore': hasMore};
|
|
|
|
FeedCard sampleFeedCard({
|
|
String id = 'p-1',
|
|
bool likedByMe = false,
|
|
int likeCount = 6,
|
|
}) => FeedCard.fromJson(
|
|
sampleFeedCardJson(id: id, likedByMe: likedByMe, likeCount: likeCount),
|
|
);
|
|
|
|
CursorPage<FeedCard> feedPage(
|
|
List<FeedCard> items, {
|
|
String? nextCursor,
|
|
bool hasMore = false,
|
|
}) => CursorPage(items: items, nextCursor: nextCursor, hasMore: hasMore);
|
|
|
|
/// 假仓库:controller 测试注入行为并记录调用(Completer 控时序)。
|
|
/// 未注入 handler 的方法一律 UnimplementedError(误触发即测试失败)。
|
|
class FakeCommunityRepository implements CommunityRepository {
|
|
/// 调用日志,如 `feed:cursor=null`、`like:p-1`、`unlike:p-1`。
|
|
final List<String> calls = [];
|
|
|
|
Future<CursorPage<FeedCard>> Function(int? limit, String? cursor)? onFeed;
|
|
Future<LikeState> Function(String postId, bool target)? onLikeToggle;
|
|
Future<BookmarkState> Function(String postId, bool target)? onBookmarkToggle;
|
|
Future<Post> Function(String postId)? onGetPost;
|
|
|
|
@override
|
|
Future<CursorPage<FeedCard>> getFeed({int? limit, String? cursor}) {
|
|
calls.add('feed:cursor=$cursor');
|
|
return onFeed!(limit, cursor);
|
|
}
|
|
|
|
@override
|
|
Future<LikeState> likePost(String postId) {
|
|
calls.add('like:$postId');
|
|
return onLikeToggle!(postId, true);
|
|
}
|
|
|
|
@override
|
|
Future<LikeState> unlikePost(String postId) {
|
|
calls.add('unlike:$postId');
|
|
return onLikeToggle!(postId, false);
|
|
}
|
|
|
|
@override
|
|
Future<BookmarkState> bookmarkPost(String postId) {
|
|
calls.add('bookmark:$postId');
|
|
return onBookmarkToggle!(postId, true);
|
|
}
|
|
|
|
@override
|
|
Future<BookmarkState> unbookmarkPost(String postId) {
|
|
calls.add('unbookmark:$postId');
|
|
return onBookmarkToggle!(postId, false);
|
|
}
|
|
|
|
@override
|
|
Future<Post> getPost(String postId) {
|
|
calls.add('getPost:$postId');
|
|
return onGetPost!(postId);
|
|
}
|
|
|
|
@override
|
|
Future<MediaUploadCredentials> createMediaUpload(
|
|
CreateMediaUploadRequest request,
|
|
) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<MediaAsset> completeMediaUpload(String assetId) =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
Future<Post> createPost(CreatePostRequest request) =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
Future<Post> updatePost(String postId, UpdatePostRequest request) =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
Future<void> deletePost(String postId) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<CursorPage<Post>> listMyPosts({
|
|
int? limit,
|
|
String? cursor,
|
|
PostStatus? status,
|
|
}) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<CursorPage<PostComment>> listComments(
|
|
String postId, {
|
|
int? limit,
|
|
String? cursor,
|
|
}) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<PostComment> createComment(
|
|
String postId,
|
|
CreateCommentRequest request,
|
|
) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<void> deleteComment(String commentId) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<CursorPage<FeedCard>> listMyBookmarks({int? limit, String? cursor}) =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
Future<FollowState> followUser(String userId) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<FollowState> unfollowUser(String userId) => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<FollowStats> getFollowStats(String userId) =>
|
|
throw UnimplementedError();
|
|
}
|