#!perl
use Cassandane::Tiny;

sub test_contact_copy_overquota
    :min_version_3_1
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $carddav = $self->{carddav};
    my $admintalk = $self->{adminstore}->get_client();
    my $service = $self->{instance}->get_service("http");

    xlog $self, "create shared accounts";
    $admintalk->create("user.other");

    my $othercarddav = Net::CardDAVTalk->new(
        user => "other",
        password => 'pass',
        host => $service->host(),
        port => $service->port(),
        scheme => 'http',
        url => '/',
        expandurl => 1,
    );

    $admintalk->setacl('user.other.#addressbooks.Default',
                       'cassandane' => 'lrswipkxtecdn') or die;

    $self->_set_quotaroot('user.other.#addressbooks');
    $self->_set_quotalimits(storage => 1);

    my $res = $jmap->CallMethods([
        ['Contact/set', {
            create => {
                1 => {
                    lastName => 'name',
                    notes => ('x' x 1024),
                },
            },
        }, 'R1'],
    ]);
    my $contactId = $res->[0][1]{created}{1}{id};
    $self->assert_not_null($contactId);

    $res = $jmap->CallMethods([
        ['Contact/copy', {
            fromAccountId => 'cassandane',
            accountId => 'other',
            create => {
                2 => {
                    id => $contactId,
                },
            },
        }, 'R1']
    ]);
    $self->assert_str_equals('overQuota', $res->[0][1]{notCreated}{2}{type});

}
