#!perl
use Cassandane::Tiny;

sub test_email_query_dash
    :min_version_3_3 :needs_component_sieve :needs_component_jmap
    :JMAPExtensions
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $imap = $self->{store}->get_client();

    $self->make_message("something - otherthing", body => 'test') || die;
    $self->make_message("something", body => 'test') || die;
    $self->make_message("otherthing", body => 'test') || die;

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

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

    xlog "Running query with guidsearch";
    my $res = $jmap->CallMethods([
        ['Email/query', {
            filter => {
                "operator" => "AND",
                "conditions" => [
                    {
                        "subject" => "something"
                    },
                    {
                        "subject" => "-"
                    },
                    {
                        "subject" => "otherthing"
                    }
                ],
            },
        }, 'R1']
    ], $using);
    $self->assert_num_equals(1, scalar @{$res->[0][1]{ids}});
}
