#!perl
use Cassandane::Tiny;

# RFC 9425 Section 4.5 defines Quota/queryChanges as a standard /queryChanges
# method (RFC 8620 Section 5.6). Cyrus cannot calculate the changes, so the
# method must exist and answer cannotCalculateChanges rather than
# unknownMethod.

sub test_quota_querychanges
    :needs_component_jmap
    ($self)
{
    my $jmap = $self->{jmap};

    xlog $self, "get current query state";
    my $res = $jmap->CallMethods([['Quota/query', {}, 'R1']]);
    my $state = $res->[0][1]{queryState};
    $self->assert_not_null($state);

    xlog $self, "queryChanges is refused, not unknown";
    $res = $jmap->CallMethods([['Quota/queryChanges', {
        sinceQueryState => $state,
    }, 'R2']]);
    $self->assert_str_equals('error', $res->[0][0]);
    $self->assert_str_equals('cannotCalculateChanges', $res->[0][1]{type});
    $self->assert_str_equals('R2', $res->[0][2]);

    xlog $self, "arguments are still validated";
    $res = $jmap->CallMethods([['Quota/queryChanges', {
        sinceQueryState => $state,
        filter          => { nosuchproperty => 1 },
    }, 'R3']]);
    $self->assert_str_equals('error', $res->[0][0]);
    $self->assert_str_equals('invalidArguments', $res->[0][1]{type});
}
