first(); $role = Role::factory()->create(); $role->permissions()->attach($permission->id); $user = User::factory()->create(); $user->roles()->attach($role->id); Sanctum::actingAs($user); $response = $this->post('/auth/role/',[ "name" => "new role" ]); $response->assertStatus(201); $response->assertJson([ "data" => [ "name" => "new role" ] ]); } /** * A basic feature test example. */ public function test_with_roles_success(): void { $permission = Permission::where("code","auth.role:create")->first(); $role = Role::factory()->create(); $role->permissions()->attach($permission->id); $user = User::factory()->create(); $user->roles()->attach($role->id); $role2 = Role::factory()->create(); Sanctum::actingAs($user); $response = $this->post('/auth/role/',[ "name" => "new role", "permissions" => [$permission->id] ]); $response->assertStatus(201); $response->assertJson([ "data" => [ "name" => "new role", "permissions" => [ [ "id" => $permission->id ], ] ] ]); } }