Skip to content

Commit 8dc88f5

Browse files
author
Jiří Novák
committed
test: AJDA-443 add tests for FlowInfo and JobInfo
1 parent 47af694 commit 8dc88f5

4 files changed

Lines changed: 236 additions & 0 deletions

File tree

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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,97 @@ public function testJsonSerializeWithFlowAndJob(): void
103103
$projectEmail->jsonSerialize(),
104104
);
105105
}
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+
}
106199
}

tests/Requests/PostNotification/ProjectWebhookTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,97 @@ public function testJsonSerializeWithFlowAndJob(): void
139139
$projectWebhook->jsonSerialize(),
140140
);
141141
}
142+
143+
public function testJsonSerializeWithFlow(): void
144+
{
145+
$recipient = new WebhookRecipient('https://example.com/webhook');
146+
$projectId = '12345';
147+
$projectName = 'Test Project';
148+
$title = 'Test Notification';
149+
$message = 'This is a test notification message';
150+
$flow = new FlowInfo(
151+
'flow-123',
152+
'My Test Flow',
153+
'https://connection.keboola.com/flows/123',
154+
);
155+
156+
$projectWebhook = new ProjectWebhook(
157+
$recipient,
158+
$projectId,
159+
$projectName,
160+
$title,
161+
$message,
162+
$flow,
163+
);
164+
165+
self::assertSame(
166+
[
167+
'type' => 'direct-project-webhook',
168+
'recipient' => [
169+
'channel' => 'webhook',
170+
'url' => 'https://example.com/webhook',
171+
],
172+
'data' => [
173+
'project' => [
174+
'id' => $projectId,
175+
'name' => $projectName,
176+
],
177+
'title' => $title,
178+
'message' => $message,
179+
'flow' => [
180+
'id' => 'flow-123',
181+
'name' => 'My Test Flow',
182+
'url' => 'https://connection.keboola.com/flows/123',
183+
],
184+
],
185+
],
186+
$projectWebhook->jsonSerialize(),
187+
);
188+
}
189+
190+
public function testJsonSerializeWithJob(): void
191+
{
192+
$recipient = new WebhookRecipient('https://example.com/webhook');
193+
$projectId = '12345';
194+
$projectName = 'Test Project';
195+
$title = 'Test Notification';
196+
$message = 'This is a test notification message';
197+
$job = new JobInfo(
198+
'job-123',
199+
'https://connection.keboola.com/jobs/123',
200+
);
201+
202+
$projectWebhook = new ProjectWebhook(
203+
$recipient,
204+
$projectId,
205+
$projectName,
206+
$title,
207+
$message,
208+
null,
209+
$job,
210+
);
211+
212+
self::assertSame(
213+
[
214+
'type' => 'direct-project-webhook',
215+
'recipient' => [
216+
'channel' => 'webhook',
217+
'url' => 'https://example.com/webhook',
218+
],
219+
'data' => [
220+
'project' => [
221+
'id' => $projectId,
222+
'name' => $projectName,
223+
],
224+
'title' => $title,
225+
'message' => $message,
226+
'job' => [
227+
'id' => 'job-123',
228+
'url' => 'https://connection.keboola.com/jobs/123',
229+
],
230+
],
231+
],
232+
$projectWebhook->jsonSerialize(),
233+
);
234+
}
142235
}

0 commit comments

Comments
 (0)