pull/3/head
Hasin Hayder 3 years ago
parent 0890cb2e45
commit 8191b92a15

@ -2,13 +2,15 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Role;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Testing\Fluent\AssertableJson; use Illuminate\Testing\Fluent\AssertableJson;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Hash;
class NewUserTest extends TestCase { class UserTest extends TestCase {
/** /**
* A basic feature test example. * A basic feature test example.
* *
@ -177,4 +179,38 @@ class NewUserTest extends TestCase {
->where('message', 'user deleted') ->where('message', 'user deleted')
); );
} }
public function test_delete_admin_user_if_multiple_admins_are_present() {
$newAdminUser = User::create([
'name'=>'Test Admin',
'password'=>Hash::make('abcd'),
'email'=>'testadmin@test.com'
]);
$adminRole = Role::find(1);
$newAdminUser->roles()->attach($adminRole);
$response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project',
'password' => 'hydra'
]);
$data = json_decode($response->getContent());
$this->token = $data->token;
$this->user_id = $data->id;
$target = User::where('email', 'testadmin@test.com')->first();
$response = $this->withHeader('Authorization', 'Bearer ' . $this->token)
->delete("/api/users/{$target->id}");
$response
->assertJson(
fn (AssertableJson $json) =>
$json->where('error', 0)
->where('message', 'user deleted')
);
}
} }
Loading…
Cancel
Save