feat: harden tenant settings and import pipeline
This commit is contained in:
@@ -2,29 +2,26 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Resources\EmotionResource\Pages\ImportEmotions;
|
||||
use App\Models\Emotion;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use App\Services\EmotionImportService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmotionResourceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_import_emotions_csv()
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$csvData = "name_de,name_en,icon,color,description_de,description_en,sort_order,is_active,event_types\nGlück,Joy,😊,#FFD700,Gefühl des Glücks,Feeling of joy,1,1,wedding|birthday";
|
||||
$csvFile = UploadedFile::fake()->createWithContent('emotions.csv', $csvData);
|
||||
|
||||
Livewire::test(ImportEmotions::class)
|
||||
->set('file', $csvFile->getRealPath())
|
||||
->call('doImport');
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'emotions_');
|
||||
file_put_contents($tempFile, $csvData);
|
||||
|
||||
[$success, $failed] = app(EmotionImportService::class)->import($tempFile);
|
||||
|
||||
$this->assertSame(1, $success);
|
||||
$this->assertSame(0, $failed);
|
||||
|
||||
$this->assertDatabaseHas('emotions', [
|
||||
'name' => json_encode(['de' => 'Glück', 'en' => 'Joy']),
|
||||
|
||||
Reference in New Issue
Block a user