test(tests): add comprehensive unit tests for various models and repositories, enhancing test coverage and ensuring correct functionality

This commit is contained in:
mso7nueh
2025-12-09 16:19:48 +03:00
parent edd064d20d
commit 70e4a42e98
25 changed files with 2565 additions and 58 deletions

View File

@@ -49,6 +49,102 @@ void main() {
expect(chosenPlan.chosenPlanState, ChosenPlanStateEnum.stateInited);
expect(chosenPlan.plan.id, 1);
});
test('fromJson создает ChosenPlanModel из JSON', () {
final json = {
'id': 1,
'option_type': 'options1',
'start_date': '2024-01-01T00:00:00Z',
'last_state': 'initied',
'chat_id': 'chat-1',
'consultant_id': 1,
'plan': {
'id': 1,
'slug': 'test-plan',
'name': 'Test Plan',
'image': 'https://example.com/image.jpg',
'duration': 7,
'state': 'active',
'type': {'fit': true, 'slim': false, 'behavior': false, 'wellness': false},
'description_md': 'Test details',
'packets_count': 3,
'author': {
'author_slug': 'author',
'author_name': 'Author Name',
'author_profile_icon': 'https://example.com/icon.jpg',
'author_is_me': false,
'is_entity_subscribed_by_me': null,
'author_place_in_rating': null,
},
'total_likes': 10,
'total_views': 100,
'total_comments': 5,
'is_favorite': false,
'min_price_of_options': 1000.0,
'max_price_of_options': 2000.0,
'was_liked_by_me': false,
},
};
final chosenPlan = ChosenPlanModel.fromJson(json);
expect(chosenPlan.id, 1);
expect(chosenPlan.optionType, 'options1');
expect(chosenPlan.chosenPlanState, ChosenPlanStateEnum.stateInited);
expect(chosenPlan.chatId, 'chat-1');
});
});
group('parseChosenPlan', () {
test('parseChosenPlan создает ChosenPlanModel из Map', () {
final json = {
'id': 1,
'option_type': 'options1',
'start_date': '2024-01-01T00:00:00Z',
'last_state': 'initied',
'chat_id': 'chat-1',
'consultant_id': 1,
'plan': {
'id': 1,
'slug': 'test-plan',
'name': 'Test Plan',
'image': 'https://example.com/image.jpg',
'duration': 7,
'state': 'active',
'type': {'fit': true, 'slim': false, 'behavior': false, 'wellness': false},
'description_md': 'Test details',
'packets_count': 3,
'author': {
'author_slug': 'author',
'author_name': 'Author Name',
'author_profile_icon': 'https://example.com/icon.jpg',
'author_is_me': false,
'is_entity_subscribed_by_me': null,
'author_place_in_rating': null,
},
'total_likes': 10,
'total_views': 100,
'total_comments': 5,
'is_favorite': false,
'min_price_of_options': 1000.0,
'max_price_of_options': 2000.0,
'was_liked_by_me': false,
},
};
final result = parseChosenPlan(json);
expect(result, isNotNull);
expect(result!.id, 1);
expect(result.optionType, 'options1');
});
test('parseChosenPlan возвращает null для не-Map значения', () {
expect(parseChosenPlan(null), isNull);
expect(parseChosenPlan('string'), isNull);
expect(parseChosenPlan(123), isNull);
expect(parseChosenPlan([]), isNull);
});
});
}