create(); $response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $response->assertOk(); $response->assertJsonPath('songs.0.title', 'Test'); $song = Song::where('title', 'Test')->first(); $this->assertNotNull($song); $this->assertSame(4, $song->groups()->count()); $this->assertSame(5, $song->groups()->withCount('slides')->get()->sum('slides_count')); $this->assertSame(2, $song->arrangements()->count()); $this->assertTrue($song->has_translation); } public function test_import_pro_ohne_ccli_erstellt_neuen_song(): void { $user = User::factory()->create(); $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $this->assertSame(1, Song::count()); $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $this->assertSame(2, Song::count()); } public function test_import_pro_upsert_mit_ccli_dupliziert_nicht(): void { $user = User::factory()->create(); $existingSong = Song::create([ 'title' => 'Old Title', 'ccli_id' => '999', ]); $existingSong->groups()->create(['name' => 'Old Group', 'color' => '#FF0000', 'order' => 0]); $this->assertSame(1, $existingSong->groups()->count()); $existingSong->update(['ccli_id' => '999']); $this->assertSame(1, Song::count()); $response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $response->assertOk(); $this->assertSame(2, Song::count()); } public function test_import_pro_lehnt_ungueltige_datei_ab(): void { $user = User::factory()->create(); $invalidFile = UploadedFile::fake()->create('test.txt', 100); $response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $invalidFile, ]); $response->assertStatus(422); } public function test_import_pro_erfordert_authentifizierung(): void { $response = $this->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $response->assertUnauthorized(); } public function test_import_pro_erstellt_arrangement_gruppen(): void { $user = User::factory()->create(); $this->actingAs($user)->postJson(route('api.songs.import-pro'), [ 'file' => $this->testProFile(), ]); $song = Song::where('title', 'Test')->first(); $normalArrangement = $song->arrangements()->where('name', 'normal')->first(); $this->assertNotNull($normalArrangement); $this->assertTrue($normalArrangement->is_default); $this->assertSame(5, $normalArrangement->arrangementGroups()->count()); } }