work on test models part 1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
|
||||
|
||||
void main() {
|
||||
group('ForgotPasswordResponseModel Tests', () {
|
||||
final mockJson = {
|
||||
'success': true,
|
||||
'message': 'Password reset link sent successfully',
|
||||
'data': {
|
||||
'message': 'Reset link has been emailed to you',
|
||||
'success': true,
|
||||
},
|
||||
'error': {'message': null, 'code': null, 'details': null},
|
||||
'meta': {'timestamp': 1759746927},
|
||||
};
|
||||
|
||||
test('fromJson creates valid instance', () {
|
||||
final response = ForgotPasswordResponseModel.fromJson(mockJson);
|
||||
|
||||
expect(response.success, isTrue);
|
||||
expect(response.message, 'Password reset link sent successfully');
|
||||
|
||||
final data = response.data!;
|
||||
expect(data.message, 'Reset link has been emailed to you');
|
||||
expect(data.success, isTrue);
|
||||
|
||||
expect(response.error?.message, isNull);
|
||||
expect(response.meta?['timestamp'], 1759746927);
|
||||
});
|
||||
|
||||
test('toJson converts model back to JSON correctly', () {
|
||||
final response = ForgotPasswordResponseModel.fromJson(mockJson);
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['success'], true);
|
||||
expect(json['message'], 'Password reset link sent successfully');
|
||||
|
||||
final data = response.data?.toJson() ?? {};
|
||||
expect(data['message'], 'Reset link has been emailed to you');
|
||||
expect(data['success'], true);
|
||||
|
||||
final meta = json['meta'] as Map<String, dynamic>?;
|
||||
expect(meta?['timestamp'], 1759746927);
|
||||
});
|
||||
|
||||
test('copyWith updates fields correctly', () {
|
||||
final response = ForgotPasswordResponseModel.fromJson(mockJson);
|
||||
|
||||
final updated = response.copyWith(
|
||||
message: 'Updated message',
|
||||
success: false,
|
||||
data: response.data?.copyWith(success: false),
|
||||
);
|
||||
|
||||
expect(updated.message, 'Updated message');
|
||||
expect(updated.success, isFalse);
|
||||
expect(updated.data?.success, isFalse);
|
||||
});
|
||||
|
||||
test('equality works as expected', () {
|
||||
final res1 = ForgotPasswordResponseModel.fromJson(mockJson);
|
||||
final res2 = ForgotPasswordResponseModel.fromJson(mockJson);
|
||||
|
||||
expect(res1, equals(res2));
|
||||
expect(res1.hashCode, equals(res2.hashCode));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user