diff --git a/app/cdash/tests/CMakeLists.txt b/app/cdash/tests/CMakeLists.txt index 2a0aa62888..7e18b6fd60 100644 --- a/app/cdash/tests/CMakeLists.txt +++ b/app/cdash/tests/CMakeLists.txt @@ -236,6 +236,10 @@ add_feature_test(/Feature/GraphQL/BuildCommandTypeTest) add_feature_test(/Feature/GraphQL/BuildCommandOutputTypeTest) +add_feature_test(/Feature/GraphQL/UpdateTypeTest) + +add_feature_test(/Feature/GraphQL/UpdateFileTypeTest) + add_feature_test(/Feature/Submission/Instrumentation/BuildInstrumentationTest) add_feature_test(/Feature/Submission/Tests/TestXMLTest) diff --git a/graphql/schema.graphql b/graphql/schema.graphql index efbb5f56d7..c89700fa88 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -539,6 +539,10 @@ type Build { dynamicAnalyses( filters: _ @filter ): [DynamicAnalysis!]! @hasMany(type: CONNECTION) @orderBy(column: "id", direction: ASC) + + updates( + filters: _ @filter + ): [Update!]! @belongsToMany(type: CONNECTION) @orderBy(column: "id", direction: DESC) } @@ -964,3 +968,49 @@ type DynamicAnalysisDefect { value: Int! } + + +type Update @model(class: "App\\Models\\BuildUpdate") { + "Unique primary key." + id: ID! + + command: String! + + type: String @filterable + + status: String! @filterable + + revision: String @filterable + + priorRevision: String @rename(attribute: "priorrevision") @filterable + + path: String @filterable + + updateFiles( + filters: _ @filter + ): [UpdateFile!]! @hasMany(type: CONNECTION) @orderBy(column: "id", direction: DESC) +} + + +type UpdateFile @model(class: "App\\Models\\BuildUpdateFile") { + "Unique primary key." + id: ID! + + fileName: String @rename(attribute: "filename") @filterable + + authorName: String @rename(attribute: "author") @filterable + + authorEmail: String @rename(attribute: "email") @filterable + + committerName: String @rename(attribute: "committer") @filterable + + committerEmail: String @rename(attribute: "committeremail") @filterable + + log: String + + revision: String @filterable + + priorRevision: String @rename(attribute: "priorrevision") @filterable + + status: String! @filterable +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8414abb1a4..e4e337a465 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -27216,6 +27216,18 @@ parameters: count: 1 path: tests/Feature/GraphQL/SiteTypeTest.php + - + rawMessage: 'PHPDoc tag @var with type App\Models\BuildUpdate is not subtype of type App\Models\BuildUpdate&object{pivot: Illuminate\Database\Eloquent\Relations\Pivot}.' + identifier: varTag.type + count: 1 + path: tests/Feature/GraphQL/UpdateFileTypeTest.php + + - + rawMessage: 'PHPDoc tag @var with type App\Models\BuildUpdate is not subtype of type App\Models\BuildUpdate&object{pivot: Illuminate\Database\Eloquent\Relations\Pivot}.' + identifier: varTag.type + count: 1 + path: tests/Feature/GraphQL/UpdateTypeTest.php + - rawMessage: Cannot access offset 0 on mixed. identifier: offsetAccess.nonOffsetAccessible diff --git a/tests/Feature/GraphQL/UpdateFileTypeTest.php b/tests/Feature/GraphQL/UpdateFileTypeTest.php new file mode 100644 index 0000000000..498525100f --- /dev/null +++ b/tests/Feature/GraphQL/UpdateFileTypeTest.php @@ -0,0 +1,136 @@ +project = $this->makePublicProject(); + } + + protected function tearDown(): void + { + $this->project->delete(); + + foreach ($this->updates as $update) { + $update->delete(); + } + + parent::tearDown(); + } + + /** + * A basic test to ensure that each of the fields works + */ + public function testBasicFieldAccess(): void + { + /** @var Build $build */ + $build = $this->project->builds()->create([ + 'name' => 'build1', + 'uuid' => Str::uuid()->toString(), + ]); + + /** @var BuildUpdate $update */ + $update = $build->updates()->create([ + 'command' => Str::uuid()->toString(), + 'type' => 'GIT', + 'status' => Str::uuid()->toString(), + 'revision' => Str::uuid()->toString(), + 'priorrevision' => Str::uuid()->toString(), + 'path' => Str::uuid()->toString(), + ]); + + /** @var BuildUpdateFile $updateFile */ + $updateFile = $update->updateFiles()->create([ + 'filename' => Str::uuid()->toString(), + 'author' => Str::uuid()->toString(), + 'email' => Str::uuid()->toString(), + 'committer' => Str::uuid()->toString(), + 'committeremail' => Str::uuid()->toString(), + 'log' => Str::uuid()->toString(), + 'revision' => Str::uuid()->toString(), + 'priorrevision' => Str::uuid()->toString(), + 'status' => 'UPDATED', + ]); + + $this->graphQL(' + query build($id: ID) { + build(id: $id) { + updates { + edges { + node { + updateFiles { + edges { + node { + fileName + authorName + authorEmail + committerName + committerEmail + log + revision + priorRevision + status + } + } + } + } + } + } + } + } + ', [ + 'id' => $build->id, + ])->assertExactJson([ + 'data' => [ + 'build' => [ + 'updates' => [ + 'edges' => [ + [ + 'node' => [ + 'updateFiles' => [ + 'edges' => [ + [ + 'node' => [ + 'fileName' => $updateFile->filename, + 'authorName' => $updateFile->author, + 'authorEmail' => $updateFile->email, + 'committerName' => $updateFile->committer, + 'committerEmail' => $updateFile->committeremail, + 'log' => $updateFile->log, + 'revision' => $updateFile->revision, + 'priorRevision' => $updateFile->priorrevision, + 'status' => $updateFile->status, + ], + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]); + } +} diff --git a/tests/Feature/GraphQL/UpdateTypeTest.php b/tests/Feature/GraphQL/UpdateTypeTest.php new file mode 100644 index 0000000000..566c50ca8f --- /dev/null +++ b/tests/Feature/GraphQL/UpdateTypeTest.php @@ -0,0 +1,104 @@ +project = $this->makePublicProject(); + } + + protected function tearDown(): void + { + $this->project->delete(); + + foreach ($this->updates as $update) { + $update->delete(); + } + + parent::tearDown(); + } + + /** + * A basic test to ensure that each of the fields works + */ + public function testBasicFieldAccess(): void + { + /** @var Build $build */ + $build = $this->project->builds()->create([ + 'name' => 'build1', + 'uuid' => Str::uuid()->toString(), + ]); + + /** @var BuildUpdate $update */ + $update = $build->updates()->create([ + 'command' => Str::uuid()->toString(), + 'type' => 'GIT', + 'status' => Str::uuid()->toString(), + 'revision' => Str::uuid()->toString(), + 'priorrevision' => Str::uuid()->toString(), + 'path' => Str::uuid()->toString(), + ]); + + $this->graphQL(' + query build($id: ID) { + build(id: $id) { + updates { + edges { + node { + id + command + type + status + revision + priorRevision + path + } + } + } + } + } + ', [ + 'id' => $build->id, + ])->assertExactJson([ + 'data' => [ + 'build' => [ + 'updates' => [ + 'edges' => [ + [ + 'node' => [ + 'id' => (string) $update->id, + 'command' => $update->command, + 'type' => $update->type, + 'status' => $update->status, + 'revision' => $update->revision, + 'priorRevision' => $update->priorrevision, + 'path' => $update->path, + ], + ], + ], + ], + ], + ], + ]); + } +}