|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NotificationChannels\WhatsApp\Test; |
| 4 | + |
| 5 | +use NotificationChannels\WhatsApp\Component\Currency; |
| 6 | +use NotificationChannels\WhatsApp\Component\Document; |
| 7 | +use NotificationChannels\WhatsApp\Component\Image; |
| 8 | +use NotificationChannels\WhatsApp\Component\Text; |
| 9 | +use NotificationChannels\WhatsApp\Component\Video; |
| 10 | +use NotificationChannels\WhatsApp\WhatsAppTemplate; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +final class WhatsAppTemplateTest extends TestCase |
| 14 | +{ |
| 15 | + /** @test */ |
| 16 | + public function the_notification_recipient_can_be_set() |
| 17 | + { |
| 18 | + $message = WhatsAppTemplate::create() |
| 19 | + ->to('346762014584'); |
| 20 | + |
| 21 | + $this->assertEquals('346762014584', $message->recipient()); |
| 22 | + } |
| 23 | + |
| 24 | + /** @test */ |
| 25 | + public function the_notification_name_can_be_set() |
| 26 | + { |
| 27 | + $message = WhatsAppTemplate::create() |
| 28 | + ->name('invoice_created'); |
| 29 | + |
| 30 | + $this->assertEquals('invoice_created', $message->configuredName()); |
| 31 | + } |
| 32 | + |
| 33 | + /** @test */ |
| 34 | + public function the_notification_language_can_be_set() |
| 35 | + { |
| 36 | + $message = WhatsAppTemplate::create() |
| 37 | + ->language('es_fake'); |
| 38 | + |
| 39 | + $this->assertEquals('es_fake', $message->configuredLanguage()); |
| 40 | + } |
| 41 | + |
| 42 | + /** @test */ |
| 43 | + public function the_notification_component_header_can_be_set() |
| 44 | + { |
| 45 | + $message = WhatsAppTemplate::create() |
| 46 | + ->header(new Currency(10, 'USD')) |
| 47 | + ->header(new Document('https://netflie.es/document.pdf')) |
| 48 | + ->header(new Video('https://netflie.es/video.webm')); |
| 49 | + |
| 50 | + $expectedHeader = [ |
| 51 | + [ |
| 52 | + 'type' => 'currency', |
| 53 | + 'currency' => ['amount_1000' => 10000, 'code' => 'USD'], |
| 54 | + ], |
| 55 | + [ |
| 56 | + 'type' => 'document', |
| 57 | + 'document' => ['link' => 'https://netflie.es/document.pdf'], |
| 58 | + ], |
| 59 | + [ |
| 60 | + 'type' => 'video', |
| 61 | + 'video' => ['link' => 'https://netflie.es/video.webm'], |
| 62 | + ], |
| 63 | + ]; |
| 64 | + |
| 65 | + $this->assertEquals($expectedHeader, $message->components()->header()); |
| 66 | + } |
| 67 | + |
| 68 | + /** @test */ |
| 69 | + public function the_notification_component_body_can_be_set() |
| 70 | + { |
| 71 | + $message = WhatsAppTemplate::create() |
| 72 | + ->body(new Text('Mr Jones')) |
| 73 | + ->body(new Image('https://netflie.es/image.png')); |
| 74 | + |
| 75 | + $expectedHeader = [ |
| 76 | + [ |
| 77 | + 'type' => 'text', |
| 78 | + 'text' => 'Mr Jones', |
| 79 | + ], |
| 80 | + [ |
| 81 | + 'type' => 'image', |
| 82 | + 'image' => ['link' => 'https://netflie.es/image.png'], |
| 83 | + ], |
| 84 | + ]; |
| 85 | + |
| 86 | + $this->assertEquals($expectedHeader, $message->components()->body()); |
| 87 | + } |
| 88 | +} |
0 commit comments