#!perl
use Cassandane::Tiny;

#
# Test big conversation rename
#
sub test_rename_user_midsizeconversation
    :AllowMoves :Conversations :min_version_3_0 :NoAltNameSpace
    ($self)
{
    my $admintalk = $self->{adminstore}->get_client();

    xlog $self, "Test user rename with a big conversation";

    my %exp;

    $admintalk->create("user.cassandane.foo") || die;
    $admintalk->create("user.cassandane.bar") || die;
    $admintalk->create("user.cassandane.foo.sub") || die;

    $self->{store}->set_folder("INBOX.foo");
    $self->{store}->set_fetch_attributes('uid', 'cid');

    $exp{A} = $self->make_message("Message A");
    $exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid());

    for (1..80) {
      $exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]);
      $exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid());
    }

    $self->check_conversations();

    $self->check_messages(\%exp, keyed_on => 'uid');

    my $res = $admintalk->rename('user.cassandane', 'user.newuser');
    $self->assert(not $admintalk->get_last_error());

    $res = $admintalk->select("user.newuser.foo.sub");
    $self->assert(not $admintalk->get_last_error());

    $self->{adminstore}->set_folder("user.newuser.foo");
    $self->{adminstore}->set_fetch_attributes('uid', 'cid');
    $self->check_messages(\%exp, keyed_on => 'uid', store => $self->{adminstore});

    $self->check_conversations();
}
