Skip to content

Commit 1039c14

Browse files
authored
Merge pull request #23 from keboola/novakjiri-AJDA-443
feat: AJDA-443 add additional info about flow and job for project notifications
2 parents 42baf28 + 8dc88f5 commit 1039c14

8 files changed

Lines changed: 442 additions & 2 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Requests\PostNotification;
6+
7+
class FlowInfo
8+
{
9+
private string $id;
10+
11+
private string $name;
12+
13+
private string $url;
14+
15+
public function __construct(string $id, string $name, string $url)
16+
{
17+
$this->id = $id;
18+
$this->name = $name;
19+
$this->url = $url;
20+
}
21+
22+
public function jsonSerialize(): array
23+
{
24+
return [
25+
'id' => $this->id,
26+
'name' => $this->name,
27+
'url' => $this->url,
28+
];
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Requests\PostNotification;
6+
7+
class JobInfo
8+
{
9+
private string $id;
10+
11+
private string $url;
12+
13+
public function __construct(string $id, string $url)
14+
{
15+
$this->id = $id;
16+
$this->url = $url;
17+
}
18+
19+
public function jsonSerialize(): array
20+
{
21+
return [
22+
'id' => $this->id,
23+
'url' => $this->url,
24+
];
25+
}
26+
}

src/Requests/PostNotification/ProjectEmail.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@ class ProjectEmail implements NotificationInterface
1515
private string $title;
1616
private string $message;
1717
private EmailRecipient $recipient;
18+
private ?FlowInfo $flow;
19+
private ?JobInfo $job;
1820

1921
public function __construct(
2022
EmailRecipient $recipient,
2123
string $projectId,
2224
string $projectName,
2325
string $title,
2426
string $message,
27+
?FlowInfo $flow = null,
28+
?JobInfo $job = null,
2529
) {
2630
$this->recipient = $recipient;
2731
$this->projectId = $projectId;
2832
$this->projectName = $projectName;
2933
$this->title = $title;
3034
$this->message = $message;
35+
$this->flow = $flow;
36+
$this->job = $job;
3137
}
3238

3339
public function jsonSerialize(): array
3440
{
35-
return [
41+
$notification = [
3642
'type' => self::TYPE,
3743
'recipient' => $this->recipient->jsonSerialize(),
3844
'data' => [
@@ -44,5 +50,15 @@ public function jsonSerialize(): array
4450
'message' => $this->message,
4551
],
4652
];
53+
54+
if ($this->flow !== null) {
55+
$notification['data']['flow'] = $this->flow->jsonSerialize();
56+
}
57+
58+
if ($this->job !== null) {
59+
$notification['data']['job'] = $this->job->jsonSerialize();
60+
}
61+
62+
return $notification;
4763
}
4864
}

src/Requests/PostNotification/ProjectWebhook.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@ class ProjectWebhook implements NotificationInterface
1515
private string $title;
1616
private ?string $message;
1717
private WebhookRecipient $recipient;
18+
private ?FlowInfo $flow;
19+
private ?JobInfo $job;
1820

1921
public function __construct(
2022
WebhookRecipient $recipient,
2123
string $projectId,
2224
string $projectName,
2325
string $title,
2426
?string $message,
27+
?FlowInfo $flow = null,
28+
?JobInfo $job = null,
2529
) {
2630
$this->recipient = $recipient;
2731
$this->projectId = $projectId;
2832
$this->projectName = $projectName;
2933
$this->title = $title;
3034
$this->message = $message;
35+
$this->flow = $flow;
36+
$this->job = $job;
3137
}
3238

3339
public function jsonSerialize(): array
3440
{
35-
return [
41+
$notification = [
3642
'type' => self::TYPE,
3743
'recipient' => $this->recipient->jsonSerialize(),
3844
'data' => [
@@ -44,5 +50,15 @@ public function jsonSerialize(): array
4450
'message' => $this->message,
4551
],
4652
];
53+
54+
if ($this->flow !== null) {
55+
$notification['data']['flow'] = $this->flow->jsonSerialize();
56+
}
57+
58+
if ($this->job !== null) {
59+
$notification['data']['job'] = $this->job->jsonSerialize();
60+
}
61+
62+
return $notification;
4763
}
4864
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Tests\Requests\PostNotification;
6+
7+
use Keboola\NotificationClient\Requests\PostNotification\FlowInfo;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class FlowInfoTest extends TestCase
11+
{
12+
public function testJsonSerialize(): void
13+
{
14+
$flowInfo = new FlowInfo(
15+
'flow-123',
16+
'My Test Flow',
17+
'https://connection.keboola.com/flows/123',
18+
);
19+
20+
$this->assertSame([
21+
'id' => 'flow-123',
22+
'name' => 'My Test Flow',
23+
'url' => 'https://connection.keboola.com/flows/123',
24+
], $flowInfo->jsonSerialize());
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Tests\Requests\PostNotification;
6+
7+
use Keboola\NotificationClient\Requests\PostNotification\JobInfo;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class JobInfoTest extends TestCase
11+
{
12+
public function testJsonSerialize(): void
13+
{
14+
$jobInfo = new JobInfo(
15+
'job-123',
16+
'https://connection.keboola.com/jobs/123',
17+
);
18+
19+
$this->assertSame([
20+
'id' => 'job-123',
21+
'url' => 'https://connection.keboola.com/jobs/123',
22+
], $jobInfo->jsonSerialize());
23+
}
24+
}

tests/Requests/PostNotification/ProjectEmailTest.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Keboola\NotificationClient\Tests\Requests\PostNotification;
66

7+
use Keboola\NotificationClient\Requests\PostNotification\FlowInfo;
8+
use Keboola\NotificationClient\Requests\PostNotification\JobInfo;
79
use Keboola\NotificationClient\Requests\PostNotification\ProjectEmail;
810
use Keboola\NotificationClient\Requests\PostSubscription\EmailRecipient;
911
use PHPUnit\Framework\TestCase;
@@ -45,4 +47,153 @@ public function testJsonSerialize(): void
4547
$projectEmail->jsonSerialize(),
4648
);
4749
}
50+
51+
public function testJsonSerializeWithFlowAndJob(): void
52+
{
53+
$recipient = new EmailRecipient('john.doe@example.com');
54+
$projectId = '12345';
55+
$projectName = 'Test Project';
56+
$title = 'Test Notification';
57+
$message = 'This is a test notification message';
58+
$flow = new FlowInfo(
59+
'flow-123',
60+
'My Test Flow',
61+
'https://connection.keboola.com/flows/123',
62+
);
63+
$job = new JobInfo(
64+
'job-123',
65+
'https://connection.keboola.com/jobs/123',
66+
);
67+
68+
$projectEmail = new ProjectEmail(
69+
$recipient,
70+
$projectId,
71+
$projectName,
72+
$title,
73+
$message,
74+
$flow,
75+
$job,
76+
);
77+
78+
self::assertSame(
79+
[
80+
'type' => 'direct-project-email',
81+
'recipient' => [
82+
'channel' => 'email',
83+
'address' => 'john.doe@example.com',
84+
],
85+
'data' => [
86+
'project' => [
87+
'id' => $projectId,
88+
'name' => $projectName,
89+
],
90+
'title' => $title,
91+
'message' => $message,
92+
'flow' => [
93+
'id' => 'flow-123',
94+
'name' => 'My Test Flow',
95+
'url' => 'https://connection.keboola.com/flows/123',
96+
],
97+
'job' => [
98+
'id' => 'job-123',
99+
'url' => 'https://connection.keboola.com/jobs/123',
100+
],
101+
],
102+
],
103+
$projectEmail->jsonSerialize(),
104+
);
105+
}
106+
107+
public function testJsonSerializeWithFlow(): void
108+
{
109+
$recipient = new EmailRecipient('john.doe@example.com');
110+
$projectId = '12345';
111+
$projectName = 'Test Project';
112+
$title = 'Test Notification';
113+
$message = 'This is a test notification message';
114+
$flow = new FlowInfo(
115+
'flow-123',
116+
'My Test Flow',
117+
'https://connection.keboola.com/flows/123',
118+
);
119+
120+
$projectEmail = new ProjectEmail(
121+
$recipient,
122+
$projectId,
123+
$projectName,
124+
$title,
125+
$message,
126+
$flow,
127+
);
128+
129+
self::assertSame(
130+
[
131+
'type' => 'direct-project-email',
132+
'recipient' => [
133+
'channel' => 'email',
134+
'address' => 'john.doe@example.com',
135+
],
136+
'data' => [
137+
'project' => [
138+
'id' => $projectId,
139+
'name' => $projectName,
140+
],
141+
'title' => $title,
142+
'message' => $message,
143+
'flow' => [
144+
'id' => 'flow-123',
145+
'name' => 'My Test Flow',
146+
'url' => 'https://connection.keboola.com/flows/123',
147+
],
148+
],
149+
],
150+
$projectEmail->jsonSerialize(),
151+
);
152+
}
153+
154+
public function testJsonSerializeWithJob(): void
155+
{
156+
$recipient = new EmailRecipient('john.doe@example.com');
157+
$projectId = '12345';
158+
$projectName = 'Test Project';
159+
$title = 'Test Notification';
160+
$message = 'This is a test notification message';
161+
$job = new JobInfo(
162+
'job-123',
163+
'https://connection.keboola.com/jobs/123',
164+
);
165+
166+
$projectEmail = new ProjectEmail(
167+
$recipient,
168+
$projectId,
169+
$projectName,
170+
$title,
171+
$message,
172+
null,
173+
$job,
174+
);
175+
176+
self::assertSame(
177+
[
178+
'type' => 'direct-project-email',
179+
'recipient' => [
180+
'channel' => 'email',
181+
'address' => 'john.doe@example.com',
182+
],
183+
'data' => [
184+
'project' => [
185+
'id' => $projectId,
186+
'name' => $projectName,
187+
],
188+
'title' => $title,
189+
'message' => $message,
190+
'job' => [
191+
'id' => 'job-123',
192+
'url' => 'https://connection.keboola.com/jobs/123',
193+
],
194+
],
195+
],
196+
$projectEmail->jsonSerialize(),
197+
);
198+
}
48199
}

0 commit comments

Comments
 (0)