Skip to content

Commit

Permalink
Fix wizard store method, and add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Jun 4, 2024
1 parent 15446f2 commit f19089f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/Auth/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ public function index(): View

public function store(): RedirectResponse
{
$valid = request()->validate(request(), [
$valid = request()->validate([
'os' => ['required', 'string', Rule::in(OperatingSystem::ALL)],
'track' => ['required', 'int', 'exists:tracks,id'],
'locale' => ['required', 'string', Rule::in((new Locale)->slugs())],
], [], [
'os' => 'OS',
]);

auth()->user()->update(['track_id' => $valid['track']]);
Expand Down
2 changes: 1 addition & 1 deletion database/seeders/ContentSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ContentSeeder extends Seeder
public function run(): void
{
User::factory()->create([
'email' => 'matt@tighten.co',
'email' => 'testuser@tighten.co',
'password' => bcrypt('password'),
'role' => 'admin',
]);
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/WizardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Tests\Feature;

use App\Facades\Preferences;
use App\Models\Track;
use App\Models\User;
use App\OperatingSystem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

Expand All @@ -19,4 +22,23 @@ public function it_loads(): void

$response->assertStatus(200);
}

/** @test */
public function it_can_be_submitted(): void
{
$this->be($user = User::factory()->create());
$response = $this->post(route('wizard.store', ['locale' => 'en']),
[
'os' => OperatingSystem::MACOS,
'track' => $track_id = Track::factory()->create()->id,
'locale' => 'en',
]
);

$response->assertStatus(302);
$user->refresh();
$this->assertEquals($track_id, $user->track_id);
$this->assertEquals(OperatingSystem::MACOS, Preferences::get('operating-system'));
$this->assertEquals('en', Preferences::get('locale'));
}
}

0 comments on commit f19089f

Please sign in to comment.