line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Checks::Contact; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
10794
|
use JMAP::Validation; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
95
|
|
4
|
4
|
|
|
4
|
|
1386
|
use JMAP::Validation::Checks::Address; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
119
|
|
5
|
4
|
|
|
4
|
|
21
|
use JMAP::Validation::Checks::Boolean; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
64
|
|
6
|
4
|
|
|
4
|
|
1484
|
use JMAP::Validation::Checks::ContactInformation; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
116
|
|
7
|
4
|
|
|
4
|
|
1312
|
use JMAP::Validation::Checks::File; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
114
|
|
8
|
4
|
|
|
4
|
|
20
|
use JMAP::Validation::Checks::String; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
58
|
|
9
|
4
|
|
|
4
|
|
1440
|
use JMAP::Validation::Tests::Contact; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
88
|
|
10
|
4
|
|
|
4
|
|
1232
|
use JMAP::Validation::Tests::SetError; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
83
|
|
11
|
4
|
|
|
4
|
|
15
|
use JMAP::Validation::Tests::String; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
46
|
|
12
|
4
|
|
|
4
|
|
12
|
use Test2::Bundle::Extended; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
18
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# record types {{{ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $is_Contact = hash { |
17
|
|
|
|
|
|
|
field id => $JMAP::Validation::Checks::String::is_id; |
18
|
|
|
|
|
|
|
field isFlagged => $JMAP::Validation::Checks::Boolean::is_boolean; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
field avatar => validator(sub { |
21
|
|
|
|
|
|
|
my (%params) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if (defined $params{got}) { |
24
|
|
|
|
|
|
|
return unless JMAP::Validation::validate( |
25
|
|
|
|
|
|
|
$params{got}, |
26
|
|
|
|
|
|
|
$JMAP::Validation::Checks::File::is_File, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
}); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my @string_types = qw{ |
34
|
|
|
|
|
|
|
prefix |
35
|
|
|
|
|
|
|
firstName |
36
|
|
|
|
|
|
|
lastName |
37
|
|
|
|
|
|
|
suffix |
38
|
|
|
|
|
|
|
nickname |
39
|
|
|
|
|
|
|
company |
40
|
|
|
|
|
|
|
department |
41
|
|
|
|
|
|
|
jobTitle |
42
|
|
|
|
|
|
|
notes |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
foreach my $field (@string_types) { |
46
|
|
|
|
|
|
|
field $field => $JMAP::Validation::Checks::String::is_string; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
field birthday => $JMAP::Validation::Checks::String::is_date; |
50
|
|
|
|
|
|
|
field anniversary => $JMAP::Validation::Checks::String::is_date; |
51
|
|
|
|
|
|
|
field emails => $JMAP::Validation::Checks::ContactInformation::is_ContactInformation_emails; |
52
|
|
|
|
|
|
|
field phones => $JMAP::Validation::Checks::ContactInformation::is_ContactInformation_phones; |
53
|
|
|
|
|
|
|
field online => $JMAP::Validation::Checks::ContactInformation::is_ContactInformation_online; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
field addresses => array { |
56
|
|
|
|
|
|
|
filter_items { grep { ! $JMAP::Validation::Checks::Address::is_Address } @_ }; |
57
|
|
|
|
|
|
|
end(); |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
end(); |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# }}} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# response types {{{ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
our $is_contacts = hash { |
68
|
|
|
|
|
|
|
field accountId => $JMAP::Validation::Checks::String::is_id; |
69
|
|
|
|
|
|
|
field state => $JMAP::Validation::Checks::String::is_string; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# TODO: https://github.com/Test-More/Test2-Suite/issues/9 |
72
|
|
|
|
|
|
|
# field list => array { all_items($is_Contact) }; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
field list => array{ |
75
|
|
|
|
|
|
|
filter_items { grep { ! JMAP::Validation::Tests::Contact::is_Contact($_) } @_ }; |
76
|
|
|
|
|
|
|
end(); |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
field notFound => validator(sub { |
80
|
|
|
|
|
|
|
my (%params) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
if (defined $params{got}) { |
83
|
|
|
|
|
|
|
return unless JMAP::Validation::validate( |
84
|
|
|
|
|
|
|
$params{got}, |
85
|
|
|
|
|
|
|
array { |
86
|
|
|
|
|
|
|
filter_items { grep { ! JMAP::Validation::Tests::String::is_string($_) } @_ }; |
87
|
|
|
|
|
|
|
end(); |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return 1; |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
our $is_contactUpdates = hash { |
97
|
|
|
|
|
|
|
field accountId => $JMAP::Validation::Checks::String::is_id; |
98
|
|
|
|
|
|
|
field oldState => $JMAP::Validation::Checks::String::is_string; |
99
|
|
|
|
|
|
|
field newState => $JMAP::Validation::Checks::String::is_string; |
100
|
|
|
|
|
|
|
field hasMoreUpdates => $JMAP::Validation::Checks::Boolean::is_boolean; |
101
|
|
|
|
|
|
|
field changed => $JMAP::Validation::Checks::String::is_array_of_ids; |
102
|
|
|
|
|
|
|
field removed => $JMAP::Validation::Checks::String::is_array_of_ids; |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
our $is_contactsSet = hash { |
106
|
|
|
|
|
|
|
field accountId => $JMAP::Validation::Checks::String::is_id; |
107
|
|
|
|
|
|
|
field oldState => $JMAP::Validation::Checks::String::is_string_or_null; |
108
|
|
|
|
|
|
|
field newState => $JMAP::Validation::Checks::String::is_string; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
field created => check_set( |
111
|
|
|
|
|
|
|
hash {}, |
112
|
|
|
|
|
|
|
validator(sub { |
113
|
|
|
|
|
|
|
my (%params) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
foreach my $createdId (keys %{$params{got}}) { |
116
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::Object::is_object($params{got}{$createdId}); |
117
|
|
|
|
|
|
|
return unless scalar(keys %{$params{got}{$createdId}}) == 1; |
118
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::String::is_id($params{got}{$createdId}{id}); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return 1; |
122
|
|
|
|
|
|
|
}), |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
field updated => $JMAP::Validation::Checks::String::is_array_of_ids; |
126
|
|
|
|
|
|
|
field destroyed => $JMAP::Validation::Checks::String::is_array_of_ids; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
field notCreated => check_set( |
129
|
|
|
|
|
|
|
hash {}, |
130
|
|
|
|
|
|
|
validator(sub { |
131
|
|
|
|
|
|
|
my (%params) = @_; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
foreach my $creationId (keys %{$params{got}}) { |
134
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::SetError::is_SetError_invalidProperties( |
135
|
|
|
|
|
|
|
$params{got}{$creationId}, qw{name contactIds}, |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return 1; |
140
|
|
|
|
|
|
|
}), |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
field notUpdated => check_set( |
144
|
|
|
|
|
|
|
hash {}, |
145
|
|
|
|
|
|
|
validator(sub { |
146
|
|
|
|
|
|
|
my (%params) = @_; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
foreach my $updatedId (keys %{$params{got}}) { |
149
|
|
|
|
|
|
|
my $is_notFound = JMAP::Validation::Tests::SetError::is_SetError_notFound( |
150
|
|
|
|
|
|
|
$params{got}{$updatedId} |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $is_invalidProperties = JMAP::Validation::Tests::SetError::is_SetError_invalidProperties( |
154
|
|
|
|
|
|
|
$params{got}{$updatedId}, qw{name contactIds}, |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
return unless ($is_notFound or $is_invalidProperties); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
return 1; |
161
|
|
|
|
|
|
|
}), |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
field notDestroyed => check_set( |
165
|
|
|
|
|
|
|
hash {}, |
166
|
|
|
|
|
|
|
validator(sub { |
167
|
|
|
|
|
|
|
my (%params) = @_; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
foreach my $destroyedId (keys %{$params{got}}) { |
170
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::SetError::is_SetError_notFound( |
171
|
|
|
|
|
|
|
$params{got}{$destroyedId} |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return 1; |
176
|
|
|
|
|
|
|
}), |
177
|
|
|
|
|
|
|
); |
178
|
|
|
|
|
|
|
}; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# }}} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |