9A — Gelb geht direkt live (Entscheidung 12.06.2026): - routeByClassification(): Gelb durchlaeuft denselben Auto-Publish-Pfad wie Gruen (autoPublishApproved); nur Rot wird abgelehnt - Scheduler publiziert faellige gelbe + gruene PMs; unklassifizierte bleiben als Fallback in der manuellen Queue 9B — Slot-Verbrauch bei Veroeffentlichung (Decision-Update 3.2): - Increment aus submitForReview() entfernt; publish() und changeStatusFromAdmin() zaehlen idempotent beim ersten published-Uebergang (Pruefung ueber Status-Logs); Rot kostet nichts - Submit-Guard: Einreichen erfordert freien Slot (QuotaExceededException, API 422) 9C — Submit-Gate vorbereitet (Decision-Update 5.1): - User::hasActiveBooking()-Stub hinter config/billing.php (enforce_booking, Default aus); Tarif-Modul ersetzt nur den Rumpf - Einreichungs-Modal zeigt ohne Buchung einen Buchungs-Hinweis; Server-Guard (BookingRequiredException), API antwortet 402 - Fix: Customer-Create legte PMs bei "Zur Pruefung senden" direkt mit Status review an (vorbei an Blacklist/Quota/KI/Status-Log) — laeuft jetzt immer ueber submitForReview() Suite: 451 passed, 4 skipped (9 neue Tests). Pint clean. Plan: docs/PHASE-9-FLOW-UND-TARIFE-PLAN.md (Block 2 nach Review-Stopp). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
161 lines
5.5 KiB
PHP
161 lines
5.5 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\PressRelease;
|
|
use App\Models\PressReleaseStatusLog;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
test('api create always produces a draft and ignores any status input', function () {
|
|
/** @var TestCase $this */
|
|
$user = User::factory()->create();
|
|
$company = Company::factory()->presseecho()->create();
|
|
$category = Category::factory()->withTranslations()->create();
|
|
$user->companies()->attach($company->id, ['role' => 'owner']);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson('/api/v1/press-releases', [
|
|
'company_id' => $company->id,
|
|
'category_id' => $category->id,
|
|
'language' => 'de',
|
|
'title' => 'API Entwurf',
|
|
'text' => 'Inhalt',
|
|
'status' => 'review', // soll ignoriert werden
|
|
])
|
|
->assertCreated()
|
|
->assertJsonPath('data.status', PressReleaseStatus::Draft->value);
|
|
});
|
|
|
|
test('api submit route raises a draft to review without consuming quota and writes a log', function () {
|
|
/** @var TestCase $this */
|
|
Queue::fake(); // Klassifikations-Routing separat getestet; hier nur der Submit-Übergang.
|
|
|
|
$user = User::factory()->create(['press_release_quota_used_this_month' => 0]);
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Saubere Pressemitteilung',
|
|
'text' => 'Vollkommen unauffälliger Inhalt.',
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertOk()
|
|
->assertJsonPath('data.status', PressReleaseStatus::Review->value);
|
|
|
|
expect($pressRelease->fresh()->status)->toBe(PressReleaseStatus::Review);
|
|
// Slot-Verbrauch erst bei Veröffentlichung (Decision-Update §3.2).
|
|
expect($user->fresh()->press_release_quota_used_this_month)->toBe(0);
|
|
expect(PressReleaseStatusLog::where('press_release_id', $pressRelease->id)
|
|
->where('to_status', PressReleaseStatus::Review->value)
|
|
->exists())->toBeTrue();
|
|
});
|
|
|
|
test('api submit responds 402 when the booking gate is enforced', function () {
|
|
/** @var TestCase $this */
|
|
config()->set('billing.enforce_booking', true);
|
|
|
|
$user = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Saubere Pressemitteilung',
|
|
'text' => 'Inhalt',
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertStatus(402);
|
|
|
|
expect($pressRelease->fresh()->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|
|
|
|
test('api submit responds 422 when the monthly quota is exhausted', function () {
|
|
/** @var TestCase $this */
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 3,
|
|
]);
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Saubere Pressemitteilung',
|
|
'text' => 'Inhalt',
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertStatus(422);
|
|
|
|
expect($pressRelease->fresh()->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|
|
|
|
test('api submit auto-rejects a press release containing a banned word', function () {
|
|
/** @var TestCase $this */
|
|
config()->set('blacklist.words', ['penis']);
|
|
|
|
$user = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Unzulässiger Titel penis',
|
|
'text' => 'Inhalt',
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertStatus(422);
|
|
|
|
expect($pressRelease->fresh()->status)->toBe(PressReleaseStatus::Rejected);
|
|
});
|
|
|
|
test('api submit requires the write ability', function () {
|
|
/** @var TestCase $this */
|
|
$user = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:read']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertForbidden();
|
|
});
|
|
|
|
test('api submit rejects a press release already in review', function () {
|
|
/** @var TestCase $this */
|
|
$user = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->inReview()->create([
|
|
'user_id' => $user->id,
|
|
]);
|
|
|
|
Sanctum::actingAs($user, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertStatus(409);
|
|
});
|
|
|
|
test('api user cannot submit another users press release', function () {
|
|
/** @var TestCase $this */
|
|
$owner = User::factory()->create();
|
|
$otherUser = User::factory()->create();
|
|
$pressRelease = PressRelease::factory()->create([
|
|
'user_id' => $owner->id,
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
]);
|
|
|
|
Sanctum::actingAs($otherUser, ['press-releases:write']);
|
|
|
|
$this->postJson("/api/v1/press-releases/{$pressRelease->id}/submit")
|
|
->assertForbidden();
|
|
});
|