pp-planer/tests/Feature/ServiceSongControllerTest.php
Thorsten Bus 7a29a21822 feat: confirm-state for service songs + service-edit UX fixes
- add explicit confirmed_at assignment state (red/amber/green) with confirm/unconfirm endpoints
- clone leader arrangement before opening dialog to avoid flicker
- agenda slide strip: show all previews, drag-reorder, number badges, auto-hide uploader
- fix info-slide expire-date saving via axios (was rendering raw JSON modal)
- point top-left logo to / instead of /dashboard
2026-06-21 11:53:55 +02:00

141 lines
4.5 KiB
PHP

<?php
use App\Models\ServiceSong;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\User;
/*
|--------------------------------------------------------------------------
| ServiceSongController — confirm/unconfirm + Reset-Logik
|--------------------------------------------------------------------------
*/
test('POST /api/service-songs/{id}/confirm setzt confirmed_at', function () {
$user = User::factory()->create();
$song = Song::factory()->create();
$serviceSong = ServiceSong::factory()->create([
'song_id' => $song->id,
'confirmed_at' => null,
]);
$response = $this->actingAs($user)
->postJson("/api/service-songs/{$serviceSong->id}/confirm");
$response->assertOk()
->assertJson(['success' => true]);
$serviceSong->refresh();
expect($serviceSong->confirmed_at)->not->toBeNull();
});
test('POST /api/service-songs/{id}/unconfirm setzt confirmed_at auf null', function () {
$user = User::factory()->create();
$song = Song::factory()->create();
$serviceSong = ServiceSong::factory()->create([
'song_id' => $song->id,
'confirmed_at' => now(),
]);
$response = $this->actingAs($user)
->postJson("/api/service-songs/{$serviceSong->id}/unconfirm");
$response->assertOk()
->assertJson(['success' => true]);
$serviceSong->refresh();
expect($serviceSong->confirmed_at)->toBeNull();
});
test('confirm/unconfirm erfordern Authentifizierung', function () {
$serviceSong = ServiceSong::factory()->create();
$this->postJson("/api/service-songs/{$serviceSong->id}/confirm")
->assertUnauthorized();
$this->postJson("/api/service-songs/{$serviceSong->id}/unconfirm")
->assertUnauthorized();
});
test('assign setzt confirmed_at zurueck', function () {
$user = User::factory()->create();
$oldSong = Song::factory()->create();
$newSong = Song::factory()->create();
$serviceSong = ServiceSong::factory()->create([
'song_id' => $oldSong->id,
'confirmed_at' => now(),
]);
$this->actingAs($user)
->postJson("/api/service-songs/{$serviceSong->id}/assign", [
'song_id' => $newSong->id,
])
->assertOk();
$serviceSong->refresh();
expect($serviceSong->song_id)->toBe($newSong->id);
expect($serviceSong->confirmed_at)->toBeNull();
});
test('unassign setzt confirmed_at zurueck', function () {
$user = User::factory()->create();
$song = Song::factory()->create();
$serviceSong = ServiceSong::factory()->create([
'song_id' => $song->id,
'confirmed_at' => now(),
]);
$this->actingAs($user)
->postJson("/api/service-songs/{$serviceSong->id}/unassign")
->assertOk();
$serviceSong->refresh();
expect($serviceSong->song_id)->toBeNull();
expect($serviceSong->confirmed_at)->toBeNull();
});
test('Aenderung des Arrangements setzt confirmed_at zurueck', function () {
$user = User::factory()->create();
$song = Song::factory()->create();
$arrA = SongArrangement::factory()->create(['song_id' => $song->id, 'name' => 'A']);
$arrB = SongArrangement::factory()->create(['song_id' => $song->id, 'name' => 'B']);
$serviceSong = ServiceSong::factory()->create([
'song_id' => $song->id,
'song_arrangement_id' => $arrA->id,
'confirmed_at' => now(),
]);
$this->actingAs($user)
->patchJson("/api/service-songs/{$serviceSong->id}", [
'song_arrangement_id' => $arrB->id,
])
->assertOk();
$serviceSong->refresh();
expect($serviceSong->song_arrangement_id)->toBe($arrB->id);
expect($serviceSong->confirmed_at)->toBeNull();
});
test('reine use_translation Aenderung setzt confirmed_at NICHT zurueck', function () {
$user = User::factory()->create();
$song = Song::factory()->create(['has_translation' => true]);
$arr = SongArrangement::factory()->create(['song_id' => $song->id, 'name' => 'A']);
$confirmedAt = now()->subHour();
$serviceSong = ServiceSong::factory()->create([
'song_id' => $song->id,
'song_arrangement_id' => $arr->id,
'use_translation' => false,
'confirmed_at' => $confirmedAt,
]);
$this->actingAs($user)
->patchJson("/api/service-songs/{$serviceSong->id}", [
'use_translation' => true,
])
->assertOk();
$serviceSong->refresh();
expect($serviceSong->use_translation)->toBeTrue();
expect($serviceSong->confirmed_at)->not->toBeNull();
});