#!perl
use Cassandane::Tiny;

sub test_calendarevent_get_recurrenceoverrides_before_after
    :min_version_3_5 :needs_component_jmap
{
    my ($self) = @_;

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

    xlog $self, "create events";
    my $res = $jmap->CallMethods([
        ['CalendarEvent/set', {
            create => {
                "1" => {
                    calendarIds => {
                        Default => JSON::true,
                    },
                    uid => 'event1uidlocal',
                    title => "event1",
                    start => "2020-01-01T09:00:00",
                    timeZone => "Europe/Vienna",
                    duration => "PT1H",
                    recurrenceRules => [{
                        frequency => 'daily',
                    }],
                    recurrenceOverrides => {
                        '2020-01-02T09:00:00' => {
                            title => 'override1',
                        },
                        '2020-01-03T09:00:00' => {
                            title => 'override2',
                        },
                        '2020-01-04T09:00:00' => {
                            title => 'override3',
                        },
                        '2020-01-05T09:00:00' => {
                            title => 'override4',
                        },
                    },
                },
            }
        }, 'R1'],
        ['CalendarEvent/get', {
            ids => ['#1'],
            properties => ['recurrenceOverrides'],
            recurrenceOverridesAfter => '2020-01-03T08:00:00Z',
            recurrenceOverridesBefore => '2020-01-05T08:00:00Z',
        }, 'R2'],
    ]);

    $self->assert_deep_equals({
        '2020-01-03T09:00:00' => {
            title => 'override2',
        },
        '2020-01-04T09:00:00' => {
            title => 'override3',
        },
    }, $res->[1][1]{list}[0]{recurrenceOverrides});
}
