forked from eatvio/eatvio_app
feat(tests): tests coverage 67.2
This commit is contained in:
@@ -131,5 +131,574 @@ void main() {
|
||||
// createdAt is initialized with epoch when not provided
|
||||
expect(notification.createdAt.isBefore(DateTime.now()), isTrue);
|
||||
});
|
||||
|
||||
test('ConsultantAssignedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'consultant_name': 'John Doe',
|
||||
'plan_name': 'Test Plan',
|
||||
'plan_id': 123,
|
||||
'created_at': '2024-01-01T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ConsultantAssignedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.consultantAssigned,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.consultantName, 'John Doe');
|
||||
expect(notification.planName, 'Test Plan');
|
||||
expect(notification.planId, 123);
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.consultantAssigned);
|
||||
});
|
||||
|
||||
test('ConsultantUnassignedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'consultant_name': 'Jane Smith',
|
||||
'plan_name': 'Another Plan',
|
||||
'plan_id': 456,
|
||||
'created_at': '2024-01-02T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ConsultantUnassignedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.consultantUnassigned,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.consultantName, 'Jane Smith');
|
||||
expect(notification.planName, 'Another Plan');
|
||||
expect(notification.planId, 456);
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.consultantUnassigned);
|
||||
});
|
||||
|
||||
test('PaymentFailedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Premium Plan',
|
||||
'error_message': 'Insufficient funds',
|
||||
'payment_method': 'credit_card',
|
||||
'created_at': '2024-01-03T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PaymentFailedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.paymentFailed,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Premium Plan');
|
||||
expect(notification.errorMessage, 'Insufficient funds');
|
||||
expect(notification.paymentMethod, 'credit_card');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.paymentFailed);
|
||||
});
|
||||
|
||||
test('PaymentSuccessfulNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Premium Plan',
|
||||
'amount': 99.99,
|
||||
'currency': 'USD',
|
||||
'transaction_id': 'txn_123456',
|
||||
'created_at': '2024-01-04T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PaymentSuccessfulNotification.fromJson(
|
||||
json,
|
||||
NotificationType.paymentSuccessful,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Premium Plan');
|
||||
expect(notification.amount, 99.99);
|
||||
expect(notification.currency, 'USD');
|
||||
expect(notification.transactionId, 'txn_123456');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.paymentSuccessful);
|
||||
});
|
||||
|
||||
test('PaymentSuccessfulNotification.fromJson handles int amount', () {
|
||||
final json = {
|
||||
'plan_name': 'Basic Plan',
|
||||
'amount': 50,
|
||||
'currency': 'EUR',
|
||||
'transaction_id': 'txn_789',
|
||||
'created_at': '2024-01-05T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PaymentSuccessfulNotification.fromJson(
|
||||
json,
|
||||
NotificationType.paymentSuccessful,
|
||||
);
|
||||
|
||||
expect(notification.amount, 50.0);
|
||||
});
|
||||
|
||||
test('GoalAchievedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'goal_name': 'Weight Loss',
|
||||
'goal_type': 'weight',
|
||||
'achieved_value': 70.5,
|
||||
'target_value': 75.0,
|
||||
'created_at': '2024-01-06T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = GoalAchievedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.goalAchieved,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.goalName, 'Weight Loss');
|
||||
expect(notification.goalType, 'weight');
|
||||
expect(notification.achievedValue, 70.5);
|
||||
expect(notification.targetValue, 75.0);
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.goalAchieved);
|
||||
});
|
||||
|
||||
test('GoalAchievedNotification.fromJson handles int values', () {
|
||||
final json = {
|
||||
'goal_name': 'Steps',
|
||||
'goal_type': 'steps',
|
||||
'achieved_value': 10000,
|
||||
'target_value': 8000,
|
||||
'created_at': '2024-01-07T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = GoalAchievedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.goalAchieved,
|
||||
);
|
||||
|
||||
expect(notification.achievedValue, 10000.0);
|
||||
expect(notification.targetValue, 8000.0);
|
||||
});
|
||||
|
||||
test('WorkoutReminderNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'workout_name': 'Morning Run',
|
||||
'workout_type': 'running',
|
||||
'duration': 30,
|
||||
'created_at': '2024-01-08T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = WorkoutReminderNotification.fromJson(
|
||||
json,
|
||||
NotificationType.workoutReminder,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.workoutName, 'Morning Run');
|
||||
expect(notification.workoutType, 'running');
|
||||
expect(notification.duration, 30);
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.workoutReminder);
|
||||
});
|
||||
|
||||
test('MealReminderNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'meal_name': 'Breakfast',
|
||||
'meal_type': 'breakfast',
|
||||
'calories': 500,
|
||||
'created_at': '2024-01-09T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = MealReminderNotification.fromJson(
|
||||
json,
|
||||
NotificationType.mealReminder,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.mealName, 'Breakfast');
|
||||
expect(notification.mealType, 'breakfast');
|
||||
expect(notification.calories, 500);
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.mealReminder);
|
||||
});
|
||||
|
||||
test('DietCancelledNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diet_name': 'Keto Diet',
|
||||
'created_at': '2024-01-10T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietCancelledNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietCancelled,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.dietName, 'Keto Diet');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.dietCancelled);
|
||||
});
|
||||
|
||||
test('DietCancelledNotification.fromJson handles missing diet_name', () {
|
||||
final json = {
|
||||
'created_at': '2024-01-11T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietCancelledNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietCancelled,
|
||||
);
|
||||
|
||||
expect(notification.dietName, '');
|
||||
});
|
||||
|
||||
test('DietStartedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diet_name': 'Mediterranean Diet',
|
||||
'created_at': '2024-01-12T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietStartedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietStarted,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.dietName, 'Mediterranean Diet');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.dietStarted);
|
||||
});
|
||||
|
||||
test('DietStartedNotification.fromJson handles missing diet_name', () {
|
||||
final json = {
|
||||
'created_at': '2024-01-13T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietStartedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietStarted,
|
||||
);
|
||||
|
||||
expect(notification.dietName, '');
|
||||
});
|
||||
|
||||
test('DietExpiredNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diet_name': 'Vegan Diet',
|
||||
'created_at': '2024-01-14T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietExpiredNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietExpired,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.dietName, 'Vegan Diet');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.dietExpired);
|
||||
});
|
||||
|
||||
test('DietExpiredNotification.fromJson handles missing diet_name', () {
|
||||
final json = {
|
||||
'created_at': '2024-01-15T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietExpiredNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietExpired,
|
||||
);
|
||||
|
||||
expect(notification.dietName, '');
|
||||
});
|
||||
|
||||
test('Notification models use custom createdAt when provided', () {
|
||||
final customDate = DateTime(2024, 6, 15, 10, 30);
|
||||
final json = {'plan_name': 'Test Plan', 'plan_id': 1};
|
||||
|
||||
final notification = ChosenPlanStartedToClientNotification.fromJson(
|
||||
json,
|
||||
NotificationType.chosenPlanStartedToClient,
|
||||
createdAt: customDate.toIso8601String(),
|
||||
);
|
||||
|
||||
expect(notification.createdAt, customDate);
|
||||
});
|
||||
|
||||
test('DietWillStartedInNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diet_name': 'Summer Diet',
|
||||
'start_date': '2024-06-01',
|
||||
'created_at': '2024-01-16T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietWillStartedInNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietWillStartedIn,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.dietName, 'Summer Diet');
|
||||
expect(notification.startDate, '2024-06-01');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.dietWillStartedIn);
|
||||
});
|
||||
|
||||
test('DietWillStartedInNotification.fromJson handles missing fields', () {
|
||||
final json = {'created_at': '2024-01-17T12:00:00Z'};
|
||||
|
||||
final notification = DietWillStartedInNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietWillStartedIn,
|
||||
);
|
||||
|
||||
expect(notification.dietName, '');
|
||||
expect(notification.startDate, '');
|
||||
});
|
||||
|
||||
test('DietCanNotBeStartedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diet_name': 'Winter Diet',
|
||||
'reason': 'Not enough products',
|
||||
'created_at': '2024-01-18T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DietCanNotBeStartedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietCanNotBeStarted,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.dietName, 'Winter Diet');
|
||||
expect(notification.reason, 'Not enough products');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.dietCanNotBeStarted);
|
||||
});
|
||||
|
||||
test('DietCanNotBeStartedNotification.fromJson handles missing fields', () {
|
||||
final json = {'created_at': '2024-01-19T12:00:00Z'};
|
||||
|
||||
final notification = DietCanNotBeStartedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.dietCanNotBeStarted,
|
||||
);
|
||||
|
||||
expect(notification.dietName, '');
|
||||
expect(notification.reason, '');
|
||||
});
|
||||
|
||||
test('PersonalDietCreationNeededNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Custom Plan',
|
||||
'client_name': 'John Doe',
|
||||
'created_at': '2024-01-20T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PersonalDietCreationNeededNotification.fromJson(
|
||||
json,
|
||||
NotificationType.personalDietCreationNeeded,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Custom Plan');
|
||||
expect(notification.clientName, 'John Doe');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.personalDietCreationNeeded);
|
||||
});
|
||||
|
||||
test('PersonalDietCreationNeededNotification.fromJson handles missing fields', () {
|
||||
final json = {'created_at': '2024-01-21T12:00:00Z'};
|
||||
|
||||
final notification = PersonalDietCreationNeededNotification.fromJson(
|
||||
json,
|
||||
NotificationType.personalDietCreationNeeded,
|
||||
);
|
||||
|
||||
expect(notification.planName, '');
|
||||
expect(notification.clientName, '');
|
||||
});
|
||||
|
||||
test('ChosenPlanClientLastDayFinishedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Final Plan',
|
||||
'created_at': '2024-01-22T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ChosenPlanClientLastDayFinishedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.chosenPlanClientLastDayFinished,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Final Plan');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.chosenPlanClientLastDayFinished);
|
||||
});
|
||||
|
||||
test('ChosenPlanClientLastDayStartedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Starting Plan',
|
||||
'created_at': '2024-01-23T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ChosenPlanClientLastDayStartedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.chosenPlanClientLastDayStarted,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Starting Plan');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.chosenPlanClientLastDayStarted);
|
||||
});
|
||||
|
||||
test('StayOnTrackToAuthorNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Track Plan',
|
||||
'client_name': 'Jane Smith',
|
||||
'created_at': '2024-01-24T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = StayOnTrackToAuthorNotification.fromJson(
|
||||
json,
|
||||
NotificationType.stayOnTrackToAuthor,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Track Plan');
|
||||
expect(notification.clientName, 'Jane Smith');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.stayOnTrackToAuthor);
|
||||
});
|
||||
|
||||
test('ClientStartPlanSubscriptionToSubscriberNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Subscriber Plan',
|
||||
'created_at': '2024-01-25T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ClientStartPlanSubscriptionToSubscriberNotification.fromJson(
|
||||
json,
|
||||
NotificationType.clientStartPlanSubscriptionToSubscriber,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Subscriber Plan');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.clientStartPlanSubscriptionToSubscriber);
|
||||
});
|
||||
|
||||
test('PlanSubscriptionCanceledToAuthorNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Canceled Plan',
|
||||
'user_name': 'User Name',
|
||||
'created_at': '2024-01-26T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PlanSubscriptionCanceledToAuthorNotification.fromJson(
|
||||
json,
|
||||
NotificationType.planSubscriptionCanceledToAuthor,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Canceled Plan');
|
||||
expect(notification.customerName, 'User Name');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.planSubscriptionCanceledToAuthor);
|
||||
});
|
||||
|
||||
test('ChosenPlanTomorrowReminderToClientNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Reminder Plan',
|
||||
'created_at': '2024-01-27T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ChosenPlanTomorrowReminderToClientNotification.fromJson(
|
||||
json,
|
||||
NotificationType.chosenPlanTomorrowReminderToClientNotification,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Reminder Plan');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.chosenPlanTomorrowReminderToClientNotification);
|
||||
});
|
||||
|
||||
test('DiaryReminderNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'created_at': '2024-01-28T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = DiaryReminderNotification.fromJson(
|
||||
json,
|
||||
NotificationType.diaryReminderNotification,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.diaryReminderNotification);
|
||||
});
|
||||
|
||||
test('ConsultantLeftCommentNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'diary_date': '2024-01-29T12:00:00Z',
|
||||
'created_at': '2024-01-29T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ConsultantLeftCommentNotification.fromJson(
|
||||
json,
|
||||
NotificationType.consultantLeftComment,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.date, isA<DateTime>());
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.consultantLeftComment);
|
||||
});
|
||||
|
||||
test('PersonalizedDietIsDefinedNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'created_at': '2024-01-30T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PersonalizedDietIsDefinedNotification.fromJson(
|
||||
json,
|
||||
NotificationType.personalizedDietIsDefined,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.personalizedDietIsDefined);
|
||||
});
|
||||
|
||||
test('ChosenPlanFinishedToClientNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Finished Plan',
|
||||
'created_at': '2024-01-31T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = ChosenPlanFinishedToClientNotification.fromJson(
|
||||
json,
|
||||
NotificationType.chosenPlanFinishedToClient,
|
||||
isRead: true,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Finished Plan');
|
||||
expect(notification.isRead, true);
|
||||
expect(notification.type, NotificationType.chosenPlanFinishedToClient);
|
||||
});
|
||||
|
||||
test('PlanSubscriptionCanceledToCustomerNotification.fromJson parses all fields', () {
|
||||
final json = {
|
||||
'plan_name': 'Customer Canceled Plan',
|
||||
'created_at': '2024-02-01T12:00:00Z',
|
||||
};
|
||||
|
||||
final notification = PlanSubscriptionCanceledToCustomerNotification.fromJson(
|
||||
json,
|
||||
NotificationType.planSubscriptionCanceledToCustomer,
|
||||
isRead: false,
|
||||
);
|
||||
|
||||
expect(notification.planName, 'Customer Canceled Plan');
|
||||
expect(notification.isRead, false);
|
||||
expect(notification.type, NotificationType.planSubscriptionCanceledToCustomer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user