#!perl
use Cassandane::Tiny;

sub test_card_set_update_extra_rejected
    :min_version_3_9 :needs_component_jmap :needs_dependency_icalvcard
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $carddav = $self->{carddav};

    my $res = $jmap->CallMethods([
        ['ContactCard/set', {
            create => {
                card1 => {
                    '@type' => 'Card',
                    name => {
                        full => 'John',
                    },
                },
            },
        }, 'R1'],
    ]);
    my $cardId = $res->[0][1]{created}{card1}{id};
    $self->assert_not_null($cardId);

    $res = $jmap->CallMethods([
        ['ContactCard/set', {
            update => {
                $cardId => {
                    extra => 'reserved',
                    'name/extra' => 'reserved',
                    localizations => {
                        de => {
                            'name/extra' => 'reserved2',
                        },
                    },
                },
            },
        }, 'R1'],
    ]);

    $self->assert_null($res->[0][1]{created}{card1});
    $self->assert_str_equals('invalidProperties',
        $res->[0][1]{notUpdated}{$cardId}{type});

    my @wantInvalidProps = (
        "extra",
        "localizations/de/name~1extra",
        "name/extra",
    );
    my @haveInvalidProps = sort @{$res->[0][1]{notUpdated}{$cardId}{properties}};
    $self->assert_deep_equals(\@wantInvalidProps, \@haveInvalidProps);
}
