--- /dev/null
+# -*-Perl-*-
+use Mojo::Base -strict;
+
+use Test::More;
+use Test::Mojo;
+use Newslash::Util::TestMan;
+use Data::Dumper;
+
+use Newslash::Eventd::Handler::Journal;
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+my ($admin, $user, $journal);
+
+my $test_man = Newslash::Util::TestMan->new($t);
+my $events = $t->app->model('events');
+ok($events, "get Events instance");
+
+my $journal_handler = new Newslash::Eventd::Handler::Journal($t->app);
+ok($journal_handler, "create journal handler instance");
+
+my $web_messages = $t->app->model('web_messages');
+ok($web_messages, "get WebMessages instance");
+my $messages = $t->app->model('messages');
+ok($messages, "get Messages instance");
+
+my $users = $t->app->model('users');
+ok($users, "get Users instance");
+
+my $relations = $t->app->model('relations');
+ok($users, "get Relations instance");
+
+my $test_title = "This is test journal foobar";
+
+# prepare for test
+if ($t->app->mode eq 'test') {
+ $admin = $test_man->create_admin("ehjadmin");
+ ok($admin, "create admin user");
+
+ $user = $test_man->create_user("ehjtest");
+ ok($user, "create test user");
+
+ ok($relations->create($user->{uid}, $admin->{uid}, "friend"),
+ "new relation create");
+
+ # set create friend journal notification to web
+ ok($users->update_message_config(uid => $user->{uid},
+ config => [ { code => 5, mode => 1 } ]),
+ "change notification mode for user");
+
+ $journal = $test_man->create_journal(user => $admin,
+ title => $test_title);
+ ok($journal, "create test journal");
+}
+
+subtest 'test journal:post handler' => sub {
+ plan skip_all => "mode is not 'test'" if ($t->app->mode ne 'test');
+
+ # create journal post event
+ $t->app->event_que->emit("journal", "post", $admin->{uid}, $journal->{id});
+
+ # get and process event
+ my $event = $events->select(type => "journal",
+ subtype => "post",
+ related_id => $journal->{id},
+ active => 1,
+ order_by => { created_timestamp => "DESC" },
+ limit => 1,
+ );
+ ok($event, "select events");
+ ok($event->[0], "get valid event");
+ if (!$event->[0]) {
+ diag Dumper $event;
+ }
+ else {
+ $event = $event->[0];
+ $journal_handler->post($event);
+ my $msgs = $web_messages->select(uid => $user->{uid},
+ order_by => { id => "DESC" },
+ limit => 1);
+ ok($msgs, "select web_message");
+ is(@$msgs, 1, "select valid message");
+ like($msgs->[0]->{subject}, qr/$journal->{title}/, "subject check 1");
+ like($msgs->[0]->{subject}, qr/$admin->{nickname}/, "subject check 2");
+ like($msgs->[0]->{message}, qr/\/journal\/$journal->{journal_id}/, "message check 1");
+
+ ok($web_messages->hard_delete(id => $msgs->[0]->{id}), "delete message");
+ }
+};
+
+$test_man->cleanup;
+done_testing;