More tests.

master
Manager Bot 3 years ago
parent 7029ab517c
commit a885897fbe
  1. 34
      Web/t/01_endpoints/02_auth/01_register.t
  2. 29
      Web/t/01_endpoints/02_auth/02_register_open.t
  3. 69
      Web/t/01_endpoints/02_auth/03_do_register_open.t
  4. 29
      Web/t/01_endpoints/02_auth/04_register_invite.t
  5. 66
      Web/t/01_endpoints/02_auth/05_do_register_invite.t

@ -0,0 +1,34 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test file ensures that the open registration redirect system works as expected.
#
# The value of config->{register}{default} controls the redirect:
#
# invite -> /registration/invite
# open -> /registration/open
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Ensure both registration systems are enabled.
$t->app->config->{register}{enable_open} = 1;
$t->app->config->{register}{enable_invite} = 1;
# Check about redirects to the invite system working correctly.
$t->app->config->{register}{default} = 'invite';
$t->get_ok( '/register' )
->status_is( 302 )
->header_is( location => '/register/invite' );
# Check about redirects to the open system working correctly.
$t->app->config->{register}{default} = 'open';
# Ensure that a user who has come to this page is redirected to the default registration system
$t->get_ok( '/register' )
->status_is( 302 )
->header_is( location => '/register/open' );
done_testing();

@ -0,0 +1,29 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test file ensures that the open registration system works as expected.
#
# 1. When the open registration system is disabled, attemps to use it will result
# in the user being redirected to /register.
# 2. When the open registration system is enabled, the page displayes.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Make sure that this registration method is disabled.
$t->app->config->{register}{enable_open} = 0;
# Ensure that a user who has come to this page is redirected to the default registration system
$t->get_ok( '/register/open' )
->status_is( 302 )
->header_is( location => '/register' );
# Make sure that this registration method is enabled.
$t->app->config->{register}{enable_open} = 1;
# Ensure that the open registration page displays when it is enabled.
$t->get_ok( '/register/open' )
->status_is( 200 );
done_testing();

@ -0,0 +1,69 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test file ensures that the open registration system works as expected.
#
# 1. When the open registration system is disabled, attemps to use it will result
# in the user being redirected to /register.
# 2. When the form is submitted with errors, the account is not created and those
# errors are reported to the user.
# 3. When there are no errors, the user account is created and the user is logged in.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Make sure that this registration method is disabled.
$t->app->config->{register}{enable_open} = 0;
# Ensure that a user who has come to this page is redirected to the default registration system
$t->get_ok( '/register/open' )
->status_is( 302 )
->header_is( location => '/register' );
# Ensure that a user who submits this form in a naughty way is redirected to the default registration system
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
})
->status_is( 302 )
->header_is( location => '/register' )
->code_block( sub {
is( scalar(@{shift->stash->{errors}}), 0, 'No errors' );
});
# Make sure that this registration method is enabled.
$t->app->config->{register}{enable_open} = 1;
# Try creating an account with an error, ensure we get the error.
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperFail',
})->status_is( 302
)->code_block( sub {
is( shift->stash->{errors}->[0], 'Password and confirm password must match', 'Expected error thrown' );
})->code_block( sub {
is( shift->app->db->resultset('Person')->search( { name => 'fred'})->count, 0, 'No user created.');
});
## Try creating a valid account, ensure it exists in the DB.
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
})->status_is( 302
)->code_block( sub {
is( scalar(@{shift->stash->{errors}}), 0, 'No errors' );
})->code_block( sub {
is( shift->app->db->resultset('Person')->search( { name => 'fred'})->count, 1, 'User created.');
})->get_ok( '/'
)->code_block( sub {
is(shift->stash->{person}->name, 'fred', 'Got the fred after login...');
});
done_testing();

@ -0,0 +1,29 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test file ensures that the invite registration system works as expected.
#
# 1. When the invite registration system is disabled, attemps to use it will result
# in the user being redirected to /register.
# 2. When the invite registration system is enabled, the page displayes.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Make sure that this registration method is disabled.
$t->app->config->{register}{enable_invite} = 0;
# Ensure that a user who has come to this page is redirected to the default registration system
$t->get_ok( '/register/invite' )
->status_is( 302 )
->header_is( location => '/register' );
# Make sure that this registration method is enabled.
$t->app->config->{register}{enable_invite} = 1;
# Ensure that the invite registration page displays when it is enabled.
$t->get_ok( '/register/invite' )
->status_is( 200 );
done_testing();

@ -0,0 +1,66 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test file ensures that the invite registration system works as expected.
#
# 1. When the invite registration system is disabled, attemps to use it will result
# in the user being redirected to /register.
# 2. When the form is submitted without an invite code, the account is not created and
# an error is reported to the user.
# 3. When there is a valid invite code, the user account is created and the user is logged in.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Make sure that this registration method is disabled.
$t->app->config->{register}{enable_invite} = 0;
# Ensure you cannot register an account with the invite system when it is disabled.
$t->post_ok( '/register/invite', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
invite_code => 'invite-code',
})
->status_is( 302 )
->header_is( location => '/register' );
# Make sure that this registration method is disabled.
$t->app->config->{register}{enable_invite} = 1;
# Trying to register an account without a valid invite code will fail.
$t->post_ok( '/register/invite', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
invite_code => 'invite-code',
})
->status_is( 302 )
->header_is( location => '/register/invite' )
->code_block( sub {
my $self = shift;
is( scalar(@{$self->stash->{errors}}), 1, 'Got an expected error.' );
is( $self->stash->{errors}->[0], 'That invite code is not valid.', 'Expected error.' );
});
# Create an invite code.
$t->app->db->invites->create({ code => 'invite-code' });
# Register an account with a valid invite code.
$t->post_ok( '/register/invite', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
invite_code => 'invite-code',
})
->status_is( 302 )
->header_is( location => '/dashboard' )
->code_block( sub {
is( scalar(@{shift->stash->{errors}}), 0, 'No errors' );
});
done_testing();
Loading…
Cancel
Save