forked from eatvio/eatvio_app
feat(feed): fixed comments state updating in feed, feat(consultantRegistration): fixed registration flow for users with unverified phone, feat(tests): fixed tests coverage
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Smoke coverage for [fromJson] factories not exercised elsewhere — improves line coverage on large model file.
|
||||
void main() {
|
||||
const c = '2024-06-01T12:00:00Z';
|
||||
final base = <String, dynamic>{'created_at': c};
|
||||
|
||||
final planAndUser = <String, dynamic>{'created_at': c, 'plan_name': 'p', 'user_name': 'u', 'renewal_date': '2024-06-02'};
|
||||
|
||||
final scoreLike = <String, dynamic>{
|
||||
'created_at': c,
|
||||
'score_key': 'k',
|
||||
'scorable_id': 1,
|
||||
'scorable_type': 'Type',
|
||||
'score_value': 2,
|
||||
};
|
||||
|
||||
final commentReply = <String, dynamic>{
|
||||
'created_at': c,
|
||||
'entity_name': 'e',
|
||||
'commented_entity_id': 1,
|
||||
'commented_entity_type': 'diet',
|
||||
'author': 'a',
|
||||
'author_id': 2,
|
||||
'parrent_comment_id': 3,
|
||||
};
|
||||
|
||||
final entityCommented = <String, dynamic>{
|
||||
'created_at': c,
|
||||
'entity_name': 'e',
|
||||
'entity_id': 1,
|
||||
'entity_type': 'diet',
|
||||
'entity_traslated_type': 't',
|
||||
'entity_url': 'u',
|
||||
'author_name': 'a',
|
||||
'author_id': 2,
|
||||
'author_slug': 's',
|
||||
};
|
||||
|
||||
group('CommentedEntityType.fromJson', () {
|
||||
test('maps known and legacy keys', () {
|
||||
expect(CommentedEntityType.fromJson('diet'), CommentedEntityType.diet);
|
||||
expect(CommentedEntityType.fromJson('Modules\\UserGeneratedPublicContent\\Models\\Diet'), CommentedEntityType.diet);
|
||||
expect(CommentedEntityType.fromJson('blog-post'), CommentedEntityType.blogPost);
|
||||
expect(CommentedEntityType.fromJson('Modules\\UserGeneratedPublicContent\\Models\\BlogPost'), CommentedEntityType.blogPost);
|
||||
expect(CommentedEntityType.fromJson('other'), CommentedEntityType.unknown);
|
||||
});
|
||||
});
|
||||
|
||||
group('notification fromJson bulk smoke', () {
|
||||
test('executes remaining model factories with minimal JSON', () {
|
||||
PlanSubscriptionExpiredNotification.fromJson(planAndUser, NotificationType.planSubscriptionExpired);
|
||||
PlanSubscriptionRenewedNotification.fromJson(planAndUser, NotificationType.planSubscriptionRenewed);
|
||||
ChosenPlanStartedToConsultantNotification.fromJson(base, NotificationType.chosenPlanStartedToConsultant);
|
||||
ChosenPlanTomorrowReminderToConsultantNotification.fromJson(base, NotificationType.chosenPlanTomorrowReminderToConsultant);
|
||||
PlanSubscriptionPaidToAuthorNotification.fromJson(base, NotificationType.planSubscriptionPaidToAuthor);
|
||||
ChosenPlanFinishedToConsultantNotification.fromJson(base, NotificationType.chosenPlanFinishedToConsultant);
|
||||
ChosenPlanLastDayFinishedForUser.fromJson(base, NotificationType.chosenPlanLastDayFinishedForUser);
|
||||
ChosenPlanConsultantLastDayStarted.fromJson(base, NotificationType.chosenPlanConsultantLastDayStarted);
|
||||
ComplaintToModerationForUser.fromJson(base, NotificationType.complaintToModerationForUser);
|
||||
CommentReplied.fromJson(commentReply, NotificationType.commentReplied);
|
||||
ScoreAdded.fromJson(scoreLike, NotificationType.scoreAdded);
|
||||
ScoreSubstractedNotification.fromJson(scoreLike, NotificationType.scoreSubstracted);
|
||||
EntityCommented.fromJson(entityCommented, NotificationType.entityCommented);
|
||||
UnknownNotification.fromJson(base, NotificationType.unknown);
|
||||
|
||||
ConsultantConfirmPlanSubscriptionToSubscriberNotification.fromJson(
|
||||
base,
|
||||
NotificationType.consultantConfirmPlanSubscriptionToSubscriber,
|
||||
);
|
||||
ClientPaidPlanSubscriptionToAuthorNotification.fromJson(base, NotificationType.clientPaidPlanSubscriptionToAuthor);
|
||||
ConsultantLeftDiaryCommentNotification.fromJson(base, NotificationType.consultantLeftDiaryComment);
|
||||
ConsultantConfirmPlanSubscriptionToAuthorNotification.fromJson(base, NotificationType.consultantConfirmPlanSubscriptionToAuthor);
|
||||
ClientPaidPlanSubscriptionToSubscriberNotification.fromJson(base, NotificationType.clientPaidPlanSubscriptionToSubscriber);
|
||||
ClientStartPlanSubscriptionToAuthorNotification.fromJson(base, NotificationType.clientStartPlanSubscriptionToAuthor);
|
||||
ClientCancelPlanSubscriptionToAuthorNotification.fromJson(base, NotificationType.clientCancelPlanSubscriptionToAuthor);
|
||||
ClientCancelPlanSubscriptionToSubscriberNotification.fromJson(base, NotificationType.clientCancelPlanSubscriptionToSubscriber);
|
||||
UserDailyReportCompletedNotification.fromJson(base, NotificationType.userDailyReportCompleted);
|
||||
StayOnTrackToCustomerNotification.fromJson(base, NotificationType.stayOnTrackToCustomer);
|
||||
PhoneChangedNotification.fromJson(base, NotificationType.phoneChanged);
|
||||
SubscriptionNotification.fromJson(base, NotificationType.subscription);
|
||||
BadgeAwardedNotification.fromJson(base, NotificationType.badgeAwarded);
|
||||
BadgeRevokedNotification.fromJson(base, NotificationType.badgeRevoked);
|
||||
ConsultantRequestStartedNotification.fromJson(base, NotificationType.consultantRequestStarted);
|
||||
ClientCloseComplaintSuccessNotification.fromJson(base, NotificationType.clientCloseComplaintSuccess);
|
||||
ClientRefundSuccessNotification.fromJson(base, NotificationType.clientRefundSuccess);
|
||||
ConsultantRefundSuccessNotification.fromJson(base, NotificationType.consultantRefundSuccess);
|
||||
ClientRejectSuccessNotification.fromJson(base, NotificationType.clientRejectSuccess);
|
||||
ConsultantRejectSuccessNotification.fromJson(base, NotificationType.consultantRejectSuccess);
|
||||
ProductStatusUpdatedForAuthorNotification.fromJson(base, NotificationType.productStatusUpdatedForAuthor);
|
||||
DiaryReminderForUsersNotification.fromJson(base, NotificationType.diaryReminderForUsers);
|
||||
DiaryReminderForUsersNotification.fromJson({'created_at': c, 'data': <String, dynamic>{}}, NotificationType.diaryReminderForUsers);
|
||||
PersonalDietIsDefinedToCustomerNotification.fromJson(base, NotificationType.personalDietIsDefinedToCustomer);
|
||||
ConsultantEducationUpdatedNotification.fromJson(base, NotificationType.consultantEducationUpdated);
|
||||
ComplaintRegisteredNotification.fromJson(base, NotificationType.complaintRegistered);
|
||||
ContentUnpublishedNotification.fromJson(base, NotificationType.contentUnpublished);
|
||||
FinanceQuestionCreatedNotification.fromJson(base, NotificationType.financeQuestionCreated);
|
||||
NewChatMessageNotification.fromJson(base, NotificationType.newChatMessage);
|
||||
CompleteRegistrationNotification.fromJson(base, NotificationType.completeRegistration);
|
||||
ChosenDietExpiredNotification.fromJson(base, NotificationType.chosenDietExpired);
|
||||
MotivateUserNotification.fromJson(base, NotificationType.motivateUser);
|
||||
CommentComplaintNotification.fromJson(base, NotificationType.commentComplaint);
|
||||
CommentDeletedNotification.fromJson(base, NotificationType.commentDeleted);
|
||||
UserSubscribedNotification.fromJson(base, NotificationType.userSubscribed);
|
||||
});
|
||||
|
||||
test('executes additional factories used by legacy and plan flows', () {
|
||||
ClientStartPlanSubscriptionToSubscriberNotification.fromJson(base, NotificationType.clientStartPlanSubscriptionToSubscriber);
|
||||
ChosenPlanFinishedToClientNotification.fromJson(base, NotificationType.chosenPlanFinishedToClient);
|
||||
PlanSubscriptionCanceledToCustomerNotification.fromJson(base, NotificationType.planSubscriptionCanceledToCustomer);
|
||||
PlanSubscriptionCanceledToAuthorNotification.fromJson(planAndUser, NotificationType.planSubscriptionCanceledToAuthor);
|
||||
ChosenPlanStartedToClientNotification.fromJson(planAndUser, NotificationType.chosenPlanStartedToClient);
|
||||
ChosenPlanTomorrowReminderToClientNotification.fromJson(planAndUser, NotificationType.chosenPlanTomorrowReminderToClient);
|
||||
DiaryReminderNotification.fromJson(base, NotificationType.diaryReminderNotification);
|
||||
ConsultantLeftCommentNotification.fromJson(base, NotificationType.consultantLeftComment);
|
||||
PersonalizedDietIsDefinedNotification.fromJson(base, NotificationType.personalizedDietIsDefined);
|
||||
PlanSubscriptionStartedToAuthorNotification.fromJson(planAndUser, NotificationType.planSubscriptionStartedToAuthor);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user