From c08ce73906f75778d030dc2ec6efff23805991a1 Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Sun, 27 Nov 2022 08:31:27 +0000 Subject: [PATCH] Blog tests now! --- Web/t/01_endpoints/04_dashboard/01_index.t | 34 ++++++++++++++++++++++ Web/t/01_endpoints/04_dashboard/02_blog.t | 32 ++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Web/t/01_endpoints/04_dashboard/01_index.t create mode 100644 Web/t/01_endpoints/04_dashboard/02_blog.t diff --git a/Web/t/01_endpoints/04_dashboard/01_index.t b/Web/t/01_endpoints/04_dashboard/01_index.t new file mode 100644 index 0000000..d67585a --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/01_index.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that the dashboard index page works as expected. +# +# Users must login to access this page. +# +# This page will include blogs in the stash. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +$t->get_ok('/dashboard') + ->status_is( 302 ) + ->header_is( location => '/login', "Cannot access dashboard without login." ); + +$t->create_user + ->post_ok( '/blog/domain', form => { + domain => 'blog.example.com', + calling_route => 'show_blog_domain_owned', + }) + ->get_ok( '/dashboard' ) + ->code_block( sub { + my $self = shift; + is $self->stash->{blogs}->[0]->domain->name, 'blog.example.com', 'Found blog in listing on dashboard.'; + }); + +#== +# Remove Jekyll blog repos that were created as a part of this test. +#== +$t->clear_tempdir; + +done_testing; diff --git a/Web/t/01_endpoints/04_dashboard/02_blog.t b/Web/t/01_endpoints/04_dashboard/02_blog.t new file mode 100644 index 0000000..5fd0aba --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/02_blog.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that the blog index (info tab) page loads, +# and that correct blog is loaded into the stash.. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +my $blog_id = $t->create_user + ->post_ok( '/blog/domain', form => { + domain => 'blog.example.com', + calling_route => 'show_blog_domain_owned', + }) + ->get_ok( '/dashboard' ) + ->stash->{blogs}->[0]->id; + +$t->get_ok( "/dashboard/blog/$blog_id" ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + ok exists $self->stash->{blog}, "The blog loads!"; + is $self->stash->{blog}->domain->name, 'blog.example.com', "Correct domain name for id."; + }); + +#== +# Remove Jekyll blog repos that were created as a part of this test. +#== +$t->clear_tempdir; + +done_testing;