#!perl
use Cassandane::Tiny;

sub test_contact_set_reject_duplicate_uid
    :min_version_3_5
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $carddav = $self->{carddav};

    $carddav->NewAddressBook('addrbookB') or die;

    my $res = $jmap->CallMethods([
        ['Contact/set', {
            create => {
                contactA => {
                    uid => '123456789',
                    lastName => 'contactA',
                },
            }
        }, 'R1'],
    ]);
    my $contactA = $res->[0][1]{created}{contactA}{id};
    $self->assert_not_null($contactA);

    $res = $jmap->CallMethods([
        ['Contact/set', {
            create => {
                contactB => {
                    addressbookId => 'addrbookB',
                    uid => '123456789',
                    lastName => 'contactB',
                },
            }
        }, 'R1'],
    ]);
    $self->assert_str_equals('invalidProperties',
        $res->[0][1]{notCreated}{contactB}{type});
    $self->assert_deep_equals(['uid'],
        $res->[0][1]{notCreated}{contactB}{properties});
}
