Test 2 - get data

This commit is contained in:
PovilasKorop
2021-11-16 07:57:23 +02:00
parent 37db8803e2
commit 065d5dc4fd
5 changed files with 75 additions and 0 deletions
+24
View File
@@ -4,6 +4,7 @@ namespace Tests\Feature;
use App\Models\Morningnews;
use App\Models\News;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -20,4 +21,27 @@ class EloquentTest extends TestCase
$this->assertDatabaseHas('morning_news', $article);
}
// TASK: Write Eloquent query to return the newest 3 verified users
public function test_users_get()
{
$user1 = User::factory()->create(['created_at' => now()->subMinutes(5)]);
$user2 = User::factory()->create(['created_at' => now()->subMinutes(4)]);
$user3 = User::factory()->create(['created_at' => now()->subMinutes(3), 'email_verified_at' => NULL]);
$user4 = User::factory()->create(['created_at' => now()->subMinutes(2)]);
$user5 = User::factory()->create(['created_at' => now()->subMinute()]);
$response = $this->get('users');
// This one should be filtered by "email_verified_at is not null"
$response->assertDontSee($user3->name);
// This one should be filtered out by "limit 3"
$response->assertDontSee($user1->name);
// Do we have the correct order?
$response->assertSee('1. ' . $user5->name);
$response->assertSee('2. ' . $user4->name);
$response->assertSee('3. ' . $user2->name); // not $user3
}
}