json('projects')); } private function collectResponseUsers(TestResponse $response): Collection { return $this->collectResponseProjects($response)->pluck('users')->collapse(); } protected function setUp(): void { parent::setUp(); $this->admin = UserFactory::asAdmin()->withTokens()->create(); $this->intervals = IntervalFactory::withRandomRelations()->createMany(self::INTERVALS_AMOUNT); $this->intervals->each(function (TimeInterval $interval) { ScreenshotFactory::fake()->forInterval($interval)->create(); $this->uids[] = $interval->user_id; $this->pids[] = $interval->task->project->id; $this->duration += Carbon::parse($interval->end_at)->diffInSeconds($interval->start_at); }); $this->requestData = [ 'start_at' => $this->intervals->min('start_at'), 'end_at' => $this->intervals->max('end_at')->addMinute(), 'uids' => $this->uids, 'pids' => $this->pids ]; } public function test_list(): void { $response = $this->actingAs($this->admin)->postJson(self::URI, $this->requestData); $response->assertOk(); $users = $this->collectResponseUsers($response); $this->assertEquals($this->duration, $users->sum('tasks_time')); $this->assertEquals(count($this->uids), $users->count()); //TODO change later } public function test_unauthorized(): void { $response = $this->getJson(self::URI); $response->assertUnauthorized(); } public function test_without_params(): void { $response = $this->actingAs($this->admin)->getJson(self::URI); $response->assertValidationError(); } }