work on test models part 1
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tm_app/data/services/model/company_profile_data/company_profile_data.dart';
|
||||
import 'package:tm_app/data/services/model/company_profile_response/company_profile_response.dart';
|
||||
import 'package:tm_app/data/services/model/error/error_model.dart';
|
||||
|
||||
void main() {
|
||||
group('CompanyProfileResponse Model Tests', () {
|
||||
test('fromJson should parse nested JSON correctly', () {
|
||||
final json = {
|
||||
'message': 'Success',
|
||||
'success': true,
|
||||
'error': {'code': '0', 'message': 'No error', 'details': 'details'},
|
||||
'data': {
|
||||
'id': '10',
|
||||
'name': 'AI Labs',
|
||||
'registration_number': 'A123',
|
||||
'industry': 'AI',
|
||||
'founded_year': 2020,
|
||||
'created_at': 1700000000,
|
||||
},
|
||||
};
|
||||
|
||||
final response = CompanyProfileResponse.fromJson(json);
|
||||
|
||||
expect(response.message, 'Success');
|
||||
expect(response.success, true);
|
||||
expect(response.data?.name, 'AI Labs');
|
||||
expect(response.data?.foundedYear, 2020);
|
||||
});
|
||||
|
||||
test('toJson should return valid JSON map', () {
|
||||
final data = const CompanyProfileData(
|
||||
id: '3',
|
||||
name: 'NeuralNet',
|
||||
registrationNumber: 'B456',
|
||||
industry: 'ML',
|
||||
foundedYear: 2019,
|
||||
createdAt: 1750000000,
|
||||
);
|
||||
|
||||
final response = CompanyProfileResponse(
|
||||
message: 'Success',
|
||||
success: true,
|
||||
error: const ErrorModel(
|
||||
code: '0',
|
||||
message: 'No error',
|
||||
details: 'details',
|
||||
),
|
||||
data: data,
|
||||
);
|
||||
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['message'], 'Success');
|
||||
expect(json['success'], true);
|
||||
expect(response.data?.name, 'NeuralNet');
|
||||
});
|
||||
|
||||
test('copyWith should modify only specific fields', () {
|
||||
final response = const CompanyProfileResponse(
|
||||
message: 'Old message',
|
||||
success: false,
|
||||
error: null,
|
||||
data: null,
|
||||
);
|
||||
|
||||
final updated = response.copyWith(message: 'New message', success: true);
|
||||
|
||||
expect(updated.message, 'New message');
|
||||
expect(updated.success, true);
|
||||
expect(updated.data, null);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user