-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4987 from rsto/jmap_copy_preserve_xprops
JMAP Contacts: preserve x-properties in Contact/copy
- Loading branch information
Showing
5 changed files
with
342 additions
and
2 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
cassandane/tiny-tests/JMAPContacts/contact_copy_preserve_xprops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!perl | ||
use Cassandane::Tiny; | ||
|
||
sub test_contact_copy_preserve_xprops | ||
: needs_component_jmap { | ||
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 account"; | ||
$admintalk->create("user.other"); | ||
|
||
my $otherCarddav = Net::CardDAVTalk->new( | ||
user => "other", | ||
password => 'pass', | ||
host => $service->host(), | ||
port => $service->port(), | ||
scheme => 'http', | ||
url => '/', | ||
expandurl => 1, | ||
); | ||
|
||
my $otherJmap = Mail::JMAPTalk->new( | ||
user => 'other', | ||
password => 'pass', | ||
host => $service->host(), | ||
port => $service->port(), | ||
scheme => 'http', | ||
url => '/jmap/', | ||
); | ||
$otherJmap->DefaultUsing([ | ||
'urn:ietf:params:jmap:core', | ||
'https://cyrusimap.org/ns/jmap/contacts', | ||
'https://cyrusimap.org/ns/jmap/debug' | ||
]); | ||
|
||
xlog $self, "share addressbook"; | ||
$admintalk->setacl( | ||
"user.other.#addressbooks.Default", | ||
"cassandane" => 'lrswipkxtecdn' | ||
) or die; | ||
|
||
my $card = decode( | ||
'utf-8', <<EOF | ||
BEGIN:VCARD | ||
VERSION:3.0 | ||
UID:0A8F88DE-1073-4D47-926F-0D535523FD15 | ||
N:Smith;Hank;; | ||
FN:Hank Smith | ||
X-FOO;X-BAZ=Bam:Bar | ||
REV:2008-04-24T19:52:43Z | ||
END:VCARD | ||
EOF | ||
); | ||
$card =~ s/\r?\n/\r\n/gs; | ||
$carddav->Request('PUT', 'Default/test.vcf', $card, 'Content-Type' => 'text/vcard'); | ||
|
||
my $res = $jmap->CallMethods([ | ||
[ 'Contact/query', {}, 'R1' ], | ||
]); | ||
$self->assert_num_equals(1, scalar @{ $res->[0][1]{ids} }); | ||
my $contactId = $res->[0][1]{ids}[0]; | ||
$self->assert_not_null($contactId); | ||
|
||
$res = $jmap->CallMethods([ | ||
[ | ||
'Contact/copy', | ||
{ | ||
fromAccountId => 'cassandane', | ||
accountId => 'other', | ||
create => { | ||
contact1 => { | ||
addressbookId => 'Default', | ||
id => $contactId | ||
} | ||
}, | ||
onSuccessDestroyOriginal => JSON::false, | ||
}, | ||
'R1' | ||
], | ||
]); | ||
my $copiedContactId = $res->[0][1]{created}{contact1}{id}; | ||
$self->assert_not_null($copiedContactId); | ||
|
||
$res = $otherJmap->CallMethods([ | ||
[ | ||
'Contact/get', | ||
{ | ||
accountId => 'other', | ||
ids => [$copiedContactId], | ||
properties => [ 'x-href' ], | ||
}, | ||
'R1' | ||
], | ||
]); | ||
|
||
$card = $otherCarddav->Request('GET', $res->[0][1]{list}[0]{'x-href'}); | ||
$self->assert_matches(qr/^X-FOO;X-BAZ=Bam:Bar\r$/m, $card->{content}); | ||
} |
74 changes: 74 additions & 0 deletions
74
cassandane/tiny-tests/JMAPContacts/contact_set_preserve_xprops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!perl | ||
use Cassandane::Tiny; | ||
use Encode qw(decode); | ||
|
||
sub test_contact_set_preserve_xprops | ||
: needs_component_jmap { | ||
my ($self) = @_; | ||
my $jmap = $self->{jmap}; | ||
my $carddav = $self->{carddav}; | ||
|
||
xlog $self, "Create vCard with x-property"; | ||
my $card = decode( | ||
'utf-8', <<EOF | ||
BEGIN:VCARD | ||
VERSION:3.0 | ||
UID:0A8F88DE-1073-4D47-926F-0D535523FD15 | ||
N:Smith;Hank;; | ||
FN:Hank Smith | ||
X-FOO;X-BAZ=Bam:Bar | ||
REV:2008-04-24T19:52:43Z | ||
END:VCARD | ||
EOF | ||
); | ||
$card =~ s/\r?\n/\r\n/gs; | ||
$carddav->Request('PUT', 'Default/test.vcf', $card, 'Content-Type' => 'text/vcard'); | ||
|
||
xlog $self, "Update some contact property"; | ||
my $res = $jmap->CallMethods([ | ||
[ 'Contact/query', {}, 'R1' ], | ||
[ | ||
'Contact/get', | ||
{ | ||
'#ids' => { | ||
resultOf => 'R1', | ||
path => '/ids', | ||
name => 'Contact/query', | ||
}, | ||
properties => ['lastName'], | ||
}, | ||
'R2' | ||
], | ||
]); | ||
|
||
my $contactId = $res->[0][1]{ids}[0]; | ||
$self->assert_not_null($contactId); | ||
$self->assert_str_equals('Smith', $res->[1][1]{list}[0]{lastName}); | ||
|
||
$res = $jmap->CallMethods([ | ||
[ | ||
'Contact/set', | ||
{ | ||
update => { | ||
$contactId => { | ||
lastName => 'Kraut', | ||
} | ||
}, | ||
}, | ||
'R1' | ||
], | ||
[ | ||
'Contact/get', | ||
{ | ||
ids => [$contactId], | ||
properties => ['lastName'], | ||
}, | ||
'R2' | ||
], | ||
]); | ||
$self->assert_str_equals('Kraut', $res->[1][1]{list}[0]{lastName}); | ||
|
||
xlog $self, "Update x-property is preserved in vCard"; | ||
$res = $carddav->Request('GET', 'Default/test.vcf'); | ||
$self->assert_matches(qr/^X-FOO;X-BAZ=Bam:Bar\r?$/m, $res->{content}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.