|
4 | 4 |
|
5 | 5 | namespace Keboola\NotificationClient\Tests\Requests\PostNotification; |
6 | 6 |
|
| 7 | +use Keboola\NotificationClient\Requests\PostNotification\FlowInfo; |
| 8 | +use Keboola\NotificationClient\Requests\PostNotification\JobInfo; |
7 | 9 | use Keboola\NotificationClient\Requests\PostNotification\ProjectEmail; |
8 | 10 | use Keboola\NotificationClient\Requests\PostSubscription\EmailRecipient; |
9 | 11 | use PHPUnit\Framework\TestCase; |
@@ -45,4 +47,153 @@ public function testJsonSerialize(): void |
45 | 47 | $projectEmail->jsonSerialize(), |
46 | 48 | ); |
47 | 49 | } |
| 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 | + } |
48 | 199 | } |
0 commit comments