#!perl use Cassandane::Tiny; sub test_calendarevent_parse_repair_broken_ical { my ($self) = @_; my $jmap = $self->{jmap}; my @testCases = ({ desc => 'Top-level component is VEVENT', wantParsed => { '@type' => 'Event', title => 'test', uid => '2a358cee-6489-4f14-a57f-c104db4dc357', }, ical => < 'iCalendar stream with two iCalendar objects', wantParsed => { '@type' => 'Event', title => 'test1', uid => '1a968fa5-3afd-4736-8fac-21958ef3db90', }, ical => < 'VEVENT without mandatory UID property', wantParsed => { '@type' => 'Event', title => 'test', # this need not be exactly this uid value uid => 'nouid218e89b7b9041f4b3c1999a93e6dec410b17b903', }, ical => < 'METHOD=PUBLISH without ORGANIZER in VEVENT', wantParsed => { '@type' => 'Event', uid => '01b1ee27-32c9-4c45-909b-c4c222666ebe', }, # We want to make sure that 'method' is NOT returned. wantAlsoProperties => ['method'], ical => < 'Multiple repairs required', wantParsed => { '@type' => 'Event', title => 'summary1', # this need not be exactly this uid value uid => 'nouidacf3612eeeeb579f42176697745fdc984d24aafc', }, # We want to make sure that 'method' is NOT returned. wantAlsoProperties => ['method'], ical => < 'Broken VALARMs: bad TRIGGER, no ACTION', wantParsed => { '@type' => 'Event', alerts => { valarmNoAction => { '@type' => "Alert", trigger => { '@type' => "OffsetTrigger", relativeTo => "start", offset => "PT0S" }, action => "display" } }, }, ical => <{ical} =~ s/\r?\n/\r\n/gs; my @properties = keys %{$tc->{wantParsed}}; push(@properties, @{$tc->{wantAlsoProperties} || []}); xlog $self, "Running test case: $tc->{desc}"; my $res = $jmap->CallMethods([ ['Blob/upload', { create => { ical => { data => [{ 'data:asText' => $tc->{ical}, }], }, }, }, 'R0'], ['CalendarEvent/parse', { blobIds => [ "#ical" ], repairBrokenIcal => JSON::true, properties => \@properties, }, 'R1'] ], [ 'urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:calendars', 'https://cyrusimap.org/ns/jmap/calendars', 'https://cyrusimap.org/ns/jmap/blob', ]); $self->assert_not_null($res->[0][1]{created}{ical}); if (not grep(/^uid$/, @properties)) { delete $res->[1][1]{parsed}{'#ical'}{uid}; } $self->assert_deep_equals($tc->{wantParsed}, $res->[1][1]{parsed}{'#ical'}); } }