70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Domains\Settings\ManageUserPreferences\Services;
|
|
|
|
use App\Domains\Settings\ManageUserPreferences\Services\StoreDistanceFormatPreference;
|
|
use App\Models\Account;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Tests\TestCase;
|
|
|
|
class StoreDistanceFormatPreferenceTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
/** @test */
|
|
public function it_stores_the_distance_format_preference(): void
|
|
{
|
|
$ross = $this->createUser();
|
|
$this->executeService($ross, $ross->account);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_fails_if_wrong_parameters_are_given(): void
|
|
{
|
|
$request = [
|
|
'title' => 'Ross',
|
|
];
|
|
|
|
$this->expectException(ValidationException::class);
|
|
(new StoreDistanceFormatPreference())->execute($request);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_fails_if_user_doesnt_belong_to_account(): void
|
|
{
|
|
$this->expectException(ModelNotFoundException::class);
|
|
|
|
$ross = $this->createAdministrator();
|
|
$account = $this->createAccount();
|
|
$this->executeService($ross, $account);
|
|
}
|
|
|
|
private function executeService(User $author, Account $account): void
|
|
{
|
|
Queue::fake();
|
|
|
|
$request = [
|
|
'account_id' => $account->id,
|
|
'author_id' => $author->id,
|
|
'distance_format' => 'km',
|
|
];
|
|
|
|
$user = (new StoreDistanceFormatPreference())->execute($request);
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
'id' => $user->id,
|
|
'account_id' => $account->id,
|
|
'distance_format' => 'km',
|
|
]);
|
|
|
|
$this->assertInstanceOf(
|
|
User::class,
|
|
$user
|
|
);
|
|
}
|
|
}
|