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

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 101 CC 6 SCAR 28.9
CC
6
Cov
0%
handle
42.0
title
2.0
BEGIN
2.0
CRAP 18.0
1 package Test2::Harness::UI::Controller::Events;
2 use strict;
3 use warnings;
4  
5 our $VERSION = '0.000150';
6  
7 use List::Util qw/max/;
8 use Test2::Harness::UI::Response qw/resp error/;
9 use Test2::Harness::Util::JSON qw/encode_json decode_json/;
10 use Test2::Harness::UI::UUID qw/uuid_inflate/;
11  
12 use parent 'Test2::Harness::UI::Controller';
13 use Test2::Harness::UI::Util::HashBase;
14  
15 sub title { 'Events' }
16  
17 sub handle {
18 my $self = shift;
19 my ($route) = @_;
20  
21 my $req = $self->{+REQUEST};
22 my $res = resp(200);
23 my $user = $req->user;
24 my $schema = $self->{+CONFIG}->schema;
25  
26 die error(404 => 'Missing route') unless $route;
27 my $it = $route->{id} or die error(404 => 'No name or id');
28  
29 my $p = $req->parameters;
30 my (%query, %attrs, $rs, $meth, $event);
31  
32 my $event_id = uuid_inflate($it) or die error(404 => "Invalid event id");
33  
34 if ($route->{from} eq 'single_event') {
35 $event = $schema->resultset('Event')->find({event_id => $event_id}, {remove_columns => [qw/orphan/]})
36 or die error(404 => 'Invalid Event');
37 }
38 else {
39 $event = $schema->resultset('Event')->find({event_id => $event_id}, {remove_columns => [qw/orphan facets/]})
40 or die error(404 => 'Invalid Event');
41 }
42  
43 $attrs{order_by} = {-asc => 'event_ord'};
44  
45 if ($route->{from} eq 'single_event') {
46 $res->content_type('application/json');
47 $res->raw_body($event);
48 return $res;
49 }
50  
51 $query{job_key} = $event->job_key;
52  
53 if ($p->{load_subtests}) {
54 # If we are loading subtests then we want ALL descendants, so here
55 # we take the parent event and find the next event of the same
56 # nesting level, then we want all events with an event_ord between
57 # them (in the same job);
58 my $end_at = $schema->resultset('Event')->find(
59 {%query, nested => $event->nested, event_ord => {'>' => $event->event_ord}},
60 {
61 columns => [qw/event_ord/],
62 %attrs,
63 },
64 );
65  
66 die error(404 => 'Cannot find subtest boundary') unless $end_at;
67 $query{event_ord} = {'>' => $event->event_ord, '<' => $end_at->event_ord};
68 }
69 else {
70 # We want direct descendants only
71 $query{'parent_id'} = $event_id;
72 }
73  
74 $rs = $schema->resultset('Event')->search(
75 \%query,
76 {
77 remove_columns => ['orphan'],
78 '+select' => [
79 'facets IS NOT NULL AS has_facets',
80 'orphan IS NOT NULL AS has_orphan',
81 ],
82 '+as' => [
83 'has_facets',
84 'has_orphan',
85 ],
86  
87 %attrs
88 },
89 );
90  
91 $res->stream(
92 env => $req->env,
93 content_type => 'application/x-jsonl; charset=utf-8',
94 resultset => $rs,
95 data_method => 'st_line_data',
96 );
97  
98 return $res;
99 }
100  
101 1;
102  
103 __END__