Skip to content

Commit 1182e1c

Browse files
committed
fix: configuration is not required
1 parent b4894ff commit 1182e1c

2 files changed

Lines changed: 68 additions & 9 deletions

File tree

src/Requests/PostEvent/JobData.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class JobData implements JsonSerializable
1414
private string $jobEndTime;
1515
private string $componentId;
1616
private string $componentName;
17-
private string $configurationId;
18-
private string $configurationName;
17+
private ?string $configurationId;
18+
private ?string $configurationName;
1919

2020
public function __construct(
2121
string $jobId,
@@ -24,8 +24,8 @@ public function __construct(
2424
string $jobEndTime,
2525
string $componentId,
2626
string $componentName,
27-
string $configurationId,
28-
string $configurationName
27+
?string $configurationId,
28+
?string $configurationName
2929
) {
3030
$this->jobId = $jobId;
3131
$this->jobUrl = $jobUrl;
@@ -42,7 +42,7 @@ public function __construct(
4242
*/
4343
public function jsonSerialize()
4444
{
45-
return [
45+
$result = [
4646
'id' => $this->jobId,
4747
'url' => $this->jobUrl,
4848
'startTime' => $this->jobStartTime,
@@ -51,11 +51,14 @@ public function jsonSerialize()
5151
'id' => $this->componentId,
5252
'name' => $this->componentName,
5353
],
54-
'configuration' => [
55-
'id' => $this->configurationId,
56-
'name' => $this->configurationName,
57-
],
5854
'tasks' => [],
5955
];
56+
if ($this->configurationId && $this->configurationName) {
57+
$result['configuration'] = [
58+
'id' => $this->configurationId,
59+
'name' => $this->configurationName,
60+
];
61+
}
62+
return $result;
6063
}
6164
}

tests/Requests/PostEvent/JobDataTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,60 @@ public function testJsonSerialize(): void
4040
$jobData->jsonSerialize()
4141
);
4242
}
43+
44+
public function testJsonSerializeEmptyConfigurationId(): void
45+
{
46+
$jobData = new JobData(
47+
'23456',
48+
'http://someUrl',
49+
'2020-01-01',
50+
'2020-02-02',
51+
'keboola.orchestrator',
52+
'Orchestrator',
53+
null,
54+
'My configuration'
55+
);
56+
self::assertSame(
57+
[
58+
'id' => '23456',
59+
'url' => 'http://someUrl',
60+
'startTime' => '2020-01-01',
61+
'endTime' => '2020-02-02',
62+
'component' => [
63+
'id' => 'keboola.orchestrator',
64+
'name' => 'Orchestrator',
65+
],
66+
'tasks' => [],
67+
],
68+
$jobData->jsonSerialize()
69+
);
70+
}
71+
72+
public function testJsonSerializeEmptyConfigurationName(): void
73+
{
74+
$jobData = new JobData(
75+
'23456',
76+
'http://someUrl',
77+
'2020-01-01',
78+
'2020-02-02',
79+
'keboola.orchestrator',
80+
'Orchestrator',
81+
'1234',
82+
null
83+
);
84+
self::assertSame(
85+
[
86+
'id' => '23456',
87+
'url' => 'http://someUrl',
88+
'startTime' => '2020-01-01',
89+
'endTime' => '2020-02-02',
90+
'component' => [
91+
'id' => 'keboola.orchestrator',
92+
'name' => 'Orchestrator',
93+
],
94+
'tasks' => [],
95+
],
96+
$jobData->jsonSerialize()
97+
);
98+
}
4399
}

0 commit comments

Comments
 (0)