diff --git a/Web/t/01_endpoints/01_admin/16_do_alert_read.t b/Web/t/01_endpoints/01_admin/16_do_alert_read.t new file mode 100644 index 0000000..947d22c --- /dev/null +++ b/Web/t/01_endpoints/01_admin/16_do_alert_read.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(); diff --git a/Web/t/01_endpoints/01_admin/17_do_alert_unread.t b/Web/t/01_endpoints/01_admin/17_do_alert_unread.t new file mode 100644 index 0000000..366a5a9 --- /dev/null +++ b/Web/t/01_endpoints/01_admin/17_do_alert_unread.t @@ -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(); diff --git a/Web/t/01_endpoints/01_admin/18_do_alert_remove.t b/Web/t/01_endpoints/01_admin/18_do_alert_remove.t new file mode 100644 index 0000000..76f808c --- /dev/null +++ b/Web/t/01_endpoints/01_admin/18_do_alert_remove.t @@ -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;