admin = UserFactory::asAdmin()->withTokens()->create(); $this->task = TaskFactory::forUser($this->admin)->create(); $this->intervals = collect([ IntervalFactory::forTask($this->task)->create(), IntervalFactory::forTask($this->task)->create(), IntervalFactory::forTask($this->task)->create(), ]); $this->requestData = [ 'start_at' => $this->intervals->min('start_at'), 'end_at' => $this->intervals->max('end_at')->addMinute(), 'uid' => $this->intervals->first()->user->id ]; $this->duration = $this->intervals->sum( fn ($interval) => Carbon::parse($interval->end_at)->diffInSeconds($interval->start_at) ); } public function test_list_task(): void { $response = $this->actingAs($this->admin)->postJson(self::URI . '/' . $this->task->id, $this->requestData); $response->assertOk(); $response->assertJsonFragment(['duration' => (string)$this->duration]); } public function test_unauthorized(): void { $response = $this->getJson(self::URI . '/' . $this->task->id); $response->assertUnauthorized(); } public function test_without_params(): void { $response = $this->actingAs($this->admin)->getJson(self::URI . '/' . $this->task->id); $response->assertValidationError(); } }