#!perl
use Cassandane::Tiny;

sub test_freebusy
    :min_version_3_0
{
    my ($self) = @_;

    my $CalDAV = $self->{caldav};

    my $CalendarId = $CalDAV->NewCalendar({name => 'foo'});
    $self->assert_not_null($CalendarId);

    $CalDAV->NewEvent($CalendarId, {
        timeZone => 'Etc/UTC',
        start => '2015-01-01T12:00:00',
        duration => 'PT1H',
        summary => 'waterfall',
    });

    $CalDAV->NewEvent($CalendarId, {
        timeZone => 'America/New_York',
        start => '2015-02-01T12:00:00',
        duration => 'PT1H',
        summary => 'waterfall2',
    });

    my ($data, $errors) = $CalDAV->GetFreeBusy($CalendarId);

    $self->assert_str_equals('2015-01-01T12:00:00', $data->[0]{start});
    $self->assert_str_equals('2015-02-01T17:00:00', $data->[1]{start});
    $self->assert_num_equals(2, scalar @$data);
}
