#!perl
use Cassandane::Tiny;

sub test_sieve_validate
    :min_version_3_3 :JMAPExtensions
{
    my ($self) = @_;

    my $jmap = $self->{jmap};

    xlog "validating scripts";
    my $res = $jmap->CallMethods([
        ['Blob/upload', {
            create => {
               "A" => { data => [{'data:asText' => "keepme;"}] },
               "B" => { data => [{'data:asText' => "keep;"}] }
            }
         }, "R0"],
        ['SieveScript/validate', {
            blobId => JSON::null
         }, "R1"],
        ['SieveScript/validate', {
            blobId => "#A",
            blobId => JSON::null
         }, "R2"],
        ['SieveScript/validate', {
            blobId => "#A"
         }, "R3"],
        ['SieveScript/validate', {
            blobId => "#B"
         }, "R4"],
    ]);
    $self->assert_not_null($res);

    $self->assert_str_equals("error", $res->[1][0]);
    $self->assert_str_equals("invalidArguments", $res->[1][1]{type});

    $self->assert_str_equals("error", $res->[2][0]);
    $self->assert_str_equals("invalidArguments", $res->[2][1]{type});

    $self->assert_str_equals("SieveScript/validate", $res->[3][0]);
    $self->assert_str_equals("invalidScript", $res->[3][1]{error}{type});

    $self->assert_str_equals("SieveScript/validate", $res->[4][0]);
    $self->assert_null($res->[4][1]{error});
}
