-
Notifications
You must be signed in to change notification settings - Fork 15
/
userdata_test.dart
125 lines (97 loc) · 3.15 KB
/
userdata_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import 'package:attendance/BackEnd/user.dart';
import 'package:test/test.dart';
void main() {
User testUser = User.instance();
String perfectName = 'someName';
String perfectPhone = '1234567890';
// @todo #42 Use Map object to create a testing json body
String jsonBody =
'{' + '"nativeName":"$perfectName",' + '"phone":"$perfectPhone"' + '}';
group('object inistantiation', () {
test('object should not be null', () {
expect(testUser, isNotNull);
});
test('singleton should not leak ', () {
User instance1 = new User();
User instance2 = new User();
expect(instance1.hashCode, equals(instance2.hashCode));
});
});
group('Rename', () {
test('should has no default values', () {
expect(testUser.nativeName, isNull);
});
test('should accept empty string', () {
testUser.rename('');
expect(testUser.nativeName, isEmpty);
});
test('should be matched ', () {
testUser.rename(perfectName);
expect(testUser.nativeName, 'someName');
});
test('should reject names longer than 20 chars', () {
try {
testUser.rename('This is a very long name');
} on FormatException catch (ex) {
expect(ex.message, 'invalid native name format');
}
});
test('should accept names shorter than 21 chars', () {
testUser.rename(perfectName);
expect(testUser.nativeName, perfectName);
});
});
group('changePhone', () {
test('should has no default values', () {
expect(testUser.phone, isNull);
});
test('should accept empty string', () {
testUser.changePhone('');
expect(testUser.phone, isEmpty);
});
test('should reject numbers start with leading zero ', () {
try {
testUser.changePhone('0123456789');
} on FormatException catch (ex) {
expect(ex.message, 'invalid phone number format');
}
});
test('should accept numbers start with non-leading zero ', () {
testUser.changePhone(perfectPhone);
expect(testUser.phone, perfectPhone);
});
test('should reject numbers start with country code ', () {
try {
testUser.changePhone('+012345678');
} on FormatException catch (ex) {
expect(ex.message, 'invalid phone number format');
}
});
test('should accept numbers start with no country code ', () {
testUser.changePhone(perfectPhone);
expect(testUser.phone, perfectPhone);
});
test('should be matched ', () {
expect(testUser.phone, '1234567890');
});
test('should reject numbers longer than 10 chars', () {
try {
testUser.changePhone('01234567890123456789');
} on FormatException catch (ex) {
expect(ex.message, 'invalid phone number format');
}
});
test('should accept numbers shorter than 11 chars', () {
testUser.changePhone(perfectPhone);
expect(testUser.phone, perfectPhone);
});
});
group('requestBody', () {
test('should return non empty body', () {
expect(testUser.requestBody(), isNotEmpty);
});
test('should return valid body', () {
expect(testUser.requestBody(), jsonBody);
});
});
}