|
11 | 11 | use Nexmo\Client\Exception; |
12 | 12 | use Nexmo\Message\Client; |
13 | 13 | use Nexmo\Message\Message; |
| 14 | +use Nexmo\Message\Shortcode\TwoFactor; |
14 | 15 | use Nexmo\Message\Text; |
15 | 16 | use NexmoTest\Psr7AssertionTrait; |
16 | 17 | use NexmoTest\MessageAssertionTrait; |
@@ -254,6 +255,87 @@ public function searchRejectionsProvider() |
254 | 255 | return $r; |
255 | 256 | } |
256 | 257 |
|
| 258 | + public function testShortcodeWithObject() |
| 259 | + { |
| 260 | + $message = new TwoFactor('14155550100', [ 'link' => 'https://example.com' ], ['status-report-req' => 1]); |
| 261 | + |
| 262 | + $this->nexmoClient->send(Argument::that(function(Request $request) { |
| 263 | + $this->assertRequestJsonBodyContains('to', '14155550100', $request); |
| 264 | + $this->assertRequestJsonBodyContains('link', 'https://example.com', $request); |
| 265 | + $this->assertRequestJsonBodyContains('status-report-req', 1, $request); |
| 266 | + return true; |
| 267 | + }))->willReturn($this->getResponse('success-2fa')); |
| 268 | + |
| 269 | + $response = $this->messageClient->sendShortcode($message); |
| 270 | + $this->assertEquals([ |
| 271 | + 'message-count' => '1', |
| 272 | + 'messages' =>[ |
| 273 | + [ |
| 274 | + 'status' => '0', |
| 275 | + 'message-id' => '00000123', |
| 276 | + 'to' => '14155550100', |
| 277 | + 'client-ref' => 'client-ref', |
| 278 | + 'remaining-balance' => '1.10', |
| 279 | + 'message-price' => '0.05', |
| 280 | + 'network' => '23410' |
| 281 | + ] |
| 282 | + ] |
| 283 | + ], $response); |
| 284 | + } |
| 285 | + |
| 286 | + public function testShortcodeError() |
| 287 | + { |
| 288 | + $args = [ |
| 289 | + 'to' => '14155550100', |
| 290 | + 'custom' => [ 'link' => 'https://example.com' ], |
| 291 | + 'options' => ['status-report-req' => 1], |
| 292 | + 'type' => '2fa' |
| 293 | + ]; |
| 294 | + |
| 295 | + $this->nexmoClient->send(Argument::that(function(Request $request) use ($args){ |
| 296 | + return true; |
| 297 | + }))->willReturn($this->getResponse('error-2fa')); |
| 298 | + |
| 299 | + $this->expectException(Exception\Request::class); |
| 300 | + $this->expectExceptionMessage('Invalid Account for Campaign'); |
| 301 | + |
| 302 | + $this->messageClient->sendShortcode($args); |
| 303 | + } |
| 304 | + |
| 305 | + public function testShortcodeWithArray() |
| 306 | + { |
| 307 | + $args = [ |
| 308 | + 'to' => '14155550100', |
| 309 | + 'custom' => [ 'link' => 'https://example.com' ], |
| 310 | + 'options' => ['status-report-req' => 1], |
| 311 | + 'type' => '2fa' |
| 312 | + ]; |
| 313 | + |
| 314 | + $this->nexmoClient->send(Argument::that(function(Request $request) use ($args){ |
| 315 | + $this->assertRequestJsonBodyContains('to', $args['to'], $request); |
| 316 | + $this->assertRequestJsonBodyContains('link', $args['custom']['link'], $request); |
| 317 | + $this->assertRequestJsonBodyContains('status-report-req', $args['options']['status-report-req'], $request); |
| 318 | + return true; |
| 319 | + }))->willReturn($this->getResponse('success-2fa')); |
| 320 | + |
| 321 | + $response = $this->messageClient->sendShortcode($args); |
| 322 | + $this->assertEquals([ |
| 323 | + 'message-count' => '1', |
| 324 | + 'messages' =>[ |
| 325 | + [ |
| 326 | + 'status' => '0', |
| 327 | + 'message-id' => '00000123', |
| 328 | + 'to' => '14155550100', |
| 329 | + 'client-ref' => 'client-ref', |
| 330 | + 'remaining-balance' => '1.10', |
| 331 | + 'message-price' => '0.05', |
| 332 | + 'network' => '23410' |
| 333 | + ] |
| 334 | + ] |
| 335 | + ], $response); |
| 336 | + } |
| 337 | + |
| 338 | + |
257 | 339 | /** |
258 | 340 | * Get the API response we'd expect for a call to the API. Message API currently returns 200 all the time, so only |
259 | 341 | * change between success / fail is body of the message. |
|
0 commit comments