Skip to content

Commit 49cb31a

Browse files
author
Jiří Novák
committed
feat: AJDA-381 add project webhook notification
1 parent 7e3d5e0 commit 49cb31a

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Requests\PostNotification;
6+
7+
use Keboola\NotificationClient\Requests\PostSubscription\WebhookRecipient;
8+
9+
class ProjectWebhook implements NotificationInterface
10+
{
11+
private const TYPE = 'direct-project-webhook';
12+
13+
private string $projectId;
14+
private string $projectName;
15+
private string $title;
16+
private ?string $message;
17+
private WebhookRecipient $recipient;
18+
19+
public function __construct(
20+
WebhookRecipient $recipient,
21+
string $projectId,
22+
string $projectName,
23+
string $title,
24+
?string $message
25+
) {
26+
$this->recipient = $recipient;
27+
$this->projectId = $projectId;
28+
$this->projectName = $projectName;
29+
$this->title = $title;
30+
$this->message = $message;
31+
}
32+
33+
public function jsonSerialize(): array
34+
{
35+
return [
36+
'type' => self::TYPE,
37+
'recipient' => $this->recipient->jsonSerialize(),
38+
'data' => [
39+
'project' => [
40+
'id' => $this->projectId,
41+
'name' => $this->projectName,
42+
],
43+
'title' => $this->title,
44+
'message' => $this->message,
45+
],
46+
];
47+
}
48+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Tests\Requests\PostNotification;
6+
7+
use Keboola\NotificationClient\Requests\PostNotification\ProjectWebhook;
8+
use Keboola\NotificationClient\Requests\PostSubscription\WebhookRecipient;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class ProjectWebhookTest extends TestCase
12+
{
13+
public function testJsonSerialize(): void
14+
{
15+
$recipient = new WebhookRecipient('https://example.com/webhook');
16+
$projectId = '12345';
17+
$projectName = 'Test Project';
18+
$title = 'Test Notification';
19+
$message = 'This is a test notification message';
20+
21+
$projectWebhook = new ProjectWebhook(
22+
$recipient,
23+
$projectId,
24+
$projectName,
25+
$title,
26+
$message,
27+
);
28+
29+
self::assertSame(
30+
[
31+
'type' => 'direct-project-webhook',
32+
'recipient' => [
33+
'channel' => 'webhook',
34+
'url' => 'https://example.com/webhook',
35+
],
36+
'data' => [
37+
'project' => [
38+
'id' => $projectId,
39+
'name' => $projectName,
40+
],
41+
'title' => $title,
42+
'message' => $message,
43+
],
44+
],
45+
$projectWebhook->jsonSerialize(),
46+
);
47+
}
48+
49+
public function testJsonSerializeWithNullMessage(): void
50+
{
51+
$recipient = new WebhookRecipient('https://example.com/webhook');
52+
$projectId = '67890';
53+
$projectName = 'Another Test Project';
54+
$title = 'Test Notification Without Message';
55+
$message = null;
56+
57+
$projectWebhook = new ProjectWebhook(
58+
$recipient,
59+
$projectId,
60+
$projectName,
61+
$title,
62+
$message,
63+
);
64+
65+
self::assertSame(
66+
[
67+
'type' => 'direct-project-webhook',
68+
'recipient' => [
69+
'channel' => 'webhook',
70+
'url' => 'https://example.com/webhook',
71+
],
72+
'data' => [
73+
'project' => [
74+
'id' => $projectId,
75+
'name' => $projectName,
76+
],
77+
'title' => $title,
78+
'message' => null,
79+
],
80+
],
81+
$projectWebhook->jsonSerialize(),
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)