+ public function test_event_webhook_call_before()
+ {
+ $args = [];
+ $callback = function (...$eventArgs) use (&$args) {
+ $args = $eventArgs;
+
+ return ['test' => 'hello!'];
+ };
+ Theme::listen(ThemeEvents::WEBHOOK_CALL_BEFORE, $callback);
+
+ Http::fake([
+ '*' => Http::response('', 200),
+ ]);
+
+ $webhook = new Webhook(['name' => 'Test webhook', 'endpoint' => 'https://example.com']);
+ $webhook->save();
+ $event = ActivityType::PAGE_UPDATE;
+ $detail = Page::query()->first();
+
+ dispatch((new DispatchWebhookJob($webhook, $event, $detail)));
+
+ $this->assertCount(5, $args);
+ $this->assertEquals($event, $args[0]);
+ $this->assertEquals($webhook->id, $args[1]->id);
+ $this->assertEquals($detail->id, $args[2]->id);
+
+ Http::assertSent(function (HttpClientRequest $request) {
+ return $request->isJson() && $request->data()['test'] === 'hello!';
+ });
+ }
+
+ public function test_event_activity_logged()
+ {
+ $book = Book::query()->first();
+ $args = [];
+ $callback = function (...$eventArgs) use (&$args) {
+ $args = $eventArgs;
+ };
+
+ Theme::listen(ThemeEvents::ACTIVITY_LOGGED, $callback);
+ $this->asEditor()->put($book->getUrl(), ['name' => 'My cool update book!']);
+
+ $this->assertCount(2, $args);
+ $this->assertEquals(ActivityType::BOOK_UPDATE, $args[0]);
+ $this->assertTrue($args[1] instanceof Book);
+ $this->assertEquals($book->id, $args[1]->id);
+ }
+