#!perl
use Cassandane::Tiny;

sub test_capabilities
    :min_version_3_1 :JMAPExtensions
{
    my ($self) = @_;

    my $jmap = $self->{jmap};
    my $imaptalk = $self->{store}->get_client();
    my $admintalk = $self->{adminstore}->get_client();

    $self->{instance}->create_user("other");
    $admintalk->create("user.other.box1") or die;
    $admintalk->setacl("user.other.box1", "cassandane", "lrswp") or die;

    # Missing capability in 'using'
    my $res = $jmap->CallMethods([
        ['Core/echo', { hello => 'world' }, "R1"]
    ], []);
    $self->assert_str_equals('error', $res->[0][0]);
    $self->assert_str_equals('unknownMethod', $res->[0][1]{type});

    # Missing capability in account capabilities
    $res = $jmap->CallMethods([
        ['CalendarEvent/get', {
            accountId => 'other'
        }, "R1"]
    ], [
        'urn:ietf:params:jmap:core',
        'urn:ietf:params:jmap:calendars',
        'https://cyrusimap.org/ns/jmap/calendars',
    ]);
    $self->assert_str_equals('error', $res->[0][0]);
    $self->assert_str_equals('accountNotSupportedByMethod', $res->[0][1]{type});
}
