Kleinanzeigen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
f05c44733f
50 changed files with 3854 additions and 0 deletions
60
tests/ChatContactTest.php
Normal file
60
tests/ChatContactTest.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?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 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?");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue