1+ # !/usr/bin/env perl
2+ use Mojo::Base ' -signatures' ;
3+ use BlogDB::Web::Test;
4+
5+ my $t = Test::Mojo::BlogDB-> new(' BlogDB::Web' );
6+
7+ # Post a new blog as a logged in user.
8+ $t -> create_user-> post_ok( ' /blog/new' ,
9+ form => {
10+ url => ' https://modfoss.com/' ,
11+ })-> code_block( sub {
12+ my ( $t ) = @_ ;
13+ $t -> _ss($t -> app-> db-> resultset(' PendingBlog' )-> find( { url => ' https://modfoss.com/' }));
14+ ok $t -> _sg, " Created blog entry." ;
15+ });
16+
17+ my $blog_id = $t -> _sg-> id;
18+
19+ # New Session, update the blog as a can_manage_blogs user..
20+ $t = Test::Mojo::BlogDB-> new(' BlogDB::Web' );
21+
22+ $t -> create_user({ can_manage_blogs => 1 })-> post_ok( " /blog/new/$blog_id " , form => {
23+ title => ' modFoss' ,
24+ url => ' https://modfoss.com/' ,
25+ rss_url => ' https://modfoss.com/feed' ,
26+ tagline => ' Articles on technical matters.' ,
27+ about => ' A technical blog.'
28+ })-> code_block( sub {
29+ my ( $t ) = @_ ;
30+ $t -> _ss($t -> app-> db-> resultset(' PendingBlog' )-> find( { url => ' https://modfoss.com/' }));
31+ ok $t -> _sg, " Found blog entry" ;
32+ is $t -> _sg-> title, ' modFoss' , ' Title updated.' ;
33+ is $t -> _sg-> url, ' https://modfoss.com/' , ' URL updated.' ;
34+ is $t -> _sg-> rss_url , ' https://modfoss.com/feed' , ' RSS URL updated.' ;
35+ is $t -> _sg-> tagline , ' Articles on technical matters.' , ' Tagline updated.' ;
36+ is $t -> _sg-> about , ' A technical blog.' , ' About updated.' ;
37+ })-> stash_has( { authorization => [ ' setting:can_manage_blogs' ] } );
38+
39+ # Now we publish the blog, we're still in the user account with can_manage_blogs
40+ $t -> post_ok( " /blog/publish/$blog_id " , form => {})
41+ -> code_block( sub {
42+ my ( $t ) = @_ ;
43+ $t -> _ss($t -> app-> db-> resultset(' Blog' )-> find( { url => ' https://modfoss.com/' }));
44+ ok $t -> _sg, " Found published blog" ;
45+ is $t -> _sg-> title, ' modFoss' , ' Blog has correct title.' ;
46+
47+
48+ $t -> _ss($t -> app-> db-> resultset(' PendingBlog' )-> find( { url => ' https://modfoss.com/' }));
49+ is $t -> _sg, undef , " Blog has been deleted from PendingBlogs." ;
50+ });
51+
52+ done_testing;
0 commit comments