More tests!

master
Manager Bot 3 years ago
parent 2364272122
commit ffb59ad652
  1. 29
      Web/t/01_endpoints/06_user_settings/01_profile.t
  2. 53
      Web/t/01_endpoints/06_user_settings/02_do_profile.t
  3. 17
      Web/t/01_endpoints/06_user_settings/03_change_password.t
  4. 50
      Web/t/01_endpoints/06_user_settings/04_do_change_password.t

@ -0,0 +1,29 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that the profile page displays the user's name and email
# address.
#
# 1. Create user and login.
# 2. Go to the profile page
# 3. Confirm the form fields contain the correct information
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
my $blog_id = $t->create_user
->get_ok( '/profile' )
->status_is( 200 )
->code_block(sub {
my $self = shift;
ok exists $self->stash->{form}->{name}, 'Name exists in profile form.';
ok exists $self->stash->{form}->{email}, 'Email address exists in profile form.';
is $self->stash->{form}->{name}, $self->stash->{person}->name, "Name is set correctly.";
is $self->stash->{form}->{email}, $self->stash->{person}->email, "Email is set correctly.";
});
done_testing;

@ -0,0 +1,53 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that the profile page displays the user's name and email
# address.
#
# 1. Create user and login.
# 2. Go to the profile page
# 3. Confirm the form fields contain the correct information
# 4. Change the username and email
# 5. Get the profile again and confirm the changes.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Create user and confirm profile
$t->create_user
->get_ok( '/profile' )
->status_is( 200 )
->code_block(sub {
my $self = shift;
ok exists $self->stash->{form}->{name}, 'Name exists in profile form.';
ok exists $self->stash->{form}->{email}, 'Email address exists in profile form.';
is $self->stash->{form}->{name}, $self->stash->{person}->name, "Name is set correctly.";
is $self->stash->{form}->{email}, $self->stash->{person}->email, "Email is set correctly.";
});
# Update the name/email and confirm.
$t->post_ok( '/profile', form => {
name => 'Test Name',
email => 'test@test.com',
password => $t->stash->{person}->name,
})
->status_is( 302 )
->header_is( location => '/profile' )
->get_ok( '/profile' )
->status_is( 200 )
->code_block(sub {
my $self = shift;
ok exists $self->stash->{form}->{name}, 'Name exists in profile form.';
ok exists $self->stash->{form}->{email}, 'Email address exists in profile form.';
is $self->stash->{form}->{name}, 'Test Name', "Name was changed";
is $self->stash->{form}->{email}, 'test@test.com', "Email was changed";
});
done_testing;

@ -0,0 +1,17 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that the password change page exists.
#
# 1. Create user and login.
# 2. Go to the password page and confirm it exists.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
$t->create_user
->get_ok( '/password' )
->status_is( 200 );
done_testing;

@ -0,0 +1,50 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that the password change page works as expected.
#
# 1. Create user and login.
# 2. Go to the password page and confirm it exists.
# 3. Change the password for the user account
# 4. Logout and confirm being logged out.
# 5. Login with the new credentials and confirm being logged in.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Create a user and confirm the password page exists.
$t->create_user
->get_ok( '/password' )
->status_is( 200 );
# Change the password.
$t->post_ok( '/password', form => {
password => $t->stash->{person}->name,
new_password => 'Test-Password',
password_confirm => 'Test-Password',
})
->status_is( 302 )
->header_is( location => '/password' );
# Grab the email we'll use for logging back in.
my $email = $t->stash->{person}->email;
# Logout
$t->get_ok( '/logout' );
$t->get_ok( '/dashboard' )
->status_is( 302 )
->header_is( location => '/login', "User is logged out." );
# Try to login with the new password.
$t->post_ok( '/login', form => {
email => $email,
password => 'Test-Password',
})->status_is( 302
)->header_is( location => '/dashboard', 'Login redirected to dashboard' )
->code_block( sub {
is( scalar(@{shift->stash->{errors}}), 0, 'No errors' );
});
done_testing;
Loading…
Cancel
Save