File tree Expand file tree Collapse file tree 5 files changed +63
-14
lines changed
lib/src/models/user_generated_content
test/src/models/user_generated_content Expand file tree Collapse file tree 5 files changed +63
-14
lines changed Original file line number Diff line number Diff line change @@ -106,20 +106,25 @@ class AppReview extends Equatable {
106106
107107 /// Creates a copy of this [AppReview] with updated values.
108108 AppReview copyWith ({
109+ String ? id,
110+ String ? userId,
109111 AppReviewFeedback ? feedback,
112+ DateTime ? createdAt,
110113 DateTime ? updatedAt,
111114 bool ? wasStoreReviewRequested,
112- String ? feedbackDetails,
115+ ValueWrapper < String ?> ? feedbackDetails,
113116 }) {
114117 return AppReview (
115- id: id,
116- userId: userId,
118+ id: id ?? this .id ,
119+ userId: userId ?? this .userId ,
117120 feedback: feedback ?? this .feedback,
118- createdAt: createdAt,
121+ createdAt: createdAt ?? this .createdAt ,
119122 updatedAt: updatedAt ?? this .updatedAt,
120123 wasStoreReviewRequested:
121124 wasStoreReviewRequested ?? this .wasStoreReviewRequested,
122- feedbackDetails: feedbackDetails ?? this .feedbackDetails,
125+ feedbackDetails: feedbackDetails != null
126+ ? feedbackDetails.value
127+ : this .feedbackDetails,
123128 );
124129 }
125130}
Original file line number Diff line number Diff line change 1+ import 'package:core/core.dart' ;
12import 'package:core/src/enums/engageable_type.dart' ;
23import 'package:core/src/models/user_generated_content/comment.dart' ;
34import 'package:core/src/models/user_generated_content/reaction.dart' ;
@@ -74,15 +75,23 @@ class Engagement extends Equatable {
7475 ];
7576
7677 /// Creates a copy of this [Engagement] with updated values.
77- Engagement copyWith ({Reaction ? reaction, Comment ? comment}) {
78+ Engagement copyWith ({
79+ String ? id,
80+ String ? userId,
81+ String ? entityId,
82+ EngageableType ? entityType,
83+ Reaction ? reaction,
84+ ValueWrapper <Comment ?>? comment,
85+ DateTime ? createdAt,
86+ }) {
7887 return Engagement (
79- id: id,
80- userId: userId,
81- entityId: entityId,
82- entityType: entityType,
88+ id: id ?? this .id ,
89+ userId: userId ?? this .userId ,
90+ entityId: entityId ?? this .entityId ,
91+ entityType: entityType ?? this .entityType ,
8392 reaction: reaction ?? this .reaction,
84- comment: comment ?? this .comment,
85- createdAt: createdAt,
93+ comment: comment != null ? comment.value : this .comment,
94+ createdAt: createdAt ?? this .createdAt ,
8695 updatedAt: DateTime .now (),
8796 );
8897 }
Original file line number Diff line number Diff line change @@ -105,12 +105,12 @@ class Report extends Equatable {
105105 reporterUserId: reporterUserId ?? this .reporterUserId,
106106 entityType: entityType ?? this .entityType,
107107 entityId: entityId ?? this .entityId,
108- reason: reason ?? this .reason,
109108 status: status ?? this .status,
110109 additionalComments: additionalComments != null
111110 ? additionalComments.value
112111 : this .additionalComments,
113112 createdAt: createdAt ?? this .createdAt,
113+ reason: reason ?? this .reason,
114114 );
115115 }
116116}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ void main() {
6363
6464 final updatedReview = negativeReviewWithReason.copyWith (
6565 updatedAt: newTimestamp,
66- feedbackDetails: newDetails,
66+ feedbackDetails: const ValueWrapper ( newDetails) ,
6767 );
6868
6969 expect (updatedReview.updatedAt, newTimestamp);
@@ -74,6 +74,15 @@ void main() {
7474 expect (updatedReview.createdAt, negativeReviewWithReason.createdAt);
7575 });
7676
77+ test ('allows setting feedbackDetails to null' , () {
78+ final updatedReview = negativeReviewWithReason.copyWith (
79+ feedbackDetails: const ValueWrapper (null ),
80+ );
81+
82+ expect (updatedReview.feedbackDetails, isNull);
83+ expect (updatedReview.id, negativeReviewWithReason.id);
84+ });
85+
7786 test ('correctly uses initialFeedback in copyWith' , () {
7887 final updatedReview = positiveReview.copyWith (
7988 feedback: AppReviewFeedback .negative,
Original file line number Diff line number Diff line change @@ -68,6 +68,32 @@ void main() {
6868 );
6969 });
7070
71+ test ('returns a new instance with an updated comment' , () {
72+ final newComment = Comment (
73+ language: languagesFixturesData.first,
74+ content: 'This is a new comment.' ,
75+ status: ModerationStatus .resolved,
76+ );
77+
78+ final updatedEngagement = engagementFixture.copyWith (
79+ comment: ValueWrapper (newComment),
80+ );
81+
82+ expect (updatedEngagement.comment, newComment);
83+ expect (updatedEngagement.id, engagementFixture.id);
84+ });
85+
86+ test ('returns a new instance with a null comment' , () {
87+ // Start with a fixture that has a comment.
88+ final updatedEngagement = engagementFixture.copyWith (
89+ comment: const ValueWrapper (null ),
90+ );
91+
92+ expect (updatedEngagement.comment, isNull);
93+ // Verify other fields remain unchanged
94+ expect (updatedEngagement.id, engagementFixture.id);
95+ });
96+
7197 test (
7298 'returns a new instance with a new timestamp if no updates provided' ,
7399 () {
You can’t perform that action at this time.
0 commit comments