Skip to content

Commit

Permalink
New blog tests
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Nov 27, 2021
1 parent 3522388 commit 1db96a2
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Web/t/01_endpoints/03_blog/01_new_blog.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env perl
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

# Post a new blog as a logged in user, ensure that it exists,
# make sure that the submitter id matches.
$t->create_user->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
});

# Post a new blog as an anonymous user, ensure that it exists,
# and an edit token has been created for it.
Test::Mojo::BlogDB->new('BlogDB::Web')->post_ok( '/blog/new',
form => {
url => 'https://symkat.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://symkat.com/'}));
ok $t->_sg, "Created blog entry.";
is $t->_sg->submitter_id, undef, 'No submitter id for anonymous submitted blog.';
ok $t->_sg->edit_token, 'Edit token for a anonymous-submitted blog exists.';
});

done_testing;
39 changes: 39 additions & 0 deletions Web/t/01_endpoints/03_blog/02a_edit_new_blog_as_user.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env perl
# Test that a new blog submitted by a logged in user can be edited by that same user.
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
$t->create_user->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
});

my $blog_id = $t->_sg->id;

$t->post_ok( "/blog/new/$blog_id", form => {
title => 'modFoss',
url => 'https://modfoss.com/',
rss_url => 'https://modfoss.com/feed',
tagline => 'Articles on technical matters.',
about => 'A technical blog.'
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Found blog entry";
is $t->_sg->title, 'modFoss', 'Title updated.';
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
is $t->_sg->about , 'A technical blog.', 'About updated.';
})->stash_has( { authorization => [ 'submitter' ] } );

done_testing;
39 changes: 39 additions & 0 deletions Web/t/01_endpoints/03_blog/02b_edit_new_blog_edit_token.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env perl
#
# Post a new blog without any user account, and then edit the blog.
# Make sure the edit_token functionality is being used.
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

$t->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
ok $t->_sg->edit_token, 'Edit token exists';
});

my $blog_id = $t->_sg->id;

$t->post_ok( "/blog/new/$blog_id", form => {
title => 'modFoss',
url => 'https://modfoss.com/',
rss_url => 'https://modfoss.com/feed',
tagline => 'Articles on technical matters.',
about => 'A technical blog.'
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Found blog entry";
is $t->_sg->title, 'modFoss', 'Title updated.';
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
is $t->_sg->about , 'A technical blog.', 'About updated.';
})->stash_has( { authorization => [ 'token' ] } );

done_testing;
41 changes: 41 additions & 0 deletions Web/t/01_endpoints/03_blog/02c_edit_new_blog_setting.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env perl
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
$t->create_user->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
});

my $blog_id = $t->_sg->id;

# New Session.
$t = Test::Mojo::BlogDB->new('BlogDB::Web');

$t->create_user({ can_manage_blogs => 1 })->post_ok( "/blog/new/$blog_id", form => {
title => 'modFoss',
url => 'https://modfoss.com/',
rss_url => 'https://modfoss.com/feed',
tagline => 'Articles on technical matters.',
about => 'A technical blog.'
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Found blog entry";
is $t->_sg->title, 'modFoss', 'Title updated.';
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
is $t->_sg->about , 'A technical blog.', 'About updated.';
})->stash_has( { authorization => [ 'setting:can_manage_blogs' ] } );

done_testing;
41 changes: 41 additions & 0 deletions Web/t/01_endpoints/03_blog/02d_edit_new_blog_no_anonymous.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env perl
# Test that a new blog submitted by an anonymous user cannot be edited by a
# different anonymous user.
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

# Post a new blog entry.
$t->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
});

my $blog_id = $t->_sg->id;

# New Session.
$t = Test::Mojo::BlogDB->new('BlogDB::Web');

$t->post_ok( "/blog/new/$blog_id", form => {
title => 'modFoss',
url => 'https://modfoss.com/',
rss_url => 'https://modfoss.com/feed',
tagline => 'Articles on technical matters.',
about => 'A technical blog.'
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Found blog entry";
is $t->_sg->title, undef, 'Title still the same';
is $t->_sg->url, 'https://modfoss.com/', 'URL the same.';
is $t->_sg->rss_url , undef, 'RSS URL still the same.';
is $t->_sg->tagline , undef, 'Tagline still the same.';
is $t->_sg->about , undef, 'About still the same.';
})->stash_has( { errors => [ 'Not Authorized.' ] } );

done_testing;
42 changes: 42 additions & 0 deletions Web/t/01_endpoints/03_blog/02e_edit_new_blog_no_alt_user.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env perl
# Test that a new blog submitted by a logged in user cannot be edited by another user.
use Mojo::Base '-signatures';
use BlogDB::Web::Test;

my $t = Test::Mojo::BlogDB->new('BlogDB::Web');

# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
$t->create_user->post_ok( '/blog/new',
form => {
url => 'https://modfoss.com/',
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Created blog entry.";
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
});

my $blog_id = $t->_sg->id;

# New Session.
$t = Test::Mojo::BlogDB->new('BlogDB::Web');

$t->create_user->post_ok( "/blog/new/$blog_id", form => {
title => 'modFoss',
url => 'https://modfoss.com/',
rss_url => 'https://modfoss.com/feed',
tagline => 'Articles on technical matters.',
about => 'A technical blog.'
})->code_block( sub {
my ( $t ) = @_;
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
ok $t->_sg, "Found blog entry";
is $t->_sg->title, undef, 'Title still the same';
is $t->_sg->url, 'https://modfoss.com/', 'URL the same.';
is $t->_sg->rss_url , undef, 'RSS URL still the same.';
is $t->_sg->tagline , undef, 'Tagline still the same.';
is $t->_sg->about , undef, 'About still the same.';
})->stash_has( { errors => [ 'Not Authorized.' ] } );

done_testing;

0 comments on commit 1db96a2

Please sign in to comment.