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
2 changes: 1 addition & 1 deletion app/Http/Controllers/Task/Admin/OverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function index(Course $course, Task $task) : View
}
$finishedCount = $task->projects()->where('status', ProjectStatus::Finished)->count();
$finishedPercent = $projectCount == 0 ? 0 : $finishedCount / $projectCount * 100;
$failedCount = $task->projects()->where('status', ProjectStatus::Overdue)->count();
$failedCount = $task->projects()->claimed()->where('status', ProjectStatus::Overdue)->count();
$failedPercent = $projectCount == 0 ? 0 : $failedCount / $projectCount * 100;
$buildCount = $task->jobs()->count();
$buildsToday = $task->jobs()->whereRaw("date(pipelines.created_at) = ?", now()->toDateString())->withTrashedParents()->count();
Expand Down
21 changes: 17 additions & 4 deletions tests/Feature/Task/Controller/OverviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use App\Models\Project;
use App\Models\Task;
use App\Models\User;
use App\ProjectStatus;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\actingAs;

Expand All @@ -12,12 +13,19 @@
beforeEach(function() {
$this->task = Task::factory()->for(Course::factory())->create();

$this->professor = User::factory()->admin()->hasAttached($this->task->course)->create();
$this->student = User::factory()->hasAttached($this->task->course)->create();

Project::factory()->for($this->task)->create();
Project::factory()->finished()->for($this->task)->create();
Project::factory()->overdue()->for($this->task)->create(
[
'ownable_id' => $this->student->id,
'ownable_type' => User::class,
]
);
Project::factory()->overdue()->for($this->task)->create();

$this->professor = User::factory()->admin()->hasAttached($this->task->course)->create();
$this->student = User::factory()->hasAttached($this->task->course)->create();

});

it('should not allow access for students', function() {
Expand All @@ -35,8 +43,13 @@
$response->assertStatus(200);
$response->assertViewIs('tasks.admin.index');
$response->assertViewHas('task', $this->task);
$response->assertViewHas('projectCount', 3);
$response->assertViewHas('projectCount', 4);
$response->assertViewHas('finishedCount', 1);
expect(
$this->task->projects()
->where('status', ProjectStatus::Overdue)
->count()
)->toBe(2);
$response->assertViewHas('failedCount', 1);
});

Expand Down
Loading