From f8b3482bde8852de4534daa733b0524e4fffc9f5 Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Sun, 27 Nov 2022 09:37:31 +0000 Subject: [PATCH] More tests. --- .../04_dashboard/08_blog_post_alter.t | 64 +++++++++++++++++ .../04_dashboard/09_do_blog_post_alter.t | 71 +++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 Web/t/01_endpoints/04_dashboard/08_blog_post_alter.t create mode 100644 Web/t/01_endpoints/04_dashboard/09_do_blog_post_alter.t diff --git a/Web/t/01_endpoints/04_dashboard/08_blog_post_alter.t b/Web/t/01_endpoints/04_dashboard/08_blog_post_alter.t new file mode 100644 index 0000000..407f89b --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/08_blog_post_alter.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 alter 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 alter 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/alter?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 alter 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/09_do_blog_post_alter.t b/Web/t/01_endpoints/04_dashboard/09_do_blog_post_alter.t new file mode 100644 index 0000000..cae1e26 --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/09_do_blog_post_alter.t @@ -0,0 +1,71 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog post can be edited in the alter 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. Make an edit to the post with the alter panel. +# 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.'; + +my $post = $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' ); + +is $post->headers->{title}, 'First Post!', 'The title of the post is correct.'; +is $post->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/alter", form => { + mdfile => '2022-11-27-first-post.markdown', + postHeaders => $post->headers_as_string, + postContent => 'This is my first edited post', + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/posts" ); + +# Try to re-read the post we edited and confirm it's correct. +$post = $t->app->jekyll( 'blog.example.com' )->get_post( '2022-11-27-first-post.markdown' ); + +is $post->headers->{title}, 'First Post!', 'The title of the post is correct.'; +is $post->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;