Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add and update tests for new behaviour with empty backups #519

Merged
merged 6 commits into from
Nov 5, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions tests/41end-to-end-keys/07-backup.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
my $fixture = local_user_fixture();

my $current_version; # FIXME: is there a better way of passing the backup version between tests?

test "Can create backup version",
requires => [ $fixture ],

Expand Down Expand Up @@ -40,6 +38,44 @@
});
};

test "Responds correctly when backup is empty",
requires => [ $fixture, qw( can_create_backup_version ) ],

do => sub {
my ( $user ) = @_;
my $version;

matrix_get_key_backup_info( $user )->then( sub {
my ( $content ) = @_;

log_if_fail "Content", $content;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we have a more descriptive description than "Content" ? (likewise below)


$version = $content->{version};

matrix_get_backup_key( $user, '!notaroom', 'notassession', $version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a space before the )

})->main::expect_http_4xx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a 4xx rather than something more specific? Also, please can we have a comment to say what we are testing here?

->then( sub {
matrix_get_backup_key( $user, '!notaroom', '', $version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it would be useful to have some more words to explain what we are testing and what we expect the result to be.

})->then( sub {
my ( $content ) = @_;

log_if_fail "Content", $content;

assert_deeply_eq( $content, {"sessions" => {}});

matrix_get_backup_key( $user, '', '', $version );
})->then( sub {
my ( $content ) = @_;

log_if_fail "Content", $content;

assert_deeply_eq( $content, {"rooms" => {}});

Future->done(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this

matrix_get_backup_key( $user, '', '', 'bogusversion');
})->main::expect_http_404;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use expect_m_not_found, to check the error code as well as the http code?

};

test "Can backup keys",
requires => [ $fixture, qw( can_create_backup_version ) ],

Expand Down Expand Up @@ -295,7 +331,13 @@
version => $content->{version},
}
);
})->main::expect_http_404;
})->then( sub {
my ( $content ) = @_;

assert_deeply_eq($content, {"rooms" => {}}, "Expected new backup to be empty");

Future->done(1);
});
};


Expand Down Expand Up @@ -393,9 +435,19 @@ =head2 matrix_get_backup_key
sub matrix_get_backup_key {
my ( $user, $room_id, $session_id, $version ) = @_;

my $uri;

if ($session_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to check for definedness rather than truthiness (if ( defined $session_id )) to distinguish between an absent param and an empty one.

Also, spaces inside parens please. (I don't make the rules...)

$uri = "/unstable/room_keys/keys/$room_id/$session_id";
} elsif ($room_id) {
$uri = "/unstable/room_keys/keys/$room_id";
} else {
$uri = "/unstable/room_keys/keys";
}

do_request_json_for( $user,
method => "GET",
uri => "/unstable/room_keys/keys/$room_id/$session_id",
uri => $uri,
params => {
version => $version,
},
Expand Down