59 lines
1.5 KiB
Dart
59 lines
1.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/data/services/model/address/address.dart';
|
|
|
|
void main() {
|
|
group('Address Model Tests', () {
|
|
test('fromJson should create a valid Address object', () {
|
|
final json = {
|
|
'street': '123 Main St',
|
|
'city': 'Tehran',
|
|
'state': 'Tehran',
|
|
'postal_code': '12345',
|
|
'country': 'Iran',
|
|
'address_type': 'home',
|
|
'is_default': true,
|
|
};
|
|
|
|
final address = Address.fromJson(json);
|
|
|
|
expect(address.street, '123 Main St');
|
|
expect(address.city, 'Tehran');
|
|
expect(address.isDefault, true);
|
|
});
|
|
|
|
test('toJson should return a valid JSON map', () {
|
|
final address = const Address(
|
|
street: '456 Elm St',
|
|
city: 'Shiraz',
|
|
state: 'Fars',
|
|
postalCode: '67890',
|
|
country: 'Iran',
|
|
addressType: 'office',
|
|
isDefault: false,
|
|
);
|
|
|
|
final json = address.toJson();
|
|
|
|
expect(json['street'], '456 Elm St');
|
|
expect(json['city'], 'Shiraz');
|
|
expect(json['is_default'], false);
|
|
});
|
|
|
|
test('copyWith should create a new Address with updated fields', () {
|
|
final address = const Address(
|
|
street: 'A',
|
|
city: 'B',
|
|
state: 'C',
|
|
postalCode: 'D',
|
|
country: 'E',
|
|
addressType: 'home',
|
|
isDefault: false,
|
|
);
|
|
|
|
final newAddress = address.copyWith(city: 'Tehran');
|
|
|
|
expect(newAddress.city, 'Tehran');
|
|
expect(newAddress.street, 'A');
|
|
});
|
|
});
|
|
} |