More tests.

master
Manager Bot 3 years ago
parent 6f8725b782
commit c86d6329bb
  1. 47
      Web/t/01_endpoints/01_admin/16_do_alert_read.t
  2. 51
      Web/t/01_endpoints/01_admin/17_do_alert_unread.t
  3. 44
      Web/t/01_endpoints/01_admin/18_do_alert_remove.t

@ -0,0 +1,47 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that we can mark alerts as read.
#
# When a user account is created, an alert about it is recorded.
#
# That alert will be loaded from the DB, and will be marked as read with
# the controller.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
#
# Promote the user to an admin
$t->app->config->{register}{enable_open} = 1;
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
})
->get_ok( '/' )
->code_block( sub {
my $self = shift;
$self->stash->{person}->is_admin( 1 );
ok( $self->stash->{person}->update, 'Promoted fred to an admin' );
});
# Find the alert.
my ( $alert ) = $t->app->db->system_notes->all;
ok $alert, "I have the alert.";
is $alert->is_read, 0, "The alert is marked as unread.";
# Submit the form to mark it as read.
$t->post_ok( '/admin/alert/read', form => { nid => $alert->id })
->status_is( 302 )
->header_is( location => '/admin/alerts' );
# Check that the alert is now marked as read.
is $t->app->db->system_note($alert->id)->is_read, 1, "The alert was marked as read.";
done_testing();

@ -0,0 +1,51 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that we can mark alerts as unread.
#
# It will be the same as the previous test, but extended to check
# the additional unread controller.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Create and promote a user to an admin
$t->app->config->{register}{enable_open} = 1;
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
})
->get_ok( '/' )
->code_block( sub {
my $self = shift;
$self->stash->{person}->is_admin( 1 );
ok( $self->stash->{person}->update, 'Promoted fred to an admin' );
});
# Find the alert.
my ( $alert ) = $t->app->db->system_notes->all;
ok $alert, "I have the alert.";
is $alert->is_read, 0, "The alert is marked as unread.";
# Submit the form to mark it as read.
$t->post_ok( '/admin/alert/read', form => { nid => $alert->id })
->status_is( 302 )
->header_is( location => '/admin/alerts' );
# Check that the alert is now marked as read.
is $t->app->db->system_note($alert->id)->is_read, 1, "The alert was marked as read.";
# Submit the form to mark it as unread.
$t->post_ok( '/admin/alert/unread', form => { nid => $alert->id })
->status_is( 302 )
->header_is( location => '/admin/alerts' );
# Check that the alert is now marked as unread.
is $t->app->db->system_note($alert->id)->is_read, 0, "The alert was marked as unread.";
done_testing();

@ -0,0 +1,44 @@
#!/usr/bin/env perl
use MJB::Web::Test;
#==
# This test ensures that we can remove alerts.
#
# It will create the note and an admin user just as the previous alert tests,
# however it will then use the remove controller to delete the note and confirm
# it has been removed.
#==
my $t = Test::Mojo::MJB->new('MJB::Web');
# Create and promote a user to an admin
$t->app->config->{register}{enable_open} = 1;
$t->post_ok( '/register/open', form => {
name => 'fred',
email => 'fred@blog.com',
password => 'SuperSecure',
password_confirm => 'SuperSecure',
})
->get_ok( '/' )
->code_block( sub {
my $self = shift;
$self->stash->{person}->is_admin( 1 );
ok( $self->stash->{person}->update, 'Promoted fred to an admin' );
});
# Find the alert.
my ( $alert ) = $t->app->db->system_notes->all;
ok $alert, "I have the alert.";
is $alert->is_read, 0, "The alert is marked as unread.";
# Submit the form to mark it as read.
$t->post_ok( '/admin/alert/remove', form => { nid => $alert->id })
->status_is( 302 )
->header_is( location => '/admin/alerts' );
# Check that the alert is now marked as read.
is $t->app->db->system_note($alert->id), undef, "The alert was removed.";
done_testing;
Loading…
Cancel
Save