diff --git a/tests/Feature/JsonApi/GoalApiTest.php b/tests/Feature/JsonApi/GoalApiTest.php index 3ea6b82..ba870e6 100644 --- a/tests/Feature/JsonApi/GoalApiTest.php +++ b/tests/Feature/JsonApi/GoalApiTest.php @@ -32,6 +32,8 @@ class GoalApiTest extends JsonApiTestCase * @inheritdoc */ protected function createInstances(int $count = 1): Collection { + // Remove random goals for accurate count tests. + $this->user->goals()->delete(); return $this->factory()->count($count)->for($this->user)->create(); } diff --git a/tests/Feature/JsonApi/JournalEntryApiTest.php b/tests/Feature/JsonApi/JournalEntryApiTest.php index ea357b4..8d11783 100644 --- a/tests/Feature/JsonApi/JournalEntryApiTest.php +++ b/tests/Feature/JsonApi/JournalEntryApiTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\JsonApi; use App\Models\JournalEntry; use Database\Factories\JournalEntryFactory; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\Feature\JsonApi\Traits\BelongsToUser; @@ -27,6 +28,15 @@ class JournalEntryApiTest extends JsonApiTestCase return 'journal-entries'; } + /** + * @inheritdoc + */ + protected function createInstances(int $count = 1): Collection { + // Remove random entries for accurate count tests. + $this->user->journalEntries()->delete(); + return $this->factory()->count($count)->for($this->user)->create(); + } + public function testCanGetRelatedFoods(): void { $record = $this->factory()->hasFoods(2)->create(); $this->getRelatedData($record, 'foods'); diff --git a/tests/LogsIn.php b/tests/LogsIn.php index df7146d..5023d4f 100644 --- a/tests/LogsIn.php +++ b/tests/LogsIn.php @@ -13,7 +13,10 @@ trait LogsIn */ public function loginUser(): void { - $this->user = User::factory()->create(); + $this->user = User::factory() + ->hasGoals(2) + ->hasJournalEntries(5) + ->create(); $this->post('/login', [ 'username' => $this->user->username, 'password' => 'password',