- /api/v1/kleinanzeigen: Liste mit Filtern, meta, meine, Anzeige, Formular, aufgeben/speichern mit Fotos, löschen, verlängern/erledigt/reserviert, Merkliste, Kontakt (Chat mit conversation_id oder E-Mail), Melden, Fotos mit Token - Foto-Adressen zeigen bei API-Aufrufen auf die API Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
66 lines
2.7 KiB
PHP
66 lines
2.7 KiB
PHP
<?php
|
||
|
||
namespace Tests\Plugins\Kleinanzeigen;
|
||
|
||
use App\Models\User;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Inertia\Testing\AssertableInertia as Assert;
|
||
use Inhaus\Plugins\Kleinanzeigen\Models\Listing;
|
||
use Laravel\Sanctum\Sanctum;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Kontakt über das Chat-Plugin – nur, wenn es in dieser Installation liegt (plugins/chat).
|
||
*/
|
||
class ChatContactTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
private ?string $previousState = null;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
$file = getcwd().'/storage/app/plugins.json';
|
||
$this->previousState = is_file($file) ? file_get_contents($file) : null;
|
||
$state = json_decode($this->previousState ?? '{}', true) ?: [];
|
||
$state['kleinanzeigen'] = ['enabled' => true];
|
||
$state['chat'] = ['enabled' => true];
|
||
file_put_contents($file, json_encode($state));
|
||
|
||
parent::setUp();
|
||
|
||
if (! is_dir(base_path('plugins/chat'))) {
|
||
$this->markTestSkipped('Chat-Plugin nicht installiert.');
|
||
}
|
||
|
||
Storage::fake('local');
|
||
}
|
||
|
||
protected function tearDown(): void
|
||
{
|
||
$file = storage_path('app/plugins.json');
|
||
$this->previousState === null ? @unlink($file) : file_put_contents($file, $this->previousState);
|
||
|
||
parent::tearDown();
|
||
}
|
||
|
||
public function test_contact_opens_a_chat_with_the_seller(): void
|
||
{
|
||
$seller = User::factory()->create();
|
||
$buyer = User::factory()->create();
|
||
$listing = Listing::query()->create(['user_id' => $seller->id, 'type' => 'give', 'category' => 'moebel', 'title' => 'Sofa', 'description' => 'Abholen in Mainz', 'status' => 'active', 'published_at' => now(), 'expires_at' => now()->addDays(5)]);
|
||
|
||
$this->actingAs($buyer)->get("/kleinanzeigen/{$listing->id}")->assertInertia(fn (Assert $p) => $p->where('listing.contact', 'chat'));
|
||
$location = $this->actingAs($buyer)->post("/kleinanzeigen/{$listing->id}/kontakt", ['message' => 'Kann ich es Samstag holen?'])->assertRedirect()->headers->get('Location');
|
||
$this->assertMatchesRegularExpression('#/chat/\d+$#', $location);
|
||
|
||
$this->actingAs($seller)->getJson('/chat/api/gespraeche/'.basename($location).'/nachrichten')->assertOk()
|
||
->assertJsonPath('messages.0.body', "Zu deiner Anzeige „Sofa“:\n".route('kleinanzeigen.show', $listing)."\n\nKann ich es Samstag holen?");
|
||
|
||
// App: dasselbe Gespräch, die App öffnet es direkt
|
||
Sanctum::actingAs($buyer);
|
||
$this->postJson("/api/v1/kleinanzeigen/{$listing->id}/kontakt", ['message' => 'Und Sonntag?'])->assertOk()
|
||
->assertJsonPath('via', 'chat')->assertJsonPath('conversation_id', (int) basename($location));
|
||
}
|
||
}
|