|
12 | 12 | use Nexmo\Voice\Webhook\Factory;
|
13 | 13 | use Nexmo\Voice\Webhook\Transfer;
|
14 | 14 | use Zend\Diactoros\ServerRequest;
|
| 15 | +use Nexmo\Voice\Webhook\Notification; |
15 | 16 | use Zend\Diactoros\Request\Serializer;
|
16 | 17 |
|
17 | 18 | class FactoryTest extends TestCase
|
@@ -155,6 +156,34 @@ public function testCanGenerateAnErrorWebhook()
|
155 | 156 | $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $error->getTimestamp());
|
156 | 157 | }
|
157 | 158 |
|
| 159 | + public function testCanGenerateANotificationGetWebhook() |
| 160 | + { |
| 161 | + $request = $this->getRequest('event-get-notify'); |
| 162 | + $expected = $this->getRequest('event-get-notify')->getQueryParams(); |
| 163 | + |
| 164 | + /** @var Notification $notification */ |
| 165 | + $notification = Factory::createFromRequest($request); |
| 166 | + |
| 167 | + $this->assertTrue($notification instanceof Notification); |
| 168 | + $this->assertSame($expected['conversation_uuid'], $notification->getConversationUuid()); |
| 169 | + $this->assertSame(json_decode($expected['payload'], true), $notification->getPayload()); |
| 170 | + $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $notification->getTimestamp()); |
| 171 | + } |
| 172 | + |
| 173 | + public function testCanGenerateANotificationPostWebhook() |
| 174 | + { |
| 175 | + $request = $this->getRequest('event-post-notify'); |
| 176 | + $expected = json_decode($this->getRequest('event-post-notify')->getBody()->getContents(), true); |
| 177 | + |
| 178 | + /** @var Notification $notification */ |
| 179 | + $notification = Factory::createFromRequest($request); |
| 180 | + |
| 181 | + $this->assertTrue($notification instanceof Notification); |
| 182 | + $this->assertSame($expected['conversation_uuid'], $notification->getConversationUuid()); |
| 183 | + $this->assertSame($expected['payload'], $notification->getPayload()); |
| 184 | + $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $notification->getTimestamp()); |
| 185 | + } |
| 186 | + |
158 | 187 | public function testThrowsExceptionOnUnknownWebhookData()
|
159 | 188 | {
|
160 | 189 | $this->expectException(\InvalidArgumentException::class);
|
|
0 commit comments