X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/6e18620a0a3524917adb27b0d0a3a914c1499080..refs/pull/3918/head:/tests/Actions/WebhookCallTest.php diff --git a/tests/Actions/WebhookCallTest.php b/tests/Actions/WebhookCallTest.php index 920bc2864..7ca190200 100644 --- a/tests/Actions/WebhookCallTest.php +++ b/tests/Actions/WebhookCallTest.php @@ -7,7 +7,6 @@ use BookStack\Actions\ActivityType; use BookStack\Actions\DispatchWebhookJob; use BookStack\Actions\Webhook; use BookStack\Auth\User; -use BookStack\Entities\Models\Page; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Http; @@ -53,11 +52,16 @@ class WebhookCallTest extends TestCase Http::fake([ '*' => Http::response('', 500), ]); - $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); + $webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); + $this->assertNull($webhook->last_errored_at); $this->runEvent(ActivityType::ROLE_CREATE); $this->assertTrue($logger->hasError('Webhook call to endpoint https://wh.example.com failed with status 500')); + + $webhook->refresh(); + $this->assertEquals('Response status from endpoint was 500', $webhook->last_error); + $this->assertNotNull($webhook->last_errored_at); } public function test_webhook_call_exception_is_caught_and_logged() @@ -65,11 +69,16 @@ class WebhookCallTest extends TestCase Http::shouldReceive('asJson')->andThrow(new \Exception('Failed to perform request')); $logger = $this->withTestLogger(); - $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); + $webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); + $this->assertNull($webhook->last_errored_at); $this->runEvent(ActivityType::ROLE_CREATE); $this->assertTrue($logger->hasError('Webhook call to endpoint https://wh.example.com failed with error "Failed to perform request"')); + + $webhook->refresh(); + $this->assertEquals('Failed to perform request', $webhook->last_error); + $this->assertNotNull($webhook->last_errored_at); } public function test_webhook_call_data_format() @@ -78,8 +87,7 @@ class WebhookCallTest extends TestCase '*' => Http::response('', 200), ]); $webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $editor = $this->getEditor(); $this->runEvent(ActivityType::PAGE_UPDATE, $page, $editor);