From 40df91a29f74b19f3bd9f855eff02aa7e613d4dd Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Sun, 27 Nov 2022 09:22:10 +0000 Subject: [PATCH] More and more tests. --- .../01_endpoints/04_dashboard/04_blog_post.t | 37 +++++++++ .../04_dashboard/05_do_blog_post.t | 55 ++++++++++++++ .../04_dashboard/06_blog_post_edit.t | 64 ++++++++++++++++ .../04_dashboard/07_do_blog_post_edit.t | 76 +++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 Web/t/01_endpoints/04_dashboard/04_blog_post.t create mode 100644 Web/t/01_endpoints/04_dashboard/05_do_blog_post.t create mode 100644 Web/t/01_endpoints/04_dashboard/06_blog_post_edit.t create mode 100644 Web/t/01_endpoints/04_dashboard/07_do_blog_post_edit.t diff --git a/Web/t/01_endpoints/04_dashboard/04_blog_post.t b/Web/t/01_endpoints/04_dashboard/04_blog_post.t new file mode 100644 index 0000000..f73b2e9 --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/04_blog_post.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog post can be created in the creator panel. +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Load the post creator for that blog post. +#== + +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."; + }); + +$t->get_ok( "/dashboard/blog/$blog_id/post") + ->status_is( 200 ); +#== +# 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/05_do_blog_post.t b/Web/t/01_endpoints/04_dashboard/05_do_blog_post.t new file mode 100644 index 0000000..aa0661c --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/05_do_blog_post.t @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog post can be created. +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Make a new blog post. +# 4. Ensure that the blog post shows up in the blog listing. +# 5. Make sure that the raw file for the blog post exists / right content +#== + +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."; + }); + +$t->post_ok( "/dashboard/blog/$blog_id/post", form => { + postTitle => 'First Post!', + postDate => '2022-11-27 12:48:00 -0700', + postContent => 'This is my first post', + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/posts" ); + +# See if we have the blog post entry on disk, then try to read the post we created and confirm it's correct. +ok -f $t->app->jekyll( 'blog.example.com' )->root . '/blog.example.com/_posts/2022-11-27-first-post.markdown', + 'The new blog post was written to disk.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->headers->{title}, + 'First Post!', 'The title of the post is correct.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->markdown, + 'This is my first post', 'The content of the post is correct.'; + +#== +# 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/06_blog_post_edit.t b/Web/t/01_endpoints/04_dashboard/06_blog_post_edit.t new file mode 100644 index 0000000..a8b7717 --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/06_blog_post_edit.t @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog post can be edited in the editor panel +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Make a new blog post. +# 4. Ensure that the blog post shows up in the blog listing. +# 5. Make sure that the raw file for the blog post exists / right content +# 6. Load the editor for that blog post. +#== + +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."; + }); + +$t->post_ok( "/dashboard/blog/$blog_id/post", form => { + postTitle => 'First Post!', + postDate => '2022-11-27 12:48:00 -0700', + postContent => 'This is my first post', + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/posts" ); + +# See if we have the blog post entry on disk, then try to read the post we created and confirm it's correct. +ok -f $t->app->jekyll( 'blog.example.com' )->root . '/blog.example.com/_posts/2022-11-27-first-post.markdown', + 'The new blog post was written to disk.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->headers->{title}, + 'First Post!', 'The title of the post is correct.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->markdown, + 'This is my first post', 'The content of the post is correct.'; + +# Make an edit to the post +$t->get_ok( "/dashboard/blog/$blog_id/post/edit?mdfile=2022-11-27-first-post.markdown" ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + is $self->stash->{post}->markdown, 'This is my first post', 'Post editor loaded post.'; + }); + +#== +# 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/07_do_blog_post_edit.t b/Web/t/01_endpoints/04_dashboard/07_do_blog_post_edit.t new file mode 100644 index 0000000..fc89f16 --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/07_do_blog_post_edit.t @@ -0,0 +1,76 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog post can be edited. +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Make a new blog post. +# 4. Ensure that the blog post shows up in the blog listing. +# 5. Make sure that the raw file for the blog post exists / right content +# 6. Make an edit to the post. +# 7. Make sure that the raw file for the blog post exists / right content after edit +#== + +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."; + }); + +$t->post_ok( "/dashboard/blog/$blog_id/post", form => { + postTitle => 'First Post!', + postDate => '2022-11-27 12:48:00 -0700', + postContent => 'This is my first post', + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/posts" ); + +# See if we have the blog post entry on disk, then try to read the post we created and confirm it's correct. +ok -f $t->app->jekyll( 'blog.example.com' )->root . '/blog.example.com/_posts/2022-11-27-first-post.markdown', + 'The new blog post was written to disk.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->headers->{title}, + 'First Post!', 'The title of the post is correct.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->markdown, + 'This is my first post', 'The content of the post is correct.'; + + +# Make an edit to the post +$t->post_ok( "/dashboard/blog/$blog_id/post/edit", form => { + mdfile => '2022-11-27-first-post.markdown', + postTitle => 'First Post!', + postDate => '2022-11-27 12:48:00 -0700', + postContent => 'This is my first edited post', + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/posts" ); + +# Try to read the post we edited and confirm it's correct. + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->headers->{title}, + 'First Post!', 'The title of the post is correct.'; + +is $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' )->markdown, + 'This is my first edited post', 'The content of the post is correct.'; + +#== +# Remove Jekyll blog repos that were created as a part of this test. +#== +$t->clear_tempdir; + +done_testing;