OSDN Git Service

t: devide api.t to api/{comment|story|submission}.t
authorhylom <hylom@users.sourceforge.jp>
Fri, 31 Mar 2017 11:08:32 +0000 (20:08 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 31 Mar 2017 11:08:32 +0000 (20:08 +0900)
src/newslash_web/t/api.t
src/newslash_web/t/api/comment.t [new file with mode: 0644]
src/newslash_web/t/api/story.t [new file with mode: 0644]
src/newslash_web/t/api/submission.t [new file with mode: 0644]
src/newslash_web/t/comment.t [deleted file]

index 1305a9a..2c77422 100644 (file)
@@ -11,6 +11,11 @@ use POSIX qw(strftime);
 
 my $t = Test::Mojo->new('Newslash::Web');
 
+if ($t->app->mode eq 'test') {
+    my $user = create_user($t->app, "test01", "foobar");
+    ok($user, "create test user");
+}
+
 SKIP: {
     skip "mode is not 'test'", 4 if ($t->app->mode ne 'test');
 
diff --git a/src/newslash_web/t/api/comment.t b/src/newslash_web/t/api/comment.t
new file mode 100644 (file)
index 0000000..7d81d28
--- /dev/null
@@ -0,0 +1,56 @@
+# -*-Perl-*-
+# destructive database-related  tests
+use Mojo::Base -strict;
+use Mojo::Date;
+
+use Test::More;
+use Test::Mojo;
+use Data::Dumper;
+
+use POSIX qw(strftime);
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+if ($t->app->mode eq 'test') {
+    my $user = create_user($t->app, "test01", "foobar");
+    ok($user, "create test user");
+}
+
+SKIP: {
+    skip "mode is not 'test'", 4 if ($t->app->mode ne 'test');
+
+    subtest 'comment post' => sub {
+        my $test_data = {
+                         title => "テストコメント",
+                         comment => "コメントテスト本文\nてすとてすと" . localtime,
+                         discussion_id => 1,
+                         stoid => 1,
+                         action => 'post',
+                        };
+        $t->post_ok('/api/v1/comment' => {Accept => '*/*'} => json => $test_data)
+          ->status_is(200)
+          ->json_has('/id')
+          ->json_is('/type' => "comment");
+
+    };
+
+subtest 'comment preview' => sub {
+    my $test_data = {
+                     title => "テストコメント",
+                     comment => "コメントテスト本文\nてすとてすと" . localtime,
+                     stoid => 1,
+                     action => 'preview',
+                    };
+    $t->post_ok('/api/v1/comment' => {Accept => '*/*'} => json => $test_data)
+      ->status_is(200)
+      ->content_type_is('application/json')
+      ->json_has('/title')
+      ->json_has('/comment');
+};
+
+if ($t->app->mode eq 'test') {
+    delete_user($t->app, "test01");
+}
+
+
+done_testing();
diff --git a/src/newslash_web/t/api/story.t b/src/newslash_web/t/api/story.t
new file mode 100644 (file)
index 0000000..77eb4ce
--- /dev/null
@@ -0,0 +1,52 @@
+# -*-Perl-*-
+# destructive database-related  tests
+use Mojo::Base -strict;
+use Mojo::Date;
+
+use Test::More;
+use Test::Mojo;
+use Data::Dumper;
+
+use POSIX qw(strftime);
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+if ($t->app->mode eq 'test') {
+    my $user = create_user($t->app, "test01", "foobar");
+    ok($user, "create test user");
+}
+
+SKIP: {
+    skip "mode is not 'test'", 4 if ($t->app->mode ne 'test');
+
+    subtest 'story post' => sub {
+        my $createtime = strftime('%FT%T', gmtime);
+        my $test_data = {
+                         title => "テストストーリー",
+                         createtime => $createtime,
+                         author => "test01",
+                         dept => "テストdept",
+                         introtext => "テスト本文\nてすとてすと",
+                         bodytext => "",
+                         add_related => "",
+                         url => "",
+                         mediaurl => "",
+                         mediatype => "",
+                         email => "",
+                         commentstatus => "enabled",
+                         display => 1,
+                         action => 'post',
+                        };
+        $t->post_ok('/api/v1/story' => {Accept => '*/*'} => json => $test_data)
+          ->status_is(200)
+          ->json_has('/id')
+          ->json_is('/type' => "story");
+    };
+
+}
+
+if ($t->app->mode eq 'test') {
+    delete_user($t->app, "test01");
+}
+
+done_testing();
diff --git a/src/newslash_web/t/api/submission.t b/src/newslash_web/t/api/submission.t
new file mode 100644 (file)
index 0000000..9c8ba17
--- /dev/null
@@ -0,0 +1,60 @@
+# -*-Perl-*-
+# destructive database-related  tests
+use Mojo::Base -strict;
+use Mojo::Date;
+
+use Test::More;
+use Test::Mojo;
+use Data::Dumper;
+
+use POSIX qw(strftime);
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+if ($t->app->mode eq 'test') {
+    my $user = create_user($t->app, "test01", "foobar");
+    ok($user, "create test user");
+}
+
+SKIP: {
+    skip "mode is not 'test'", 4 if ($t->app->mode ne 'test');
+
+    subtest 'submission post' => sub {
+        my $test_data = {
+                         title => "テストタレコミ @ " . localtime,
+                         introtext => "テスト本文\nてすとてすと",
+                         action => 'post',
+                        };
+        $t->post_ok('/api/v1/submission' => {Accept => '*/*'} => json => $test_data)
+          ->status_is(200)
+          ->json_has('/id')
+          ->json_is('/type' => "submission");
+
+        # duplicated submission
+        $t->post_ok('/api/v1/submission' => {Accept => '*/*'} => json => $test_data)
+          ->status_is(409);
+    };
+
+}
+
+subtest 'submission preview' => sub {
+    my $test_data = {
+                     title => "テストタレコミ @ " . localtime,
+                     intro_text => "テスト本文\nてすとてすと",
+                     action => 'preview',
+                    };
+    $t->post_ok('/api/v1/submission' => {Accept => '*/*'} => json => $test_data)
+      ->status_is(200)
+      ->content_type_is('application/json')
+      ->json_has('/title')
+      ->json_has('/intro_text')
+      ->json_has('/email')
+      ->json_has('/tid');
+    #print STDERR Dumper
+};
+
+if ($t->app->mode eq 'test') {
+    delete_user($t->app, "test01");
+}
+
+done_testing();
diff --git a/src/newslash_web/t/comment.t b/src/newslash_web/t/comment.t
deleted file mode 100644 (file)
index 925166e..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-# -*-Perl-*-
-# destructive comment-related  tests
-use Mojo::Base -strict;
-
-use Test::More;
-use Test::Mojo;
-
-my $t = Test::Mojo->new('Newslash::Web');
-
-SKIP: {
-    skip "mode is not 'test'", 1 if ($t->app->mode ne 'test');
-    #my $comments = $t->app->model('comments');
-    my $stories = $t->app->model('stories');
-    my $params = {
-                  uid => 1,
-                  title => "Test Story",
-                  bodytext => '',
-                  introtext => 'Test Story body',
-                  topics_chosen => { # tid => weight
-                                    49 => 10,
-                                    2271 => 20,
-                                   },
-                  commentstatus => '',
-                  tid => 49,
-                  #subid => '',
-                 };
-    my $uid = 1;
-    my $sid = $stories->create($params, $uid);
-    ok($sid);
-}
-
-done_testing();