From 677c21a1bbdade2d965d9017972ef2198680e7d2 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Thu, 5 Oct 2017 23:45:20 +0200 Subject: [PATCH] More tests --- tests/AmazonAlexaDriverTest.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/AmazonAlexaDriverTest.php b/tests/AmazonAlexaDriverTest.php index 97686da..4c28e44 100644 --- a/tests/AmazonAlexaDriverTest.php +++ b/tests/AmazonAlexaDriverTest.php @@ -7,10 +7,11 @@ use PHPUnit_Framework_TestCase; use BotMan\BotMan\Messages\Outgoing\Question; use Symfony\Component\HttpFoundation\Request; +use BotMan\BotMan\Drivers\Events\GenericEvent; +use Symfony\Component\HttpFoundation\Response; use BotMan\Drivers\AmazonAlexa\AmazonAlexaDriver; use BotMan\BotMan\Messages\Incoming\IncomingMessage; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; -use Symfony\Component\HttpFoundation\Response; class AmazonAlexaDriverTest extends PHPUnit_Framework_TestCase { @@ -26,7 +27,7 @@ private function getDriver($responseData, $htmlInterface = null) return new AmazonAlexaDriver($request, [], $htmlInterface); } - private function getValidDriver($htmlInterface = null) + private function getValidDriver($htmlInterface = null, $type = 'IntentRequest') { $responseData = '{ "session": { @@ -41,7 +42,7 @@ private function getValidDriver($htmlInterface = null) } }, "request": { - "type": "IntentRequest", + "type": "'.$type.'", "requestId": "request_id", "intent": { "name": "intent_name", @@ -193,6 +194,25 @@ public function it_can_send_payload() $this->assertSame('{"version":"1.0","sessionAttributes":[],"response":{"outputSpeech":{"type":"PlainText","text":"string"},"card":null,"reprompt":null,"shouldEndSession":false}}', $response->getContent()); } + /** @test */ + public function it_fires_launch_event() + { + $driver = $this->getValidDriver(null, AmazonAlexaDriver::LAUNCH_REQUEST); + + $event = $driver->hasMatchingEvent(); + + $this->assertInstanceOf(GenericEvent::class, $event); + $this->assertSame(AmazonAlexaDriver::LAUNCH_REQUEST, $event->getName()); + } + + /** @test */ + public function it_no_events_for_regular_messages() + { + $driver = $this->getValidDriver(); + + $this->assertFalse($driver->hasMatchingEvent()); + } + /** @test */ public function it_can_get_conversation_answers() {