parent
ec775aec02
commit
00b5dd7852
4 changed files with 27 additions and 2 deletions
|
@ -19,6 +19,8 @@ use Illuminate\Support\Str;
|
|||
* @property string $entity_type
|
||||
* @property int $entity_id
|
||||
* @property int $user_id
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
class Activity extends Model
|
||||
{
|
||||
|
|
|
@ -73,7 +73,7 @@ class UserApiController extends ApiController
|
|||
*/
|
||||
public function list()
|
||||
{
|
||||
$users = User::query()->select(['*'])
|
||||
$users = User::query()->select(['users.*'])
|
||||
->scopes('withLastActivityAt')
|
||||
->with(['avatar']);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"id": 2,
|
||||
"name": "Benny",
|
||||
"email": "benny@example.com",
|
||||
"created_at": "2022-01-31T20:39:24.000000Z",
|
||||
"created_at": "2020-01-15T04:43:11.000000Z",
|
||||
"updated_at": "2021-11-18T17:10:58.000000Z",
|
||||
"external_auth_id": "",
|
||||
"slug": "benny",
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
namespace Tests\Api;
|
||||
|
||||
use BookStack\Activity\ActivityType;
|
||||
use BookStack\Activity\Models\Activity as ActivityModel;
|
||||
use BookStack\Entities\Models\Entity;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Notifications\UserInvite;
|
||||
use BookStack\Users\Models\Role;
|
||||
use BookStack\Users\Models\User;
|
||||
|
@ -67,6 +69,27 @@ class UsersApiTest extends TestCase
|
|||
]]);
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue