lib/Test2/Harness/UI/Controller/Run.pm untested

filter: Statementstmt 0.0% 0 / 86 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 131 CC 11 SCAR 42.0
CC
11
Cov
0%
handle
132.0
BEGIN
2.0
BEGIN
2.0
CRAP 67.0
1 package Test2::Harness::UI::Controller::Run;
2 use strict;
3 use warnings;
4  
5 our $VERSION = '0.000150';
6  
7 use Data::GUID;
8 use List::Util qw/max/;
9 use Text::Xslate(qw/mark_raw/);
10 use Test2::Harness::UI::Util qw/share_dir/;
11 use Test2::Harness::UI::Response qw/resp error/;
12 use Test2::Harness::Util::JSON qw/encode_json decode_json/;
13 use Test2::Harness::UI::UUID qw/uuid_inflate/;
14  
15 use parent 'Test2::Harness::UI::Controller';
16 use Test2::Harness::UI::Util::HashBase qw/-title/;
17  
18 sub handle {
19 my $self = shift;
20 my ($route) = @_;
21  
22 my $req = $self->{+REQUEST};
23  
24 my $res = resp(200);
25 my $user = $req->user;
26  
27 die error(404 => 'Missing route') unless $route;
28  
29 my $run;
30  
31 if ($self->{+CONFIG}->single_run) {
32 $run = $user->runs->first or die error(404 => 'Invalid run');
33 }
34 else {
35 my $it = $route->{id} or die error(404 => 'No id');
36 $it = uuid_inflate($it) or die error(404 => "Invalid run id");
37 my $schema = $self->{+CONFIG}->schema;
38 $run = $schema->resultset('Run')->search({run_id => $it})->first or die error(404 => 'Invalid Run');
39 }
40  
41 if (my $act = $route->{action}) {
42 die error(401 => 'Login required') unless $user;
43  
44 if ($act eq 'pin_toggle') {
45 $run->update({pinned => $run->pinned ? 0 : 1});
46 }
47 elsif ($act eq 'parameters') {
48 $res->content_type('application/json');
49 $res->raw_body($run->parameters);
50 return $res;
51 }
52 elsif ($act eq 'cancel') {
53 $run->update({status => 'canceled'});
54 }
55 elsif ($act eq 'delete') {
56 die error(400 => "Cannot delete a pinned run") if $run->pinned;
57  
58 $run->coverages->delete;
59 $run->reportings->delete;
60  
61 my $batches = $run->resource_batches;
62 while (my $batch = $batches->next) {
63 $batch->resources->delete;
64 $batch->delete;
65 }
66  
67 my $jobs = $run->jobs;
68  
69 while (my $job = $jobs->next()) {
70 my $has_binary = $job->events->search({has_binary => 1});
71 while (my $e = $has_binary->next()) {
72 $e->binaries->delete;
73 $e->delete;
74 }
75  
76 $job->events->delete;
77 $job->job_fields->delete;
78 $job->delete;
79 }
80  
81 $run->run_fields->delete;
82 $run->sweeps->delete;
83 $run->delete;
84 }
85 }
86  
87 $res->content_type('application/json');
88 $res->raw_body($run);
89 return $res;
90 }
91  
92 1;
93  
94 __END__