Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coverage type to GraphQL API #2515

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Models/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,12 @@ public function measurements(): HasMany
{
return $this->hasMany(BuildMeasurement::class, 'buildid');
}

/**
* @return HasMany<Coverage>
*/
public function coverageResults(): HasMany
{
return $this->hasMany(Coverage::class, 'buildid');
}
}
9 changes: 9 additions & 0 deletions app/Models/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property int $buildid
Expand Down Expand Up @@ -35,4 +36,12 @@ class Coverage extends Model
'functionstested',
'functionsuntested',
];

/**
* @return BelongsTo<Build, self>
*/
public function build(): BelongsTo
{
return $this->belongsTo(Build::class, 'buildid');
}
}
5 changes: 4 additions & 1 deletion app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ set_tests_properties(/Feature/GraphQL/NoteTypeTest PROPERTIES DEPENDS /Feature/G
add_laravel_test(/Feature/GraphQL/BuildMeasurementTypeTest)
set_tests_properties(/Feature/GraphQL/BuildMeasurementTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/GraphQL/CoverageTypeTest)
set_tests_properties(/Feature/GraphQL/CoverageTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/PurgeUnusedProjectsCommand)
set_tests_properties(/Feature/PurgeUnusedProjectsCommand PROPERTIES DEPENDS "/Feature/GraphQL/TestTypeTest;/Feature/GraphQL/TestMeasurementTypeTest;/Feature/GraphQL/NoteTypeTest;/Feature/GraphQL/BuildMeasurementTypeTest")
set_tests_properties(/Feature/PurgeUnusedProjectsCommand PROPERTIES DEPENDS "/Feature/GraphQL/TestTypeTest;/Feature/GraphQL/TestMeasurementTypeTest;/Feature/GraphQL/NoteTypeTest;/Feature/GraphQL/BuildMeasurementTypeTest;/Feature/GraphQL/CoverageTypeTest")

add_laravel_test(/Feature/TestSchemaMigration)
set_tests_properties(/Feature/TestSchemaMigration PROPERTIES DEPENDS /Feature/PurgeUnusedProjectsCommand)
Expand Down
35 changes: 35 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ type Build {
compilerName: String @rename(attribute: "compilername")

compilerVersion: String @rename(attribute: "compilerversion")

coverageResults(
filters: _ @filter(inputType: "CoverageFilterInput")
): [Coverage!]! @belongsToMany(type: CONNECTION) @orderBy(column: "id", direction: DESC)
}

input BuildFilterInput {
Expand Down Expand Up @@ -470,3 +474,34 @@ input NoteFilterInput {
name: String
text: String
}


"""
Coverage result for a particular build+file combination.
"""
type Coverage {
"Unique primary key."
id: ID!

linesOfCodeTested: Int! @rename(attribute: "loctested")

linesOfCodeUntested: Int! @rename(attribute: "locuntested")

branchesTested: Int! @rename(attribute: "branchestested")

branchesUntested: Int! @rename(attribute: "branchesuntested")

functionsTested: Int! @rename(attribute: "functionstested")

functionsUntested: Int! @rename(attribute: "functionsuntested")
}

input CoverageFilterInput {
id: ID
linesOfCodeTested: Int @rename(attribute: "loctested")
linesOfCodeUntested: Int @rename(attribute: "locuntested")
branchesTested: Int @rename(attribute: "branchestested")
branchesUntested: Int @rename(attribute: "branchesuntested")
functionsTested: Int @rename(attribute: "functionstested")
functionsUntested: Int @rename(attribute: "functionsuntested")
}
104 changes: 104 additions & 0 deletions tests/Feature/GraphQL/CoverageTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Tests\Feature\GraphQL;

use App\Models\Project;
use Illuminate\Support\Str;
use Tests\TestCase;
use Tests\Traits\CreatesProjects;
use Tests\Traits\CreatesUsers;

class CoverageTypeTest extends TestCase
{
use CreatesUsers;
use CreatesProjects;

private Project $project;

protected function setUp(): void
{
parent::setUp();

$this->project = $this->makePublicProject();
}

protected function tearDown(): void
{
// Deleting the project will delete all corresponding builds and coverage results
$this->project->delete();

parent::tearDown();
}

/**
* A basic test to ensure that each of the fields works
*/
public function testBasicFieldAccess(): void
{
$this->project->builds()->create([
'name' => Str::uuid()->toString(),
'uuid' => Str::uuid()->toString(),
])->coverageResults()->create([
'loctested' => 4,
'locuntested' => 5,
'branchestested' => 6,
'branchesuntested' => 7,
'functionstested' => 8,
'functionsuntested' => 9,
]);

$this->graphQL('
query project($id: ID) {
project(id: $id) {
builds {
edges {
node {
coverageResults {
edges {
node {
linesOfCodeTested
linesOfCodeUntested
branchesTested
branchesUntested
functionsTested
functionsUntested
}
}
}
}
}
}
}
}
', [
'id' => $this->project->id,
])->assertJson([
'data' => [
'project' => [
'builds' => [
'edges' => [
[
'node' => [
'coverageResults' => [
'edges' => [
[
'node' => [
'linesOfCodeTested' => 4,
'linesOfCodeUntested' => 5,
'branchesTested' => 6,
'branchesUntested' => 7,
'functionsTested' => 8,
'functionsUntested' => 9,
],
],
],
],
],
],
],
],
],
],
], true);
}
}