API: test /nrbuilds and fix jobset / project references

This commit is contained in:
Graham Christensen 2022-01-14 13:42:00 -05:00
parent 86473f4b3c
commit fe095a56c5
2 changed files with 36 additions and 3 deletions

View file

@ -160,15 +160,25 @@ sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) {
my $system = $c->request->params->{system};
my $filter = {finished => 1};
$filter->{project} = $project if ! $project eq "";
$filter->{jobset} = $jobset if ! $jobset eq "";
$filter->{"jobset.project"} = $project if ! $project eq "";
$filter->{"jobset.name"} = $jobset if ! $jobset eq "";
$filter->{job} = $job if !$job eq "";
$filter->{system} = $system if !$system eq "";
$base = 60*60 if($period eq "hour");
$base = 24*60*60 if($period eq "day");
my @stats = $c->model('DB::Builds')->search($filter, {select => [{ count => "*" }], as => ["nr"], group_by => ["timestamp - timestamp % $base"], order_by => "timestamp - timestamp % $base DESC", rows => $nr});
my @stats = $c->model('DB::Builds')->search(
$filter,
{
select => [{ count => "*" }],
as => ["nr"],
group_by => ["timestamp - timestamp % $base"],
order_by => "timestamp - timestamp % $base DESC",
rows => $nr,
join => [ "jobset" ]
}
);
my @arr;
push @arr, int($_->get_column("nr")) foreach @stats;
@arr = reverse(@arr);

View file

@ -77,4 +77,27 @@ subtest "/api/latestbuilds" => sub {
};
};
subtest "/api/nrbuilds" => sub {
subtest "with no specific parameters" => sub {
my $response = request(GET '/api/nrbuilds?nr=1&period=hour');
ok($response->is_success, "The API enpdoint showing the latest builds returns 200.");
my $data = is_json($response);
is($data, [1]);
};
subtest "with very specific parameters" => sub {
my $build = $finishedBuilds->{"one_job"};
my $projectName = $build->project->name;
my $jobsetName = $build->jobset->name;
my $jobName = $build->job;
my $system = $build->system;
my $response = request(GET "/api/nrbuilds?nr=1&period=hour&project=$projectName&jobset=$jobsetName&job=$jobName&system=$system");
ok($response->is_success, "The API enpdoint showing the latest builds returns 200.");
my $data = is_json($response);
is($data, [1]);
};
};
done_testing;