Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic Calendar support/tests to JMAP::TestSuite #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/JMAP/TestSuite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 38 additions & 3 deletions lib/JMAP/TestSuite/Account.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
47 changes: 47 additions & 0 deletions lib/JMAP/TestSuite/Comparator/Calendar.pm
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 23 additions & 0 deletions lib/JMAP/TestSuite/Entity/Calendar.pm
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions lib/JMAP/TestSuite/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Sub::Exporter -setup => [ qw(
batch_ok
email
mailbox
calendar
thread
get_parts multipart part parts cmultipart cpart
) ];
Expand All @@ -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) = @_;
Expand Down
42 changes: 42 additions & 0 deletions t/Calendar/get/an-entity.t
Original file line number Diff line number Diff line change
@@ -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;
};
21 changes: 21 additions & 0 deletions t/Calendar/get/no-ids.t
Original file line number Diff line number Diff line change
@@ -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"
);
};
3 changes: 3 additions & 0 deletions t/Email/get/no-ids.t
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down