diff --git a/lib/JMAP/TestSuite.pm b/lib/JMAP/TestSuite.pm index 1d9a4b7..d8f9e3f 100644 --- a/lib/JMAP/TestSuite.pm +++ b/lib/JMAP/TestSuite.pm @@ -7,8 +7,9 @@ use JSON (); use Module::Runtime qw(require_module); use Path::Tiny; -use JMAP::TestSuite::Entity::Mailbox; +use JMAP::TestSuite::Entity::Calendar; use JMAP::TestSuite::Entity::Email; +use JMAP::TestSuite::Entity::Mailbox; use JMAP::TestSuite::Entity::Thread; sub get_server { diff --git a/lib/JMAP/TestSuite/Account.pm b/lib/JMAP/TestSuite/Account.pm index d872056..ccece12 100644 --- a/lib/JMAP/TestSuite/Account.pm +++ b/lib/JMAP/TestSuite/Account.pm @@ -163,7 +163,7 @@ package JMAP::TestSuite::Account { *$method = $code; } - my $inc = 0; + my $mb_inc = 0; sub create_mailbox { # XXX - This should probably not use Test::* functions and @@ -173,8 +173,8 @@ package JMAP::TestSuite::Account { my ($self, $arg) = @_; $arg ||= {}; - $arg->{name} ||= "Folder $inc at $^T.$$"; - $inc++; + $arg->{name} ||= "Folder $mb_inc at $^T.$$"; + $mb_inc++; my $batch = $self->create_batch(mailbox => { x => $arg, @@ -215,6 +215,41 @@ package JMAP::TestSuite::Account { ); } + my $cal_inc = 0; + + sub create_calendar { + # XXX - This should probably not use Test::* functions and + # instead hard fail if something goes wrong. + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my ($self, $arg) = @_; + + $arg ||= {}; + $arg->{name} ||= "Calendar $cal_inc at $^T.$$"; + $arg->{color} ||= '#ffffff'; + $cal_inc++; + + my $batch = $self->create_batch(calendar => { + x => $arg, + }); + + batch_ok($batch); + + ok($batch->is_entirely_successful, "created a calendar") + or diag explain $batch->all_results; + + my $x = $batch->result_for('x'); + + if ($ENV{JMTS_TELEMETRY}) { + note( + "Account " . $self->accountId + . " Created calendar '" . $x->name . "' id (" . $x->id . ")" + ); + } + + return $x; + } + no Moose::Role; } diff --git a/lib/JMAP/TestSuite/Comparator/Calendar.pm b/lib/JMAP/TestSuite/Comparator/Calendar.pm new file mode 100644 index 0000000..6d31e4d --- /dev/null +++ b/lib/JMAP/TestSuite/Comparator/Calendar.pm @@ -0,0 +1,47 @@ +package JMAP::TestSuite::Comparator::Calendar; +use Moose; + +use Test::Deep ':v1'; +use Test::Deep::JType; +use Test::Deep::HashRec; + +use Sub::Exporter -setup => [ qw(calendar) ]; + +sub calendar { + my ($overrides) = @_; + + $overrides ||= {}; + + my %required = ( + id => jstr, + name => jstr, + color => jstr, + sortOrder => jnum, + isVisible => jbool, + mayReadFreeBusy => jbool, + mayReadItems => jbool, + mayAddItems => jbool, + mayModifyItems => jbool, + mayRemoveItems => jbool, + mayRename => jbool, + mayDelete => jbool, + ); + + my %optional; + + for my $k (keys %$overrides) { + if (exists $required{$k}) { + $required{$k} = $overrides->{$k}; + } else { + $optional{$k} = $overrides->{$k}; + } + } + + return hashrec({ + required => \%required, + optional => \%optional, + }); +} + +no Moose; +__PACKAGE__->meta->make_immutable; diff --git a/lib/JMAP/TestSuite/Entity/Calendar.pm b/lib/JMAP/TestSuite/Entity/Calendar.pm new file mode 100644 index 0000000..be08c84 --- /dev/null +++ b/lib/JMAP/TestSuite/Entity/Calendar.pm @@ -0,0 +1,23 @@ +package JMAP::TestSuite::Entity::Calendar; +use Moose; +use Carp (); +with 'JMAP::TestSuite::Entity' => { + singular_noun => 'calendar', + properties => [ qw( + id + name + color + sortOrder + isVisible + mayReadFreeBusy + mayReadItems + mayAddItems + mayModifyItems + mayRemoveItems + mayRename + mayDelete + ) ], +}; + +no Moose; +__PACKAGE__->meta->make_immutable; diff --git a/lib/JMAP/TestSuite/Util.pm b/lib/JMAP/TestSuite/Util.pm index a0703d4..455b7ed 100644 --- a/lib/JMAP/TestSuite/Util.pm +++ b/lib/JMAP/TestSuite/Util.pm @@ -6,6 +6,7 @@ use Sub::Exporter -setup => [ qw( batch_ok email mailbox + calendar thread get_parts multipart part parts cmultipart cpart ) ]; @@ -17,6 +18,7 @@ use Test::More; use JMAP::TestSuite::Comparator::Email qw(email); use JMAP::TestSuite::Comparator::Mailbox qw(mailbox); use JMAP::TestSuite::Comparator::Thread qw(thread); +use JMAP::TestSuite::Comparator::Calendar qw(calendar); sub batch_ok { my ($batch) = @_; diff --git a/t/Calendar/get/an-entity.t b/t/Calendar/get/an-entity.t new file mode 100644 index 0000000..f6f3c98 --- /dev/null +++ b/t/Calendar/get/an-entity.t @@ -0,0 +1,42 @@ +use jmaptest; + +use JMAP::TestSuite::Util qw(calendar); + +test { + my ($self) = @_; + + my $account = $self->any_account; + my $tester = $account->tester; + + my $calendar1 = $account->create_calendar; + + # Sanity, I guess + ok($calendar1->id, 'calendar has an id'); + ok($calendar1->name, 'calendar has a name'); + ok($calendar1->color, 'calendar has a color'); + + my $res = $tester->request([[ + "Calendar/get" => { ids => [ $calendar1->id ], }, + ]]); + ok($res->is_success, "Calendar/get") + or diag explain $res->response_payload; + + jcmp_deeply( + $res->single_sentence("Calendar/get")->arguments, + superhashof({ + accountId => jstr($account->accountId), + state => jstr(), + notFound => [], + list => [ + calendar({ + id => $calendar1->id, + name => $calendar1->name, + color => $calendar1->color, + sortOrder => 0, + isVisible => jtrue, + }), + ], + }), + "Base response looks good", + ) or diag explain $res->as_stripped_triples; +}; diff --git a/t/Calendar/get/no-ids.t b/t/Calendar/get/no-ids.t new file mode 100644 index 0000000..e1d324b --- /dev/null +++ b/t/Calendar/get/no-ids.t @@ -0,0 +1,21 @@ +use jmaptest; + +test { + my ($self) = @_; + + my $account = $self->any_account; + my $tester = $account->tester; + + # Add a calendar to make sure we don't get it + $account->create_calendar; + + my $res = $tester->request_ok( + [ "Calendar/get" => { ids => [] } ], + superhashof({ + accountId => jstr($account->accountId), + state => jstr(), + list => [], + }), + "Response for ids => [] looks good" + ); +}; diff --git a/t/Email/get/no-ids.t b/t/Email/get/no-ids.t index 339e0e3..472cc70 100644 --- a/t/Email/get/no-ids.t +++ b/t/Email/get/no-ids.t @@ -6,6 +6,9 @@ test { my $account = $self->any_account; my $tester = $account->tester; + # Add a message to make sure we don't get it + $account->create_mailbox->add_message; + my $res = $tester->request_ok( [ "Email/get" => { ids => [] } ], superhashof({