File Coverage

blib/lib/JMAP/Tester/Response/Sentence/Set.pm
Criterion Covered Total %
statement 59 113 52.2
branch 8 14 57.1
condition 5 12 41.6
subroutine 12 23 52.1
pod 15 17 88.2
total 99 179 55.3


line stmt bran cond sub pod time code
1 2     2   407345 use v5.20.0;
  2         9  
2             package JMAP::Tester::Response::Sentence::Set 0.109;
3             # ABSTRACT: the kind of sentence you get in reply to a setFoos call
4              
5 2     2   611 use Moo;
  2         10070  
  2         16  
6             extends 'JMAP::Tester::Response::Sentence';
7              
8 2     2   4161 use experimental 'signatures';
  2         1797  
  2         16  
9              
10 2     2   1869 use Data::Dumper ();
  2         19204  
  2         83  
11 2     2   486 use JMAP::Tester::Abort 'abort';
  2         8  
  2         25  
12              
13 2     2   333 use namespace::clean;
  2         5  
  2         19  
14              
15             #pod =head1 OVERVIEW
16             #pod
17             #pod A "Set" sentence is a kind of L
18             #pod for representing C results. It has convenience methods for getting
19             #pod out the data returned in these kinds of sentences.
20             #pod
21             #pod =method new_state
22             #pod
23             #pod This returns the C in the result.
24             #pod
25             #pod =method old_state
26             #pod
27             #pod This returns the C in the result.
28             #pod
29             #pod =cut
30              
31 0     0 1 0 sub new_state ($self) { $self->arguments->{newState} }
  0         0  
  0         0  
  0         0  
32 0     0 1 0 sub old_state ($self) { $self->arguments->{oldState} }
  0         0  
  0         0  
  0         0  
33              
34             #pod =method created
35             #pod
36             #pod This returns the hashref of data in the C property.
37             #pod
38             #pod =method created_id
39             #pod
40             #pod my $id = $set->created_id( $cr_id );
41             #pod
42             #pod This returns the id given to the object created for the given creation id. If
43             #pod that creation id doesn't correspond to a created object, C is returned.
44             #pod
45             #pod =method created_creation_ids
46             #pod
47             #pod This returns the list of creation ids that were successfully created. Note:
48             #pod this returns I, not object ids.
49             #pod
50             #pod =method created_ids
51             #pod
52             #pod This returns the list of object ids that were successfully created.
53             #pod
54             #pod =method not_created_ids
55             #pod
56             #pod This returns the list of creation ids that were I successfully created.
57             #pod
58             #pod =method create_errors
59             #pod
60             #pod This returns a hashref mapping creation ids to error properties.
61             #pod
62             #pod =method updated_ids
63             #pod
64             #pod This returns a list of object ids that were successfully updated.
65             #pod
66             #pod =method not_updated_ids
67             #pod
68             #pod This returns a list of object ids that were I successfully updated.
69             #pod
70             #pod =method update_errors
71             #pod
72             #pod This returns a hashref mapping object ids to error properties.
73             #pod
74             #pod =method destroyed_ids
75             #pod
76             #pod This returns a list of object ids that were successfully destroyed.
77             #pod
78             #pod =method not_destroyed_ids
79             #pod
80             #pod This returns a list of object ids that were I successfully destroyed.
81             #pod
82             #pod =method destroy_errors
83             #pod
84             #pod This returns a hashref mapping object ids to error properties.
85             #pod
86             #pod =cut
87              
88 0     0 1 0 sub as_set ($self) { $self }
  0         0  
  0         0  
  0         0  
89              
90 0   0 0 1 0 sub created ($self) { $self->arguments->{created} // {} }
  0         0  
  0         0  
  0         0  
91              
92 0     0 1 0 sub created_id ($self, $creation_id) {
  0         0  
  0         0  
  0         0  
93 0 0       0 return undef unless my $props = $self->created->{$creation_id};
94 0         0 return $props->{id};
95             }
96              
97 0     0 1 0 sub created_creation_ids ($self) {
  0         0  
  0         0  
98 0         0 keys %{ $self->created }
  0         0  
99             }
100              
101 0     0 1 0 sub created_ids ($self) {
  0         0  
  0         0  
102 0         0 map {; $_->{id} } values %{ $self->created }
  0         0  
  0         0  
103             }
104              
105 2     2 1 2818 sub updated_ids ($self) {
  2         5  
  2         4  
106 2   50     9 my $updated = $self->{arguments}{updated} // {};
107              
108 2 100       10 if (ref $updated eq 'ARRAY') {
109 1         11 return @$updated;
110             }
111              
112 1         14 return keys %$updated;
113             }
114              
115 2     2 0 4 sub updated ($self) {
  2         5  
  2         3  
116 2   50     8 my $updated = $self->{arguments}{updated} // {};
117              
118 2 100       7 if (ref $updated eq 'ARRAY') {
119 1         3 return { map {; $_ => undef } @$updated };
  2         9  
120             }
121              
122 1         6 return $updated;
123             }
124              
125 0     0 1 0 sub destroyed_ids ($self) { @{ $self->{arguments}{destroyed} } }
  0         0  
  0         0  
  0         0  
  0         0  
126              
127             # Is this the best API to provide? I dunno, maybe. Usage will tell us whether
128             # it's right. -- rjbs, 2016-04-11
129 0     0 1 0 sub not_created_ids ($self) { keys %{ $self->{arguments}{notCreated} } }
  0         0  
  0         0  
  0         0  
  0         0  
130 0     0 1 0 sub not_updated_ids ($self) { keys %{ $self->{arguments}{notUpdated} } }
  0         0  
  0         0  
  0         0  
  0         0  
131 0     0 1 0 sub not_destroyed_ids ($self) { keys %{ $self->{arguments}{notDestroyed} } }
  0         0  
  0         0  
  0         0  
  0         0  
132              
133 1   50 1 1 3 sub create_errors ($self) { $self->{arguments}{notCreated} // {} }
  1         2  
  1         3  
  1         13  
134 2   50 2 1 5 sub update_errors ($self) { $self->{arguments}{notUpdated} // {} }
  2         23  
  2         5  
  2         49  
135 2   50 2 1 4 sub destroy_errors ($self) { $self->{arguments}{notDestroyed} // {} }
  2         5  
  2         4  
  2         15  
136              
137 1     1 0 45 sub assert_no_errors ($self) {
  1         3  
  1         3  
138 1         2 my @errors;
139 1         3 local $Data::Dumper::Terse = 1;
140              
141 1 50       2 if (keys %{ $self->create_errors }) {
  1         6  
142 0         0 push @errors, "notCreated: " . Data::Dumper::Dumper(
143             $self->_strip_json_types( $self->create_errors )
144             );
145             }
146              
147 1 50       3 if (keys %{ $self->update_errors }) {
  1         5  
148 1         6 push @errors, "notUpdated: " . Data::Dumper::Dumper(
149             $self->_strip_json_types( $self->update_errors )
150             );
151             }
152              
153 1 50       177 if (keys %{ $self->destroy_errors }) {
  1         6  
154 1         4 push @errors, "notDestroyed: " . Data::Dumper::Dumper(
155             $self->_strip_json_types( $self->destroy_errors )
156             );
157             }
158              
159 1 50       118 return $self unless @errors;
160              
161 1         16 $self->sentence_broker->abort(
162             "errors found in " . $self->name . " sentence",
163             \@errors,
164             );
165             }
166              
167             1;
168              
169             __END__