#!perl
use Cassandane::Tiny;

sub test_calendarevent_get_recurrenceid
    :min_version_3_5
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $caldav = $self->{caldav};

    my $ical = <<EOF;
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//foo//bar//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:TRANSPARENT
DTSTART;TZID=Europe/Berlin:20160928T160000
RECURRENCE-ID;TZID=Europe/London:20160928T010000
DURATION:PT1H
UID:2a358cee-6489-4f14-a57f-c104db4dc357
DTSTAMP:20150928T132434Z
CREATED:20150928T125212Z
PRIORITY:3
SEQUENCE:9
SUMMARY:test
RRULE:FREQ=MONTHLY
LAST-MODIFIED:20150928T132434Z
END:VEVENT
END:VCALENDAR
EOF

    $caldav->Request('PUT', 'Default/2a358cee-6489-4f14-a57f-c104db4dc357.ics', $ical,
        'Content-Type' => 'text/calendar');

    my $res = $jmap->CallMethods([
        ['CalendarEvent/query', {
        }, 'R1'],
        ['CalendarEvent/get', {
            '#ids' => {
                resultOf => 'R1',
                name => 'CalendarEvent/query',
                path => '/ids'
            },
            properties => [
                'recurrenceId',
                'recurrenceIdTimeZone',
                'start',
                'timeZone',
            ],
        }, 'R2'],
    ]);
    $self->assert_num_equals(1, scalar @{$res->[1][1]{list}});
    my $event = $res->[1][1]{list}[0];

    $self->assert_str_equals('2016-09-28T16:00:00', $event->{start});
    $self->assert_str_equals('Europe/Berlin', $event->{timeZone});
    $self->assert_str_equals('2016-09-28T01:00:00', $event->{recurrenceId});
    $self->assert_str_equals('Europe/London', $event->{recurrenceIdTimeZone});
}
