]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/UsersApiTest.php
respective book and chapter structure added.
[bookstack] / tests / Api / UsersApiTest.php
index 6af9c2a7a53b8f7ac453c50c2098d4258a1355c3..a0c67d0d281f73612d2f2f9ada724fed833c1859 100644 (file)
@@ -2,9 +2,11 @@
 
 namespace Tests\Api;
 
+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;
@@ -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();
@@ -117,7 +140,24 @@ class UsersApiTest extends TestCase
         $resp->assertStatus(200);
         /** @var User $user */
         $user = User::query()->where('email', '=', '[email protected]')->first();
-        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',
+            'email'       => '[email protected]',
+            'send_invite' => '1', // Submissions via x-www-form-urlencoded/form-data may use 1 instead of boolean
+        ]);
+
+        $resp->assertStatus(200);
+        /** @var User $user */
+        $user = User::query()->where('email', '=', '[email protected]')->first();
+        Notification::assertSentTo($user, UserInviteNotification::class);
     }
 
     public function test_create_name_and_email_validation()