use Test::Mojo;
use Data::Dumper;
use Storable;
+use Newslash::Util::TestMan;
my $t = Test::Mojo->new('Newslash::Web');
+my $test_man = Newslash::Util::TestMan->new($t);
+
+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");
+# prepare for test
+my ($user1, $user2);
+if ($t->app->mode eq 'test') {
+ $user1 = $test_man->create_user("msgtest1");
+ ok($user1, "create test user1");
+ $user2 = $test_man->create_user("msgtest2");
+ ok($user2, "create test user2");
+}
subtest 'basic message type methods' => sub {
plan skip_all => "mode is not 'test'" if ($t->app->mode ne 'test');
$rs = $messages->delete_message_type(message_type_id => $type->{message_type_id});
ok($rs, "delete message type");
+};
-};
+subtest 'message create and select' => sub {
+ plan skip_all => "mode is not 'test'" if ($t->app->mode ne 'test');
+ # set reply message's notification to web
+ ok($users->update_message_config(uid => $user2->{uid},
+ config => [ { code => 7, mode => 1 } ]),
+ "change notification mode");
+
+ my $title = "this is test";
+ my $body = "this is test message.";
+ my $msg_id = $messages->create(from => $user1->{uid},
+ to => $user2->{uid},
+ title => $title,
+ body => $body,
+ code => 7, # comment for journal,
+ type => "notify");
+ ok($msg_id, "create message");
+
+ # get message
+ my $msg = $web_messages->select(id => $msg_id);
+ ok($msg, "message created");
+ is($msg->{user}, $user2->{uid}, "check message user");
+ is($msg->{fuser}, 0, "check message fuser");
+ is($msg->{code}, 7, "check message code");
+ is($msg->{subject}, $title, "check message subject");
+ is($msg->{message}, $body, "check message");
+
+ ok($web_messages->hard_delete(id => $msg_id), "delete message");
+};
+$test_man->cleanup;
done_testing();