#!perl
use Cassandane::Tiny;

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

    xlog "Upload blob via JMAP";
    my $res = $jmap->Upload('someblob', "application/octet-stream");
    my $blobId = $res->{blobId};
    $self->assert_not_null($blobId);

    # clean notification cache
    $self->{instance}->getnotify();

    xlog "Create event with a Link.blobId";
    $res = $jmap->CallMethods([
        ['CalendarEvent/set', {
            create => {
                1 => {
                    uid => 'eventuid1local',
                    calendarIds => {
                        Default => JSON::true,
                    },
                    title => "event1",
                    start => "2019-12-10T23:30:00",
                    duration => "PT1H",
                    timeZone => "Australia/Melbourne",
                    links => {
                        link1 => {
                            rel => 'enclosure',
                            blobId => $blobId,
                            contentType => 'image/jpg',
                        },
                    },
                    replyTo => {
                        imip => 'mailto:cassandane@example.com',
                    },
                    participants => {
                        part1 => {
                            '@type' => 'Participant',
                            sendTo => {
                                imip => 'mailto:part1@local',
                            },
                            roles => {
                                attendee => JSON::true,
                            },
                        },
                    },
                    start => '2021-01-01T01:00:00',
                    timeZone => 'Europe/Berlin',
                    duration => 'PT1H',
                },
            },
        }, 'R1'],
    ]);
    my $eventId = $res->[0][1]{created}{1}{id};
    $self->assert_not_null($eventId);
    my $eventHref = $res->[0][1]{created}{1}{'x-href'};
    $self->assert_not_null($eventHref);

    $self->assert_rewrite_webdav_attachment_url_itip($eventHref);
}
