namespace Tests\Api;
-use BookStack\Actions\ActivityType;
-use BookStack\Auth\Role;
-use BookStack\Auth\User;
+use BookStack\Access\Notifications\UserInviteNotification;
+use BookStack\Activity\ActivityType;
+use BookStack\Activity\Models\Activity as ActivityModel;
use BookStack\Entities\Models\Entity;
-use BookStack\Notifications\UserInvite;
+use BookStack\Facades\Activity;
+use BookStack\Users\Models\Role;
+use BookStack\Users\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
{
use TestsApi;
- protected $baseEndpoint = '/api/users';
+ protected string $baseEndpoint = '/api/users';
- protected $endpointMap = [
+ protected array $endpointMap = [
['get', '/api/users'],
['post', '/api/users'],
['get', '/api/users/1'],
}
}
- public function test_index_endpoint_returns_expected_shelf()
+ public function test_index_endpoint_returns_expected_user()
{
$this->actingAsApiAdmin();
/** @var User $firstUser */
]]);
}
+ public function test_index_endpoint_has_correct_created_and_last_activity_dates()
+ {
+ $user = $this->users->editor();
+ $user->created_at = now()->subYear();
+ $user->save();
+
+ $this->actingAs($user);
+ Activity::add(ActivityType::AUTH_LOGIN, 'test login activity');
+ /** @var ActivityModel $activity */
+ $activity = ActivityModel::query()->where('user_id', '=', $user->id)->latest()->first();
+
+ $resp = $this->asAdmin()->getJson($this->baseEndpoint . '?filter[id]=3');
+ $resp->assertJson(['data' => [
+ [
+ 'id' => $user->id,
+ 'created_at' => $user->created_at->toJSON(),
+ 'last_activity_at' => $activity->created_at->toJson(),
+ ],
+ ]]);
+ }
+
public function test_create_endpoint()
{
$this->actingAsApiAdmin();
$resp->assertStatus(200);
/** @var User $user */
- Notification::assertSentTo($user, UserInvite::class);
+ Notification::assertSentTo($user, UserInviteNotification::class);
+ }
+
+ public function test_create_with_send_invite_works_with_value_of_1()
+ {
+ $this->actingAsApiAdmin();
+ Notification::fake();
+
+ $resp = $this->postJson($this->baseEndpoint, [
+ 'name' => 'Benny Boris',
+ 'send_invite' => '1', // Submissions via x-www-form-urlencoded/form-data may use 1 instead of boolean
+ ]);
+
+ $resp->assertStatus(200);
+ /** @var User $user */
+ Notification::assertSentTo($user, UserInviteNotification::class);
}
public function test_create_name_and_email_validation()
{
$this->actingAsApiAdmin();
/** @var User $user */
- $user = $this->getAdmin();
+ $user = $this->users->admin();
$roles = Role::query()->pluck('id');
$resp = $this->putJson($this->baseEndpoint . "/{$user->id}", [
'name' => 'My updated user',
{
$this->actingAsApiAdmin();
/** @var User $user */
- $user = $this->getAdmin();
+ $user = $this->users->admin();
$roleCount = $user->roles()->count();
$resp = $this->putJson($this->baseEndpoint . "/{$user->id}", []);
{
$this->actingAsApiAdmin();
/** @var User $user */
- $user = User::query()->where('id', '!=', $this->getAdmin()->id)
+ $user = User::query()->where('id', '!=', $this->users->admin()->id)
->whereNull('system_name')
->first();
{
$this->actingAsApiAdmin();
/** @var User $user */
- $user = User::query()->where('id', '!=', $this->getAdmin()->id)
+ $user = User::query()->where('id', '!=', $this->users->admin()->id)
->whereNull('system_name')
->first();
$entityChain = $this->entities->createChainBelongingToUser($user);