->json_is('/type' => "story");
};
- subtest 'journal post' => sub {
- my $text = <<"EOT";
-東芝が2013年7月から2015年8月までに発売されたノートPC45機種で使われているバッテリーの一部について、使い方によっては過熱してショートし発火する恐れがあるとし、新品への無償交換を行うことを発表した(<a href="http://www3.nhk.or.jp/news/html/20161110/k10010763661000.html">NHK</a>、<a href="http://pc.watch.impress.co.jp/docs/news/1029272.html">PC Watch</a>)。
-
-東芝のノートPCについては、<a href="http://hardware.srad.jp/story/14/11/14/2013216/">2014年</a>および<a href="https://mobile.srad.jp/story/16/01/29/2321242/">今年1月</a>にバッテリーの過熱・発煙・発火の恐れがあるとしてバッテリーのリコールが行われているが、発見されたのはこれとは別の不具合とのこと(<a href="https://batterycheck.toshiba.com/BatteryUpdate/InformationJapan?region=TJPN&country=JP&lang=ja">東芝の発表</a>)。そのため、以前問題ないとされたPCについても、再度確認が必要とのこと。
-
-EOT
-
- my $test_data = {
- title => "テスト日記",
- introtext => $text,
- commentstatus => 'enabled',
- action => 'post',
- # posttype => '',
- # tid => '',
- # submissioncopy = 0,
- };
- # anonymous user cannot create journals
- $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
- ->status_is(400);
-
- # login
- $t->post_ok('/login' => {Accept => '*/*'} => form => {nickname => 'test01', passwd => 'foobar'})
- ->status_is(302);
-
- # login user can create journals
- $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
- ->status_is(200)
- ->json_has('/id')
- ->json_is('/type' => "journal")
- ->json_hasnt('/message')
- ->or(sub {diag "message: " . $t->tx->res->json->{message}});
-
- # logout
- $t->get_ok('/logout')->status_is(302);
-
- };
}
subtest 'submission preview' => sub {
->json_has('/comment');
};
-subtest 'journal preview' => sub {
- my $test_data = {
- title => "テスト日記",
- journal => "日記テスト本文\nてすとてすと" . localtime,
- commentstatus => 'enabled',
- action => 'preview',
- };
-
- # anonymous user cannot create journals
- $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
- ->status_is(400);
-
- # login
- $t->post_ok('/login' => {Accept => '*/*'} => form => {nickname => 'test01', passwd => 'foobar'})
- ->status_is(302);
-
- # login user can create journals
- $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
- ->status_is(200)
- ->content_type_is('application/json')
- ->json_has('/title')
- ->json_has('/journal')
- ->json_hasnt('/message')
- ->or(sub {diag "message: " . $t->tx->res->json->{message}});
-
- # logout
- $t->get_ok('/logout')->status_is(302);
-};
-
done_testing();
--- /dev/null
+# -*-Perl-*-
+# destructive database-related tests
+use Mojo::Base -strict;
+use Mojo::Date;
+
+use Test::More;
+use Test::Mojo;
+use Mojo::Util qw(dumper);
+
+use POSIX qw(strftime);
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+SKIP: {
+ skip "mode is not 'test'", 0 if ($t->app->mode ne 'test');
+ subtest 'journal post' => sub {
+ my $text = <<"EOT";
+東芝が2013年7月から2015年8月までに発売されたノートPC45機種で使われているバッテリーの一部について、使い方によっては過熱してショートし発火する恐れがあるとし、新品への無償交換を行うことを発表した(<a href="http://www3.nhk.or.jp/news/html/20161110/k10010763661000.html">NHK</a>、<a href="http://pc.watch.impress.co.jp/docs/news/1029272.html">PC Watch</a>)。
+
+東芝のノートPCについては、<a href="http://hardware.srad.jp/story/14/11/14/2013216/">2014年</a>および<a href="https://mobile.srad.jp/story/16/01/29/2321242/">今年1月</a>にバッテリーの過熱・発煙・発火の恐れがあるとしてバッテリーのリコールが行われているが、発見されたのはこれとは別の不具合とのこと(<a href="https://batterycheck.toshiba.com/BatteryUpdate/InformationJapan?region=TJPN&country=JP&lang=ja">東芝の発表</a>)。そのため、以前問題ないとされたPCについても、再度確認が必要とのこと。
+
+EOT
+
+ my $test_data = {
+ title => "テスト日記",
+ introtext => $text,
+ commentstatus => 'enabled',
+ action => 'post',
+ # posttype => '',
+ # tid => '',
+ # submissioncopy = 0,
+ };
+ # anonymous user cannot create journals
+ $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
+ ->status_is(400);
+
+ # login
+ $t->post_ok('/login' => {Accept => '*/*'} => form => {nickname => 'test01', passwd => 'foobar'})
+ ->status_is(302);
+
+ # login user can create journals
+ $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
+ ->status_is(200)
+ ->json_has('/id')
+ ->json_is('/type' => "journal")
+ ->json_hasnt('/message')
+ ->or(sub {diag "message: " . $t->tx->res->json->{message}});
+
+ # logout
+ $t->get_ok('/logout')->status_is(302);
+
+ };
+
+ subtest 'journal preview' => sub {
+ my $test_data = {
+ title => "テスト日記",
+ journal => "日記テスト本文\nてすとてすと" . localtime,
+ commentstatus => 'enabled',
+ action => 'preview',
+ };
+
+ # anonymous user cannot create journals
+ $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
+ ->status_is(400);
+
+ # login
+ $t->post_ok('/login' => {Accept => '*/*'} => form => {nickname => 'test01', passwd => 'foobar'})
+ ->status_is(302);
+
+ # login user can create journals
+ $t->post_ok('/api/v1/journal' => {Accept => '*/*'} => json => $test_data)
+ ->status_is(200)
+ ->content_type_is('application/json')
+ ->json_has('/title')
+ ->json_has('/journal')
+ ->json_hasnt('/message')
+ ->or(sub {diag "message: " . $t->tx->res->json->{message}});
+
+ # logout
+ $t->get_ok('/logout')->status_is(302);
+ };
+
+};
+
+subtest 'get journal' => sub {
+ # login
+ #$t->post_ok('/login' => {Accept => '*/*'} => form => {nickname => 'test01', passwd => 'foobar'})
+ # ->status_is(302);
+
+ $t->get_ok('/api/v1/journal?nickname=hylom')
+ ->status_is(200)
+ ->content_type_is('application/json')
+ ->json_has('/journals')
+ ->or(sub {diag "message: " . dumper($t->tx->res->json);});
+
+ # logout
+ #$t->get_ok('/logout')->status_is(302);
+};
+
+done_testing();