75 lines
2.4 KiB
Dart
75 lines
2.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/data/services/model/feedback_stats_response/feedback_stat_response.dart';
|
|
|
|
void main() {
|
|
group('FeedbackStatResponse Model Tests', () {
|
|
final mockJson = {
|
|
'success': true,
|
|
'message': 'Company stats retrieved successfully',
|
|
'error': {'message': null, 'code': null, 'details': null},
|
|
'data': {
|
|
'company_id': '68c7fea825ff3fc682529856',
|
|
'total_likes': 1,
|
|
'total_dislikes': 0,
|
|
'total_feedback': 1,
|
|
'last_updated': 1759746927,
|
|
},
|
|
};
|
|
|
|
test('fromJson creates valid FeedbackStatResponse instance', () {
|
|
final response = FeedbackStatResponse.fromJson(mockJson);
|
|
|
|
expect(response.success, isTrue);
|
|
expect(response.message, 'Company stats retrieved successfully');
|
|
|
|
final data = response.data!;
|
|
expect(data.companyId, '68c7fea825ff3fc682529856');
|
|
expect(data.totalLikes, 1);
|
|
expect(data.totalDislikes, 0);
|
|
expect(data.totalFeedback, 1);
|
|
expect(data.lastUpdated, 1759746927);
|
|
|
|
expect(response.error?.message, isNull);
|
|
});
|
|
|
|
test('toJson converts model back to JSON correctly', () {
|
|
final response = FeedbackStatResponse.fromJson(mockJson);
|
|
final json = response.toJson();
|
|
|
|
expect(json['success'], true);
|
|
expect(json['message'], 'Company stats retrieved successfully');
|
|
|
|
final data = response.data?.toJson() ?? {};
|
|
|
|
expect(data['company_id'], '68c7fea825ff3fc682529856');
|
|
expect(data['total_likes'], 1);
|
|
expect(data['total_dislikes'], 0);
|
|
expect(data['total_feedback'], 1);
|
|
expect(data['last_updated'], 1759746927);
|
|
});
|
|
|
|
test('copyWith correctly updates fields', () {
|
|
final response = FeedbackStatResponse.fromJson(mockJson);
|
|
|
|
final updated = response.copyWith(
|
|
message: 'Updated Message',
|
|
success: false,
|
|
data: response.data?.copyWith(totalLikes: 10),
|
|
);
|
|
|
|
expect(updated.message, 'Updated Message');
|
|
expect(updated.success, isFalse);
|
|
expect(updated.data?.totalLikes, 10);
|
|
expect(updated.data?.companyId, '68c7fea825ff3fc682529856');
|
|
});
|
|
|
|
test('equality operator works as expected', () {
|
|
final r1 = FeedbackStatResponse.fromJson(mockJson);
|
|
final r2 = FeedbackStatResponse.fromJson(mockJson);
|
|
|
|
expect(r1, equals(r2));
|
|
expect(r1.hashCode, equals(r2.hashCode));
|
|
});
|
|
});
|
|
}
|