Skip to content

Commit

Permalink
test: asserting pulling service record + medals work
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Dec 25, 2021
1 parent 83f4d0b commit f455b67
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions database/factories/ServiceRecordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Database\Factories;

use App\Models\Medal;
use App\Models\Player;
use App\Models\ServiceRecord;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand Down Expand Up @@ -53,4 +54,19 @@ public function definition(): array
'assists_callout' => $this->faker->numberBetween(0, 25),
];
}

public function withMedals(): self
{
return $this->state(function (array $attributes) {
$medals = Medal::factory()->count(2)->create();

return [
'medals' => $medals->mapWithKeys(function (Medal $medal) {
return [
$medal->id => $this->faker->numberBetween(1, 25)
];
})->toArray()
];
});
}
}
20 changes: 20 additions & 0 deletions tests/Feature/Pages/PlayerPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Tests\Feature\Pages;

use App\Models\Player;
use App\Models\ServiceRecord;
use Illuminate\Support\Facades\Http;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
Expand Down Expand Up @@ -50,6 +51,25 @@ public function testLoadingPlayerOverviewPage(string $gamertag): void
$response->assertSeeLivewire('update-player-panel');
}

public function testLoadingPlayerOverviewPageWithMedalData(): void
{
// Arrange
Http::fake();

/** @var ServiceRecord $serviceRecord */
$serviceRecord = ServiceRecord::factory()
->withMedals()
->create();

// Act
$response = $this->get('/player/' . urlencode($serviceRecord->player->gamertag) . '/overview');

// Assert
$response->assertStatus(Response::HTTP_OK);
$response->assertSeeLivewire('overview-page');
$response->assertSeeLivewire('update-player-panel');
}

/** @dataProvider gamertagDataProvider */
public function testLoadingPlayerOverviewPageAsPrivatePlayer(string $gamertag): void
{
Expand Down

0 comments on commit f455b67

Please sign in to comment.