Give test user some goals and journal entries

This commit is contained in:
Christopher C. Wells 2021-04-06 14:42:42 -07:00
parent 69701ee4d8
commit f56fab3fd0
3 changed files with 16 additions and 1 deletions

View File

@ -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();
}

View File

@ -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');

View File

@ -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',