64 lines
2.4 KiB
PHP
64 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Permission;
|
|
|
|
use App\Invoice\InvoiceSettings;
|
|
use App\User;
|
|
use App\User\Mail\WelcomeMail;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Tests\RequestFactories\UserRequestFactory;
|
|
use Tests\TestCase;
|
|
|
|
class UserStoreTest extends TestCase
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
public function testItStoresUser(): void
|
|
{
|
|
Mail::fake();
|
|
$this->login()->loginNami();
|
|
|
|
$this->postJson(route('user.store'), UserRequestFactory::new()->name('Max Muster')->email('max@muster.de')->create())
|
|
->assertOk();
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
'email' => 'max@muster.de',
|
|
'firstname' => 'Max',
|
|
'lastname' => 'Muster',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('password_resets', ['email' => 'max@muster.de']);
|
|
Mail::assertQueued(
|
|
WelcomeMail::class,
|
|
fn ($mail) => Hash::check($mail->token, DB::table('password_resets')->where('email', 'max@muster.de')->first()->token)
|
|
);
|
|
}
|
|
|
|
public function testItNeedsNameAndEmail(): void
|
|
{
|
|
Mail::fake();
|
|
$this->login()->loginNami();
|
|
|
|
User::factory()->email('jane@doe.de')->create();
|
|
$this->postJson(route('user.store'), UserRequestFactory::new()->name('')->email('max@muster.de')->create())->assertJsonValidationErrors('firstname');
|
|
$this->postJson(route('user.store'), UserRequestFactory::new()->name('Max Muster')->email('maxusterde')->create())->assertJsonValidationErrors('email');
|
|
$this->postJson(route('user.store'), UserRequestFactory::new()->name('Max Muster')->email('')->create())->assertJsonValidationErrors('email');
|
|
$this->postJson(route('user.store'), UserRequestFactory::new()->email('jane@doe.de')->create())->assertJsonValidationErrors('email');
|
|
}
|
|
|
|
public function testWelcomeMailHasPasswordResetLink(): void
|
|
{
|
|
app(InvoiceSettings::class)->fill(['from_long' => 'Stamm BiPi'])->save();
|
|
(new WelcomeMail(User::factory()->email('max@muster.de')->name('Max Muster')->create(), 'RESETToken'))
|
|
->assertSeeInHtml('Hallo Max Muster')
|
|
->assertSeeInHtml(url(''))
|
|
->assertSeeInHtml('Stamm BiPi')
|
|
->assertSeeInHtml('max@muster.de')
|
|
->assertSeeInHtml(route('password.reset', ['token' => 'RESETToken', 'email' => 'max@muster.de']));
|
|
}
|
|
}
|