68 lines
2.0 KiB
Dart
68 lines
2.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/data/services/model/contact_person/contact_person.dart';
|
|
void main() {
|
|
group('ContactPerson Model Tests', () {
|
|
test('fromJson should create a valid ContactPerson object', () {
|
|
final json = {
|
|
'first_name': 'Ali',
|
|
'last_name': 'Rezaei',
|
|
'full_name': 'Ali Rezaei',
|
|
'position': 'Manager',
|
|
'email': 'ali@example.com',
|
|
'phone': '0211234567',
|
|
'mobile': '09121234567',
|
|
'is_primary': true,
|
|
};
|
|
|
|
final person = ContactPerson.fromJson(json);
|
|
|
|
expect(person.firstName, 'Ali');
|
|
expect(person.lastName, 'Rezaei');
|
|
expect(person.fullName, 'Ali Rezaei');
|
|
expect(person.position, 'Manager');
|
|
expect(person.email, 'ali@example.com');
|
|
expect(person.isPrimary, true);
|
|
});
|
|
|
|
test('toJson should return a valid JSON map', () {
|
|
const person = ContactPerson(
|
|
firstName: 'Sara',
|
|
lastName: 'Ahmadi',
|
|
fullName: 'Sara Ahmadi',
|
|
position: 'Developer',
|
|
email: 'sara@example.com',
|
|
phone: '0219876543',
|
|
mobile: '09129876543',
|
|
isPrimary: false,
|
|
);
|
|
|
|
final json = person.toJson();
|
|
|
|
expect(json['first_name'], 'Sara');
|
|
expect(json['last_name'], 'Ahmadi');
|
|
expect(json['full_name'], 'Sara Ahmadi');
|
|
expect(json['position'], 'Developer');
|
|
expect(json['email'], 'sara@example.com');
|
|
expect(json['is_primary'], false);
|
|
});
|
|
|
|
test('copyWith should create a new ContactPerson with updated fields', () {
|
|
const person = ContactPerson(
|
|
firstName: 'Ali',
|
|
lastName: 'Rezaei',
|
|
fullName: 'Ali Rezaei',
|
|
position: 'Manager',
|
|
email: 'ali@example.com',
|
|
phone: '0211234567',
|
|
mobile: '09121234567',
|
|
isPrimary: true,
|
|
);
|
|
|
|
final newPerson = person.copyWith(email: 'newemail@example.com');
|
|
|
|
expect(newPerson.email, 'newemail@example.com');
|
|
expect(newPerson.firstName, 'Ali');
|
|
});
|
|
});
|
|
}
|