#!perl
use Cassandane::Tiny;

sub test_contact_set_create_bday_noyear
    :needs_dependency_icalvcard
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $service = $self->{instance}->get_service("http");
    $ENV{DEBUGDAV} = 1;
    my $carddav = Net::CardDAVTalk->new(
        user => 'cassandane',
        password => 'pass',
        host => $service->host(),
        port => $service->port(),
        scheme => 'http',
        url => '/',
        expandurl => 1,
    );

    my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';

    my $res = $jmap->CallMethods([
        ['Contact/set', {
            create => {
                "1" => {
                    uid => $id,
                    firstName => 'Jane',
                    lastName => 'Doe',
                    birthday => '0000-04-15'
                }
            }
         }, 'R1'],
        ['Contact/get', { ids => [ "#1" ] }, 'R2']
    ]);

    $self->assert_not_null($res->[0][1]{created}{1});

    my $href = $res->[1][1]{list}[0]{'x-href'};
    $res = $carddav->Request('GET', $href, '',
                             'Accept' => 'text/vcard; version=4.0');

    my $card = $res->{content};
    $card =~ s/\r?\n[ \t]+//gs;  # unfold long properties

    $self->assert_matches(qr|BDAY(;VALUE=DATE)?:--0415|, $card);
}
