Skip to content
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
17 changes: 17 additions & 0 deletions app/Models/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* @property int $buildid
Expand Down Expand Up @@ -44,4 +45,20 @@ public function build(): BelongsTo
{
return $this->belongsTo(Build::class, 'buildid');
}

/**
* @return HasOne<CoverageFile, $this>
*/
public function file(): HasOne
{
return $this->hasOne(CoverageFile::class, 'id', 'fileid');
}

/**
* A helper method used by Lighthouse to hide the fact that the path lives in a separate table.
*/
public function getFilePath(): ?string
{
return $this->file?->fullpath;
}
}
2 changes: 2 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ type Coverage {
"Unique primary key."
id: ID! @filterable

filePath: String! @with(relation: "file") @method(name: "getFilePath")

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

linesOfCodeUntested: Int! @rename(attribute: "locuntested") @filterable
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/GraphQL/CoverageTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\GraphQL;

use App\Models\CoverageFile;
use App\Models\Project;
use Illuminate\Support\Str;
use Tests\TestCase;
Expand All @@ -15,6 +16,9 @@ class CoverageTypeTest extends TestCase

private Project $project;

/** @var array<CoverageFile> */
private array $coverageFiles = [];

protected function setUp(): void
{
parent::setUp();
Expand All @@ -24,6 +28,10 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach ($this->coverageFiles as $file) {
$file->delete();
}

// Deleting the project will delete all corresponding builds and coverage results
$this->project->delete();

Expand All @@ -35,10 +43,18 @@ protected function tearDown(): void
*/
public function testBasicFieldAccess(): void
{
$coverageFile = CoverageFile::create([
'fullpath' => Str::uuid()->toString(),
'file' => Str::uuid()->toString(),
'crc32' => 0,
]);
$this->coverageFiles[] = $coverageFile;

$this->project->builds()->create([
'name' => Str::uuid()->toString(),
'uuid' => Str::uuid()->toString(),
])->coverageResults()->create([
'fileid' => $coverageFile->id,
'loctested' => 4,
'locuntested' => 5,
'branchestested' => 6,
Expand All @@ -56,6 +72,7 @@ public function testBasicFieldAccess(): void
coverageResults {
edges {
node {
filePath
linesOfCodeTested
linesOfCodeUntested
branchesTested
Expand Down Expand Up @@ -83,6 +100,7 @@ functionsUntested
'edges' => [
[
'node' => [
'filePath' => $coverageFile->fullpath,
'linesOfCodeTested' => 4,
'linesOfCodeUntested' => 5,
'branchesTested' => 6,
Expand Down