#!perl
use Cassandane::Tiny;

sub test_calendarevent_set_updated
    :needs_component_httpd :needs_component_jmap :min_version_3_7
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $t = DateTime->now();
    $t->set_time_zone('Etc/UTC');
    my $start = $t->strftime('%Y-%m-%dT%H:%M:%S');
    $t->add(DateTime::Duration->new(days => -2));
    my $past = $t->strftime('%Y-%m-%dT%H:%M:%SZ');

    my $res = $jmap->CallMethods([
        ['CalendarEvent/set', {
            create => {
                event => {
                    calendarIds => {
                        'Default' => JSON::true,
                    },
                    start => $start,
                    timeZone => 'Etc/UTC',
                    duration => 'PT1H',
                    title => 'event',
                    created => $past,
                    updated => $past,
                },
            },
        }, 'R1'],
        ['CalendarEvent/get', {
            ids => [ '#event' ],
            properties => ['created', 'updated', 'title'],
        }, 'R2'],
    ]);

    $self->assert_str_equals($past, $res->[1][1]{list}[0]{created});
    my $updated = $res->[1][1]{list}[0]{updated};
    $self->assert($past lt $updated);
    $self->assert_str_equals($updated, $res->[0][1]{created}{event}{updated});
}
