Skip to content

Commit 5da941d

Browse files
committed
Merge branch 'main' into feature/unittest
# Conflicts: # lib/data/models/authorities.dart # lib/data/models/change_password.dart # lib/data/models/city.dart # lib/data/models/customer.dart # lib/data/models/district.dart # lib/data/models/jwt_token.dart # lib/data/models/menu.dart # lib/data/models/user_jwt.dart # lib/main/main_local.mapper.g.dart # lib/main/main_prod.mapper.g.dart # test/data/model/authority_test.dart # test/data/model/change_password_test.dart # test/data/model/user_test.dart
2 parents 89d9902 + 265d3de commit 5da941d

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

test/data/model/customer_test.dart

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import 'package:flutter_bloc_advance/data/models/customer.dart';
2+
import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
void main() {
6+
late Customer customerModel;
7+
8+
Customer initCustomer() {
9+
return Customer(
10+
id: '1',
11+
name: 'Acme',
12+
phone: '5055055050',
13+
cityName: 'Konya',
14+
15+
districtName: 'selçuklu',
16+
address: 'yazır mh.',
17+
active: true,
18+
);
19+
}
20+
21+
setUp(() {
22+
initializeJsonMapper();
23+
24+
customerModel = initCustomer();
25+
});
26+
27+
group("Customer model", () {
28+
test("should create a Customer instance (Constructor)", () {
29+
final finalCustomer = customerModel;
30+
31+
expect(finalCustomer.id, '1');
32+
expect(finalCustomer.name, 'Acme');
33+
expect(finalCustomer.phone, '5055055050');
34+
expect(finalCustomer.cityName, 'Konya');
35+
expect(finalCustomer.email, '[email protected]');
36+
expect(finalCustomer.districtName, "selçuklu");
37+
expect(finalCustomer.address, 'yazır mh.');
38+
expect(finalCustomer.active, true);
39+
});
40+
41+
test('should copy a Customer instance with new values (copyWith)', () {
42+
final finalCustomer = customerModel;
43+
44+
final updatedCustomer = finalCustomer.copyWith(
45+
name: 'new Acme',
46+
cityName: 'izmir',
47+
districtName: 'göztepe',
48+
address: 'yazır',
49+
);
50+
51+
expect(updatedCustomer.id, '1');
52+
expect(updatedCustomer.name, 'new Acme');
53+
expect(updatedCustomer.phone, '5055055050');
54+
expect(updatedCustomer.cityName, 'izmir');
55+
expect(updatedCustomer.email, '[email protected]');
56+
expect(updatedCustomer.districtName, 'göztepe');
57+
expect(updatedCustomer.address, 'yazır');
58+
expect(updatedCustomer.active, true);
59+
});
60+
61+
test('should deserialize from JSON', () {
62+
final json = {
63+
'id': '1',
64+
'name': 'Acme',
65+
'phone': '5055055050',
66+
'cityName': 'Konya',
67+
'email': '[email protected]',
68+
'districtName': 'selçuklu',
69+
'address': 'yazır mh.',
70+
'active': true,
71+
};
72+
73+
final finalCustomer = Customer.fromJson(json);
74+
75+
expect(finalCustomer?.id, '1');
76+
expect(finalCustomer?.name, 'Acme');
77+
expect(finalCustomer?.phone, '5055055050');
78+
expect(finalCustomer?.cityName, 'Konya');
79+
expect(finalCustomer?.email, '[email protected]');
80+
expect(finalCustomer?.districtName, "selçuklu");
81+
expect(finalCustomer?.address, 'yazır mh.');
82+
expect(finalCustomer?.active, true);
83+
});
84+
85+
test('should deserialize from JSON string', () {
86+
final jsonString = '''
87+
{
88+
"id": "1",
89+
"name" : "Acme",
90+
"phone" : "5055055050",
91+
"cityName": "izmir",
92+
"email": "[email protected]",
93+
"districtName": "göztepe",
94+
"address": "yazır",
95+
"active": true
96+
}
97+
''';
98+
99+
final finalCustomer = Customer.fromJsonString(jsonString);
100+
101+
expect(finalCustomer?.id, '1');
102+
expect(finalCustomer?.name, 'Acme');
103+
expect(finalCustomer?.phone, '5055055050');
104+
expect(finalCustomer?.cityName, 'izmir');
105+
expect(finalCustomer?.email, '[email protected]');
106+
expect(finalCustomer?.districtName, "göztepe");
107+
expect(finalCustomer?.address, 'yazır');
108+
expect(finalCustomer?.active, true);
109+
});
110+
});
111+
}

0 commit comments

Comments
 (0)