-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add preferred backup destination option
- Loading branch information
1 parent
ec57435
commit 94e7246
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
database/migrations/2024_06_16_071258_add_preferred_backup_destination_to_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use App\Models\BackupDestination; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->foreignIdFor(BackupDestination::class, 'preferred_backup_destination_id') | ||
->nullable() | ||
->constrained('backup_destinations') | ||
->nullOnDelete(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
use App\Models\BackupDestination; | ||
use App\Models\User; | ||
use Livewire\Volt\Volt; | ||
|
||
|
@@ -20,13 +21,17 @@ | |
test('profile information can be updated', function () { | ||
Toaster::fake(); | ||
$user = User::factory()->create(); | ||
$backupDestination = BackupDestination::factory()->create([ | ||
'user_id' => $user->id, | ||
]); | ||
|
||
$this->actingAs($user); | ||
|
||
$component = Volt::test('profile.update-profile-information-form') | ||
->set('name', 'Test User') | ||
->set('email', '[email protected]') | ||
->set('timezone', 'America/New_York') | ||
->set('preferred_backup_destination_id', $backupDestination->id) | ||
->call('updateProfileInformation'); | ||
|
||
$component | ||
|
@@ -38,6 +43,7 @@ | |
$this->assertSame('Test User', $user->name); | ||
$this->assertSame('[email protected]', $user->email); | ||
$this->assertSame('America/New_York', $user->timezone); | ||
$this->assertSame($backupDestination->id, $user->preferred_backup_destination_id); | ||
$this->assertNull($user->email_verified_at); | ||
|
||
Toaster::assertDispatched((__('Profile details saved.'))); | ||
|
@@ -109,3 +115,68 @@ | |
->assertHasErrors('timezone') | ||
->assertNoRedirect(); | ||
}); | ||
|
||
test('the preferred backup destination can be nullable - not set', function () { | ||
|
||
$user = User::factory()->create(); | ||
|
||
$this->actingAs($user); | ||
|
||
$component = Volt::test('profile.update-profile-information-form') | ||
->set('name', 'Test User') | ||
->set('email', '[email protected]') | ||
->set('timezone', 'America/New_York') | ||
->call('updateProfileInformation'); | ||
|
||
$component | ||
->assertHasNoErrors() | ||
->assertNoRedirect(); | ||
|
||
$user->refresh(); | ||
|
||
$this->assertNull($user->preferred_backup_destination_id); | ||
}); | ||
|
||
test('the preferred backup destination must exist', function () { | ||
|
||
$user = User::factory()->create(); | ||
|
||
$this->actingAs($user); | ||
|
||
$component = Volt::test('profile.update-profile-information-form') | ||
->set('name', 'Test User') | ||
->set('email', '[email protected]') | ||
->set('timezone', 'America/New_York') | ||
->set('preferred_backup_destination_id', 999) | ||
->call('updateProfileInformation'); | ||
|
||
$component | ||
->assertHasErrors('preferred_backup_destination_id') | ||
->assertNoRedirect(); | ||
|
||
$this->assertNull($user->refresh()->preferred_backup_destination_id); | ||
}); | ||
|
||
test('the preferred backup destination must belong to the user', function () { | ||
|
||
$user = User::factory()->create(); | ||
$otherUser = User::factory()->create(); | ||
$backupDestination = BackupDestination::factory()->create([ | ||
'user_id' => $otherUser->id, | ||
]); | ||
|
||
$this->actingAs($user); | ||
|
||
$component = Volt::test('profile.update-profile-information-form') | ||
->set('name', 'Test User') | ||
->set('email', '[email protected]') | ||
->set('timezone', 'America/New_York') | ||
->set('preferred_backup_destination_id', $backupDestination->id) | ||
->call('updateProfileInformation'); | ||
|
||
$component | ||
->assertHasErrors('preferred_backup_destination_id') | ||
->assertNoRedirect(); | ||
|
||
$this->assertNull($user->refresh()->preferred_backup_destination_id); | ||
}); |