2020-08-24 06:03:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-09-10 19:59:26 +00:00
|
|
|
namespace BeyondCode\LaravelWebSockets\Test\Dashboard;
|
2020-08-24 06:03:52 +00:00
|
|
|
|
2020-09-10 19:59:26 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\Test\Models\User;
|
|
|
|
|
use BeyondCode\LaravelWebSockets\Test\TestCase;
|
2020-08-24 06:03:52 +00:00
|
|
|
|
|
|
|
|
class SendMessageTest extends TestCase
|
|
|
|
|
{
|
2020-09-10 19:59:26 +00:00
|
|
|
public function test_can_send_message()
|
2020-08-24 06:03:52 +00:00
|
|
|
{
|
|
|
|
|
$this->actingAs(factory(User::class)->create())
|
|
|
|
|
->json('POST', route('laravel-websockets.event'), [
|
|
|
|
|
'appId' => '1234',
|
|
|
|
|
'channel' => 'test-channel',
|
|
|
|
|
'event' => 'some-event',
|
|
|
|
|
'data' => json_encode(['data' => 'yes']),
|
|
|
|
|
])
|
|
|
|
|
->seeJson([
|
2020-09-10 19:59:26 +00:00
|
|
|
'ok' => true,
|
2020-08-24 06:03:52 +00:00
|
|
|
]);
|
2020-08-24 06:39:05 +00:00
|
|
|
|
2020-09-10 19:59:26 +00:00
|
|
|
if (method_exists($this->channelManager, 'getPublishClient')) {
|
|
|
|
|
$this->channelManager
|
|
|
|
|
->getPublishClient()
|
|
|
|
|
->assertCalledWithArgs('publish', [
|
|
|
|
|
$this->channelManager->getRedisKey('1234', 'test-channel'),
|
|
|
|
|
json_encode([
|
|
|
|
|
'channel' => 'test-channel',
|
|
|
|
|
'event' => 'some-event',
|
|
|
|
|
'data' => ['data' => 'yes'],
|
|
|
|
|
'appId' => '1234',
|
|
|
|
|
'serverId' => $this->channelManager->getServerId(),
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2020-08-24 06:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 19:59:26 +00:00
|
|
|
public function test_cant_send_message_for_invalid_app()
|
2020-08-24 06:03:52 +00:00
|
|
|
{
|
|
|
|
|
$this->actingAs(factory(User::class)->create())
|
|
|
|
|
->json('POST', route('laravel-websockets.event'), [
|
|
|
|
|
'appId' => '9999',
|
|
|
|
|
'channel' => 'test-channel',
|
|
|
|
|
'event' => 'some-event',
|
|
|
|
|
'data' => json_encode(['data' => 'yes']),
|
|
|
|
|
])
|
|
|
|
|
->assertResponseStatus(422);
|
|
|
|
|
}
|
|
|
|
|
}
|