mirror of
https://github.com/snipe/snipe-it.git
synced 2026-04-29 03:05:25 +00:00
@ -5,6 +5,8 @@ namespace Tests\Feature\Users\Api;
|
||||
use App\Models\Company;
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use App\Notifications\WelcomeNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -58,21 +60,61 @@ class CreateUserTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
public function testCanStoreUser()
|
||||
public function testCanCreateUser()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->createUsers()->create())
|
||||
->postJson(route('api.users.store'), [
|
||||
'first_name' => 'Darth',
|
||||
'username' => 'darthvader',
|
||||
'password' => 'darth_password',
|
||||
'password_confirmation' => 'darth_password',
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'password' => 'testpassword1235!!',
|
||||
'password_confirmation' => 'testpassword1235!!',
|
||||
'send_welcome' => '1',
|
||||
'activated' => '1',
|
||||
'notes' => 'Test Note',
|
||||
])
|
||||
->assertStatusMessageIs('success')
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'first_name' => 'Darth',
|
||||
'username' => 'darthvader',
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'activated' => '1',
|
||||
'notes' => 'Test Note',
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCanCreateAndNotifyUser()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->actingAsForApi(User::factory()->createUsers()->create())
|
||||
->postJson(route('api.users.store'), [
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'password' => 'testpassword1235!!',
|
||||
'password_confirmation' => 'testpassword1235!!',
|
||||
'send_welcome' => '1',
|
||||
'activated' => '1',
|
||||
'email' => 'foo@example.org',
|
||||
'notes' => 'Test Note',
|
||||
])
|
||||
->assertStatusMessageIs('success')
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'activated' => '1',
|
||||
'email' => 'foo@example.org',
|
||||
'notes' => 'Test Note',
|
||||
]);
|
||||
|
||||
$user = User::where('username', 'testuser')->first();
|
||||
Notification::assertSentTo($user, WelcomeNotification::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
namespace Tests\Feature\Users\Ui;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\WelcomeNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateUserTest extends TestCase
|
||||
@ -25,6 +27,39 @@ class CreateUserTest extends TestCase
|
||||
|
||||
public function testCanCreateUser()
|
||||
{
|
||||
$response = $this->actingAs(User::factory()->createUsers()->viewUsers()->create())
|
||||
->from(route('users.index'))
|
||||
->post(route('users.store'), [
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'password' => 'testpassword1235!!',
|
||||
'password_confirmation' => 'testpassword1235!!',
|
||||
'send_welcome' => '1',
|
||||
'activated' => '1',
|
||||
'notes' => 'Test Note',
|
||||
])
|
||||
->assertSessionHasNoErrors()
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('users.index'));
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'activated' => '1',
|
||||
'notes' => 'Test Note',
|
||||
|
||||
]);
|
||||
|
||||
$this->followRedirects($response)->assertSee('Success');
|
||||
|
||||
}
|
||||
|
||||
public function testCanCreateAndNotifyUser()
|
||||
{
|
||||
|
||||
Notification::fake();
|
||||
|
||||
$response = $this->actingAs(User::factory()->createUsers()->viewUsers()->create())
|
||||
->from(route('users.index'))
|
||||
@ -33,11 +68,27 @@ class CreateUserTest extends TestCase
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'password' => 'testpassword1235!!',
|
||||
//'notes' => 'Test Note',
|
||||
'password_confirmation' => 'testpassword1235!!',
|
||||
'send_welcome' => '1',
|
||||
'activated' => '1',
|
||||
'email' => 'foo@example.org',
|
||||
'notes' => 'Test Note',
|
||||
])
|
||||
->assertSessionHasNoErrors()
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('users.index'));
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'first_name' => 'Test First Name',
|
||||
'last_name' => 'Test Last Name',
|
||||
'username' => 'testuser',
|
||||
'activated' => '1',
|
||||
'email' => 'foo@example.org',
|
||||
'notes' => 'Test Note',
|
||||
]);
|
||||
|
||||
$user = User::where('username', 'testuser')->first();
|
||||
Notification::assertSentTo($user, WelcomeNotification::class);
|
||||
$this->followRedirects($response)->assertSee('Success');
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user