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?"); } }