#!perl
use Cassandane::Tiny;

sub test_identity_get
    :min_version_3_1 :needs_component_sieve :needs_component_jmap
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $id;
    my $res;

    # Make sure it's in the correct JMAP capability, as reported in
    # https://github.com/cyrusimap/cyrus-imapd/issues/2912
    my $using = [
        'urn:ietf:params:jmap:core',
        'urn:ietf:params:jmap:submission',
    ];

    xlog $self, "get identities";
    $res = $jmap->CallMethods([['Identity/get', { }, "R1"]], $using);

    $self->assert_num_equals(1, scalar @{$res->[0][1]->{list}});
    $self->assert_num_equals(0, scalar @{$res->[0][1]->{notFound}});

    $id = $res->[0][1]->{list}[0];
    $self->assert_not_null($id->{id});
    $self->assert_not_null($id->{email});

    xlog $self, "get unknown identities";
    $res = $jmap->CallMethods([['Identity/get', { ids => ["foo"] }, "R1"]], $using);
    $self->assert_num_equals(0, scalar @{$res->[0][1]->{list}});
    $self->assert_num_equals(1, scalar @{$res->[0][1]->{notFound}});
}
