Nachrichten 1.1.0: Schnittstelle für die App, Verbindung prüfen
- /api/v1/chat: config, Gruppenchats, verlassen, bearbeiten, löschen, Reaktionen, „Gibt es Neues?“, „schreibt …“, GIFs, Echtzeit-Anmeldung und Anhänge mit Token - Anhang-Adressen zeigen bei API-Aufrufen auf die API (Token statt Sitzung) - Backend: „Echtzeit prüfen“ und „GIPHY prüfen“ melden sofort, ob die Zugangsdaten stimmen - README: Schritt-für-Schritt-Einrichtung für pusher.com und GIPHY Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2844452002
commit
5f71c3e250
9 changed files with 207 additions and 26 deletions
|
|
@ -13,10 +13,12 @@ use Illuminate\Support\Facades\Http;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Chat\Gifs;
|
||||
use Inhaus\Plugins\Chat\Models\Conversation;
|
||||
use Inhaus\Plugins\Chat\Models\Gif;
|
||||
use Inhaus\Plugins\Chat\Models\Message;
|
||||
use Inhaus\Plugins\Chat\Realtime;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -206,4 +208,42 @@ class ChatTest extends TestCase
|
|||
->assertOk()->assertJsonPath('auth', 'k:'.hash_hmac('sha256', '123.456:'.Realtime::channel($ada->id), 's3cret'));
|
||||
$this->actingAs($ada)->postJson('/chat/api/echtzeit/anmelden', ['socket_id' => '123.456', 'channel_name' => Realtime::channel($bob->id)])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_connection_checks_for_realtime_and_giphy(): void
|
||||
{
|
||||
$realtime = app(Realtime::class);
|
||||
$this->assertFalse($realtime->check()['ok']);
|
||||
|
||||
app(Settings::class)->setMany(['chat.realtime.enabled' => true, 'chat.realtime.app_id' => '42', 'chat.realtime.key' => 'k', 'chat.realtime.secret' => Crypt::encryptString('s3cret'), 'chat.realtime.host' => 'ws.example.org']);
|
||||
Http::fake(['ws.example.org/apps/42/channels*' => Http::sequence()->push(['channels' => []])->push(['error' => 'Invalid signature'], 401)]);
|
||||
$this->assertTrue($realtime->check()['ok']);
|
||||
$this->assertStringContainsString('Key und Secret', $realtime->check()['message']);
|
||||
Http::assertSent(fn ($r) => $r->method() === 'GET' && str_contains($r->url(), 'auth_signature=') && ! str_contains($r->url(), 'body_md5'));
|
||||
|
||||
$gifs = app(Gifs::class);
|
||||
$this->assertFalse($gifs->checkGiphy()['ok']);
|
||||
app(Settings::class)->set('chat.giphy_key', Crypt::encryptString('gk'));
|
||||
Http::fake(['api.giphy.com/*' => Http::sequence()->push(['data' => []])->push(['message' => 'Unauthorized'], 401)]);
|
||||
$this->assertTrue($gifs->checkGiphy()['ok']);
|
||||
$this->assertFalse($gifs->checkGiphy()['ok']);
|
||||
}
|
||||
|
||||
public function test_app_api_with_token(): void
|
||||
{
|
||||
[$ada, $bob] = User::factory()->count(2)->create()->all();
|
||||
Sanctum::actingAs($ada);
|
||||
|
||||
$this->getJson('/api/v1/chat/config')->assertOk()->assertJsonPath('me.id', $ada->id)->assertJsonPath('realtime', null)->assertJsonPath('can_create_groups', false);
|
||||
$id = $this->postJson('/api/v1/chat/direct', ['user_id' => $bob->id])->assertOk()->json('id');
|
||||
$url = $this->post("/api/v1/chat/conversations/{$id}/messages", ['body' => 'Hallo aus der App', 'files' => [UploadedFile::fake()->image('foto.jpg', 40, 40)]], ['Accept' => 'application/json'])
|
||||
->assertCreated()->json('message.attachments.0.url');
|
||||
$this->assertStringContainsString('/api/v1/chat/attachments/', $url);
|
||||
$this->get($url)->assertOk();
|
||||
|
||||
$this->getJson('/api/v1/chat/updates?offen='.$id)->assertOk()->assertJsonPath('messages.0.body', 'Hallo aus der App');
|
||||
$this->getJson('/api/v1/chat/conversations')->assertJsonPath('conversations.0.person.id', $bob->id);
|
||||
|
||||
Sanctum::actingAs(User::factory()->create());
|
||||
$this->get($url)->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue