#!perl
use Cassandane::Tiny;

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

    my $jmap = $self->{jmap};

    my $res = $jmap->CallMethods([
        ['ContactGroup/set', {
            create => {
                1 => {
                    name => 'name1',
                    otherAccountContactIds => {
                        other1 => ['contact1'],
                        other2 => ['contact2']
                    }
                }
            }
        }, "R1"],
        ['ContactGroup/get', { ids => ['#1'] }, 'R2'],
    ]);
    $self->assert_str_equals('name1', $res->[1][1]{list}[0]{name});
    $self->assert_deep_equals({
        other1 => ['contact1'],
        other2 => ['contact2']
    }, $res->[1][1]{list}[0]{otherAccountContactIds});
    my $groupId1 = $res->[1][1]{list}[0]{id};

    $res = $jmap->CallMethods([
        ['ContactGroup/set', {
            update => {
                $groupId1 => {
                    name => 'updatedname1',
                    'otherAccountContactIds/other2' => undef,
                }
            }
        }, "R1"],
        ['ContactGroup/get', { ids => [$groupId1] }, 'R2'],
    ]);
    $self->assert_str_equals('updatedname1', $res->[1][1]{list}[0]{name});
    $self->assert_deep_equals({
        other1 => ['contact1'],
    }, $res->[1][1]{list}[0]{otherAccountContactIds});
}
