]> BookStack Code Mirror - bookstack/blobdiff - tests/Actions/WebhookManagementTest.php
Fixed OIDC Logout
[bookstack] / tests / Actions / WebhookManagementTest.php
index 8abf06fc5edb1347e0a852cd97224e18dbba7d2e..05475b6997c01bf371082eb9769a2cad72445401 100644 (file)
@@ -2,24 +2,23 @@
 
 namespace Tests\Actions;
 
-use BookStack\Actions\ActivityType;
-use BookStack\Actions\Webhook;
+use BookStack\Activity\ActivityType;
+use BookStack\Activity\Models\Webhook;
 use Tests\TestCase;
 
 class WebhookManagementTest extends TestCase
 {
-
     public function test_index_view()
     {
         $webhook = $this->newWebhook([
-            'name' => 'My awesome webhook',
+            'name'     => 'My awesome webhook',
             'endpoint' => 'https://example.com/donkey/webhook',
         ], ['all']);
 
         $resp = $this->asAdmin()->get('/settings/webhooks');
         $resp->assertOk();
-        $resp->assertElementContains('a[href$="/settings/webhooks/create"]', 'Create New Webhook');
-        $resp->assertElementExists('a[href="' . $webhook->getUrl() . '"]', $webhook->name);
+        $this->withHtml($resp)->assertElementContains('a[href$="/settings/webhooks/create"]', 'Create New Webhook');
+        $this->withHtml($resp)->assertElementContains('a[href="' . $webhook->getUrl() . '"]', $webhook->name);
         $resp->assertSee($webhook->endpoint);
         $resp->assertSee('All system events');
         $resp->assertSee('Active');
@@ -30,16 +29,17 @@ class WebhookManagementTest extends TestCase
         $resp = $this->asAdmin()->get('/settings/webhooks/create');
         $resp->assertOk();
         $resp->assertSee('Create New Webhook');
-        $resp->assertElementContains('form[action$="/settings/webhooks/create"] button', 'Save Webhook');
+        $this->withHtml($resp)->assertElementContains('form[action$="/settings/webhooks/create"] button', 'Save Webhook');
     }
 
     public function test_store()
     {
         $resp = $this->asAdmin()->post('/settings/webhooks/create', [
-            'name' => 'My first webhook',
+            'name'     => 'My first webhook',
             'endpoint' => 'https://example.com/webhook',
-            'events' => ['all'],
-            'active' => 'true'
+            'events'   => ['all'],
+            'active'   => 'true',
+            'timeout'  => 4,
         ]);
 
         $resp->assertRedirect('/settings/webhooks');
@@ -49,16 +49,17 @@ class WebhookManagementTest extends TestCase
         $resp->assertSee('Webhook successfully created');
 
         $this->assertDatabaseHas('webhooks', [
-            'name' => 'My first webhook',
+            'name'     => 'My first webhook',
             'endpoint' => 'https://example.com/webhook',
-            'active' => true,
+            'active'   => true,
+            'timeout'  => 4,
         ]);
 
         /** @var Webhook $webhook */
         $webhook = Webhook::query()->where('name', '=', 'My first webhook')->first();
         $this->assertDatabaseHas('webhook_tracked_events', [
             'webhook_id' => $webhook->id,
-            'event' => 'all',
+            'event'      => 'all',
         ]);
     }
 
@@ -69,9 +70,9 @@ class WebhookManagementTest extends TestCase
         $resp = $this->asAdmin()->get('/settings/webhooks/' . $webhook->id);
         $resp->assertOk();
         $resp->assertSee('Edit Webhook');
-        $resp->assertElementContains('form[action="' . $webhook->getUrl() . '"] button', 'Save Webhook');
-        $resp->assertElementContains('a[href="' . $webhook->getUrl('/delete') . '"]', 'Delete Webhook');
-        $resp->assertElementExists('input[type="checkbox"][value="all"][name="events[]"]');
+        $this->withHtml($resp)->assertElementContains('form[action="' . $webhook->getUrl() . '"] button', 'Save Webhook');
+        $this->withHtml($resp)->assertElementContains('a[href="' . $webhook->getUrl('/delete') . '"]', 'Delete Webhook');
+        $this->withHtml($resp)->assertElementExists('input[type="checkbox"][value="all"][name="events[]"]');
     }
 
     public function test_update()
@@ -79,10 +80,11 @@ class WebhookManagementTest extends TestCase
         $webhook = $this->newWebhook();
 
         $resp = $this->asAdmin()->put('/settings/webhooks/' . $webhook->id, [
-            'name' => 'My updated webhook',
+            'name'     => 'My updated webhook',
             'endpoint' => 'https://example.com/updated-webhook',
-            'events' => [ActivityType::PAGE_CREATE, ActivityType::PAGE_UPDATE],
-            'active' => 'true'
+            'events'   => [ActivityType::PAGE_CREATE, ActivityType::PAGE_UPDATE],
+            'active'   => 'true',
+            'timeout'  => 5,
         ]);
         $resp->assertRedirect('/settings/webhooks');
 
@@ -90,10 +92,11 @@ class WebhookManagementTest extends TestCase
         $resp->assertSee('Webhook successfully updated');
 
         $this->assertDatabaseHas('webhooks', [
-            'id' => $webhook->id,
-            'name' => 'My updated webhook',
+            'id'       => $webhook->id,
+            'name'     => 'My updated webhook',
             'endpoint' => 'https://example.com/updated-webhook',
-            'active' => true,
+            'active'   => true,
+            'timeout'  => 5,
         ]);
 
         $trackedEvents = $webhook->trackedEvents()->get();
@@ -111,7 +114,7 @@ class WebhookManagementTest extends TestCase
         $resp->assertOk();
         $resp->assertSee('Delete Webhook');
         $resp->assertSee('This will fully delete this webhook, with the name \'Webhook to delete\', from the system.');
-        $resp->assertElementContains('form[action$="/settings/webhooks/' . $webhook->id . '"]', 'Delete');
+        $this->withHtml($resp)->assertElementContains('form[action$="/settings/webhooks/' . $webhook->id . '"]', 'Delete');
     }
 
     public function test_destroy()
@@ -132,7 +135,7 @@ class WebhookManagementTest extends TestCase
 
     public function test_settings_manage_permission_required_for_webhook_routes()
     {
-        $editor = $this->getEditor();
+        $editor = $this->users->editor();
         $this->actingAs($editor);
 
         $routes = [
@@ -150,7 +153,7 @@ class WebhookManagementTest extends TestCase
             $this->assertPermissionError($resp);
         }
 
-        $this->giveUserPermissions($editor, ['settings-manage']);
+        $this->permissions->grantUserRolePermissions($editor, ['settings-manage']);
 
         foreach ($routes as [$method, $endpoint]) {
             $resp = $this->call($method, $endpoint);
@@ -169,5 +172,4 @@ class WebhookManagementTest extends TestCase
 
         return $webhook;
     }
-
-}
\ No newline at end of file
+}