#!perl
use Cassandane::Tiny;

sub test_searchsnippet_get_regression
    :min_version_3_1 :needs_component_sieve :needs_component_jmap
    :JMAPExtensions
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $store = $self->{store};
    my $talk = $store->get_client();

    my $body = "--047d7b33dd729737fe04d3bde348\r\n";
    $body .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $body .= "\r\n";
    $body .= "This is the lady plain text part.";
    $body .= "\r\n";
    $body .= "--047d7b33dd729737fe04d3bde348\r\n";
    $body .= "Content-Type: text/html;charset=\"UTF-8\"\r\n";
    $body .= "\r\n";
    $body .= "<html><body><p>This is the lady html part.</p></body></html>";
    $body .= "\r\n";
    $body .= "--047d7b33dd729737fe04d3bde348--\r\n";
    $self->make_message("lady subject",
        mime_type => "multipart/alternative",
        mime_boundary => "047d7b33dd729737fe04d3bde348",
        body => $body
    ) || die;

    $self->{instance}->run_command({cyrus => 1}, 'squatter');

    my $using = [
        'https://cyrusimap.org/ns/jmap/performance',
        'https://cyrusimap.org/ns/jmap/debug',
        'urn:ietf:params:jmap:core',
        'urn:ietf:params:jmap:mail',
    ];

    my $res = $jmap->CallMethods([
        ['Email/query', { filter => {text => "lady"}}, "R1"],
    ], $using);
    my $emailIds = $res->[0][1]{ids};
    my $partIds = $res->[0][1]{partIds};

    $res = $jmap->CallMethods([
        ['SearchSnippet/get', {
            emailIds => $emailIds,
            filter => { text => "lady" },
        }, 'R2'],
    ], $using);
    $self->assert_num_equals(1, scalar @{$res->[0][1]{list}});
}
