about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-05-09 10:45:05 +0200
committerfranck cuny <franck@lumberjaph.net>2011-05-09 16:42:15 +0200
commitf712cc7006c170c25f414a67a90bcb7df6d298cb (patch)
treef39846dcf4e4e76b35bfb8237d1e7a69a44b646b
parentadd a new route to the API to delete a task (diff)
downloadjitterbug-f712cc7006c170c25f414a67a90bcb7df6d298cb.tar.gz
add a new route to the API to list all tasks
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r--lib/jitterbug/WebService.pm23
-rw-r--r--t/003_hook_route.t18
2 files changed, 39 insertions, 2 deletions
diff --git a/lib/jitterbug/WebService.pm b/lib/jitterbug/WebService.pm
index d0cf92f..53d84bd 100644
--- a/lib/jitterbug/WebService.pm
+++ b/lib/jitterbug/WebService.pm
@@ -51,4 +51,27 @@ del '/task/:id' => sub {
     {status => "task $id deleted"};
 };
 
+get '/tasks' => sub {
+    my $tasks = schema->resultset('Task')->search();
+
+    my $content;
+
+    # I think we should never use internal ID when there is a sha256 available
+    while ( my $task = $tasks->next ) {
+        push @$content,
+          {
+            id           => $task->sha256,
+            running      => $task->running,
+            started_when => $task->started_when,
+            project      => {
+                id   => $task->projectid,
+                name => $task->project->name,
+            },
+            commit => from_json($task->commit->content),
+          };
+    }
+
+    {tasks => $content};
+};
+
 1;
diff --git a/t/003_hook_route.t b/t/003_hook_route.t
index 8475382..0ce6771 100644
--- a/t/003_hook_route.t
+++ b/t/003_hook_route.t
@@ -1,4 +1,4 @@
-use Test::More tests => 15;
+use Test::More tests => 17;
 use strict;
 use warnings;
 
@@ -162,7 +162,6 @@ my $response;
 }
 
 {
-    # delete a task
     $schema->resultset('Project')->search()->delete();
     $schema->resultset('Task')->search()->delete();
 
@@ -179,9 +178,24 @@ my $response;
         }
     );
 
+    # delete a task
     my $task = $schema->resultset('Task')->search()->single();
     $response = dancer_response(DELETE => '/api/task/'.$task->sha256);
     is $response->status, 201;
+
+    # list all the tasks
+    $response = dancer_response(
+        POST => '/hook/',
+        {
+            headers =>
+              [ 'Content-Type' => 'application/x-www-form-urlencoded' ],
+            body => _generate_post_request($content),
+        }
+    );
+    my $tasks = dancer_response(GET => '/api/tasks');
+    is $response->status, 200;
+    my $content = from_json($tasks->content);
+    is scalar @{$content->{tasks}}, 1;
 }
 
 sub _generate_post_request {