mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
07c3fe1fce
commit
fb455be406
68
tests/Feature/Api/Users/UpdateUserApiTest.php
Normal file
68
tests/Feature/Api/Users/UpdateUserApiTest.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Api\Users;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Tests\Support\InteractsWithAuthentication;
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateUserApiTest extends TestCase
|
||||||
|
{
|
||||||
|
use InteractsWithSettings;
|
||||||
|
use InteractsWithAuthentication;
|
||||||
|
|
||||||
|
public function testApiUsersCanBeActivatedWithNumber()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => 0]);
|
||||||
|
|
||||||
|
$this->actingAsForApi($admin)
|
||||||
|
->patch(route('api.users.update', $user), [
|
||||||
|
'activated' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testApiUsersCanBeActivatedWithBooleanTrue()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => false]);
|
||||||
|
|
||||||
|
$this->actingAsForApi($admin)
|
||||||
|
->patch(route('api.users.update', $user), [
|
||||||
|
'activated' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testApiUsersCanBeDeactivatedWithNumber()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => true]);
|
||||||
|
|
||||||
|
$this->actingAsForApi($admin)
|
||||||
|
->patch(route('api.users.update', $user), [
|
||||||
|
'activated' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testApiUsersCanBeDeactivatedWithBooleanFalse()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => true]);
|
||||||
|
|
||||||
|
$this->actingAsForApi($admin)
|
||||||
|
->patch(route('api.users.update', $user), [
|
||||||
|
'activated' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,10 +10,10 @@ class UpdateUserTest extends TestCase
|
||||||
{
|
{
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testUsersCanBeActivated()
|
public function testUsersCanBeActivatedWithNumber()
|
||||||
{
|
{
|
||||||
$admin = User::factory()->superuser()->create();
|
$admin = User::factory()->superuser()->create();
|
||||||
$user = User::factory()->create(['activated' => false]);
|
$user = User::factory()->create(['activated' => 0]);
|
||||||
|
|
||||||
$this->actingAs($admin)
|
$this->actingAs($admin)
|
||||||
->put(route('users.update', $user), [
|
->put(route('users.update', $user), [
|
||||||
|
@ -25,7 +25,22 @@ class UpdateUserTest extends TestCase
|
||||||
$this->assertEquals(1, $user->refresh()->activated);
|
$this->assertEquals(1, $user->refresh()->activated);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUsersCanBeDeactivated()
|
public function testUsersCanBeActivatedWithBooleanTrue()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => false]);
|
||||||
|
|
||||||
|
$this->actingAs($admin)
|
||||||
|
->put(route('users.update', $user), [
|
||||||
|
'first_name' => $user->first_name,
|
||||||
|
'username' => $user->username,
|
||||||
|
'activated' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsersCanBeDeactivatedWithNumber()
|
||||||
{
|
{
|
||||||
$admin = User::factory()->superuser()->create();
|
$admin = User::factory()->superuser()->create();
|
||||||
$user = User::factory()->create(['activated' => true]);
|
$user = User::factory()->create(['activated' => true]);
|
||||||
|
@ -34,9 +49,22 @@ class UpdateUserTest extends TestCase
|
||||||
->put(route('users.update', $user), [
|
->put(route('users.update', $user), [
|
||||||
'first_name' => $user->first_name,
|
'first_name' => $user->first_name,
|
||||||
'username' => $user->username,
|
'username' => $user->username,
|
||||||
// checkboxes that are not checked are
|
'activated' => 0,
|
||||||
// not included in the request payload
|
]);
|
||||||
// 'activated' => 0,
|
|
||||||
|
$this->assertEquals(0, $user->refresh()->activated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsersCanBeDeactivatedWithBooleanFalse()
|
||||||
|
{
|
||||||
|
$admin = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->create(['activated' => true]);
|
||||||
|
|
||||||
|
$this->actingAs($admin)
|
||||||
|
->put(route('users.update', $user), [
|
||||||
|
'first_name' => $user->first_name,
|
||||||
|
'username' => $user->username,
|
||||||
|
'activated' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(0, $user->refresh()->activated);
|
$this->assertEquals(0, $user->refresh()->activated);
|
||||||
|
@ -50,10 +78,6 @@ class UpdateUserTest extends TestCase
|
||||||
->put(route('users.update', $admin), [
|
->put(route('users.update', $admin), [
|
||||||
'first_name' => $admin->first_name,
|
'first_name' => $admin->first_name,
|
||||||
'username' => $admin->username,
|
'username' => $admin->username,
|
||||||
// checkboxes that are disabled are not
|
|
||||||
// included in the request payload
|
|
||||||
// even if they are checked
|
|
||||||
// 'activated' => 0,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(1, $admin->refresh()->activated);
|
$this->assertEquals(1, $admin->refresh()->activated);
|
||||||
|
|
Loading…
Reference in a new issue