#!perl
use Cassandane::Tiny;

sub test_calendarevent_get_recurrence
    :min_version_3_1
{
    my ($self) = @_;

    my ($id, $ical) = $self->icalfile('recurrence');

    my $event = $self->putandget_vevent($id, $ical);
    $self->assert_not_null($event->{recurrenceRules}[0]);
    $self->assert_str_equals("RecurrenceRule", $event->{recurrenceRules}[0]{q{@type}});
    $self->assert_str_equals("monthly", $event->{recurrenceRules}[0]{frequency});
    $self->assert_str_equals("gregorian", $event->{recurrenceRules}[0]{rscale});
    # This assertion is a bit brittle. It depends on the libical-internal
    # sort order for BYDAY
    $self->assert_deep_equals([{
                '@type' => 'NDay',
                "day" => "mo",
                "nthOfPeriod" => 2,
            }, {
                '@type' => 'NDay',
                "day" => "mo",
                "nthOfPeriod" => 1,
            }, {
                '@type' => 'NDay',
                "day" => "tu",
            }, {
                '@type' => 'NDay',
                "day" => "th",
                "nthOfPeriod" => -2,
            }, {
                '@type' => 'NDay',
                "day" => "sa",
                "nthOfPeriod" => -1,
            }, {
                '@type' => 'NDay',
                "day" => "su",
                "nthOfPeriod" => -3,
            }], $event->{recurrenceRules}[0]{byDay});
}
