diff --git a/src/HipChatDriver.php b/src/HipChatDriver.php index e93b30d..4dc4078 100644 --- a/src/HipChatDriver.php +++ b/src/HipChatDriver.php @@ -77,7 +77,7 @@ public function isBot() */ public function buildServicePayload($message, $matchingMessage, $additionalParameters = []) { - $parameters = array_merge_recursive([ + $parameters = array_replace_recursive([ 'message_format' => 'text', ], $additionalParameters); /* diff --git a/tests/HipChatDriverTest.php b/tests/HipChatDriverTest.php index 922fe0f..8654474 100644 --- a/tests/HipChatDriverTest.php +++ b/tests/HipChatDriverTest.php @@ -229,4 +229,35 @@ public function it_is_configured() $this->assertFalse($driver->isConfigured()); } + + /** @test */ + public function it_builds_the_correct_payload() + { + // Given a user wants to send html + $driver = $this->getDriver([ + 'event' => 'room_message', + 'item' => [ + 'message' => [ + 'from' => [ + 'id' => '12345', + ], + 'message' => 'Hi Julia', + ], + 'room' => [ + 'id' => '98765', + ], + ], + 'webhook_id' => '11223344', + ]); + $message = $driver->getMessages()[0]; + $payload = $driver->buildServicePayload('Test message', $message); + $this->assertEquals('text', $payload['message_format']); + + // Now if the user wants to set the format to HTML + $payload = $driver->buildServicePayload('Test message', $message, [ + 'message_format' => 'html' + ]); + + $this->assertEquals('html', $payload['message_format']); + } }