#!perl
use Cassandane::Tiny;

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

    my $res = $jmap->CallMethods([
        ['CalendarEvent/set', {
            create => {
                event1 => {
                    calendarIds => {
                        Default => JSON::true,
                    },
                    title => 'event1',
                    start => '2020-01-01T09:00:00',
                    timeZone => 'Europe/Vienna',
                    duration => 'PT1H',
                },
            },
        }, 'R1'],
    ]);
    my $eventId = $res->[0][1]{created}{event1}{id};
    $self->assert_not_null($eventId);
    my $blobId = $res->[0][1]{created}{event1}{blobId};
    $self->assert_not_null($blobId);

    $res = $jmap->CallMethods([
        ['Blob/lookup', {
            typeNames => [
                'CalendarEvent',
            ],
            ids => [$blobId],
        }, 'R1'],
    ], [
        'urn:ietf:params:jmap:core',
        'https://cyrusimap.org/ns/jmap/blob',
    ]);
    $self->assert_deep_equals([{
        id => $blobId,
        matchedIds => {
            CalendarEvent => [
                $eventId,
            ],
        },
    }], $res->[0][1]{list});
}
