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>
133 lines
4.3 KiB
PHP
133 lines
4.3 KiB
PHP
<?php
|
|
|
|
use App\Console\Commands\ResetMonthlyPressReleaseQuota;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\PressRelease;
|
|
use App\Models\User;
|
|
use App\Services\PressRelease\PressReleaseService;
|
|
use App\Services\PressRelease\QuotaExceededException;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\TestCase;
|
|
|
|
beforeEach(function (): void {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
});
|
|
|
|
function quotaTestPressRelease(User $user, string $status = 'draft'): PressRelease
|
|
{
|
|
$company = Company::factory()->presseecho()->create();
|
|
$user->companies()->attach($company->id, ['role' => 'owner']);
|
|
|
|
return PressRelease::factory()->create([
|
|
'user_id' => $user->id,
|
|
'company_id' => $company->id,
|
|
'category_id' => Category::factory()->create()->id,
|
|
'portal' => $company->portal->value,
|
|
'status' => $status,
|
|
]);
|
|
}
|
|
|
|
test('remaining quota reflects the used counter', function () {
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 1,
|
|
]);
|
|
|
|
expect($user->pressReleaseQuotaRemaining())->toBe(2);
|
|
});
|
|
|
|
test('submitting a press release does not consume a quota slot', function () {
|
|
// Decision-Update §3.2: Der Slot zählt erst bei Veröffentlichung runter.
|
|
Queue::fake();
|
|
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 0,
|
|
]);
|
|
$user->assignRole('customer');
|
|
|
|
$pr = quotaTestPressRelease($user);
|
|
|
|
app(PressReleaseService::class)->submitForReview($pr);
|
|
|
|
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Review);
|
|
expect($user->fresh()->press_release_quota_used_this_month)->toBe(0);
|
|
});
|
|
|
|
test('publishing consumes exactly one quota slot', function () {
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 0,
|
|
]);
|
|
$user->assignRole('customer');
|
|
|
|
$pr = quotaTestPressRelease($user, 'review');
|
|
|
|
app(PressReleaseService::class)->publish($pr);
|
|
|
|
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Published);
|
|
expect($user->fresh()->press_release_quota_used_this_month)->toBe(1);
|
|
});
|
|
|
|
test('re-publishing after archive does not consume a second slot', function () {
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 0,
|
|
]);
|
|
$user->assignRole('customer');
|
|
|
|
$pr = quotaTestPressRelease($user, 'review');
|
|
$service = app(PressReleaseService::class);
|
|
|
|
$service->publish($pr);
|
|
$service->archive($pr->fresh());
|
|
$service->changeStatusFromAdmin($pr->fresh(), PressReleaseStatus::Published);
|
|
|
|
expect($user->fresh()->press_release_quota_used_this_month)->toBe(1);
|
|
});
|
|
|
|
test('a rejected press release does not consume a quota slot', function () {
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 0,
|
|
]);
|
|
$user->assignRole('customer');
|
|
|
|
$pr = quotaTestPressRelease($user, 'review');
|
|
|
|
app(PressReleaseService::class)->reject($pr, 'Unzulässiger Inhalt.', 'ki');
|
|
|
|
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Rejected);
|
|
expect($user->fresh()->press_release_quota_used_this_month)->toBe(0);
|
|
});
|
|
|
|
test('submitting with an exhausted quota is blocked', function () {
|
|
Queue::fake();
|
|
|
|
$user = User::factory()->create([
|
|
'press_release_quota' => 3,
|
|
'press_release_quota_used_this_month' => 3,
|
|
]);
|
|
$user->assignRole('customer');
|
|
|
|
$pr = quotaTestPressRelease($user);
|
|
|
|
expect(fn () => app(PressReleaseService::class)->submitForReview($pr))
|
|
->toThrow(QuotaExceededException::class);
|
|
|
|
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Draft);
|
|
});
|
|
|
|
test('monthly reset command zeroes the used counter', function () {
|
|
User::factory()->count(2)->create(['press_release_quota_used_this_month' => 2]);
|
|
$untouched = User::factory()->create(['press_release_quota_used_this_month' => 0]);
|
|
|
|
$this->artisan(ResetMonthlyPressReleaseQuota::class)->assertSuccessful();
|
|
|
|
expect(User::where('press_release_quota_used_this_month', '>', 0)->count())->toBe(0);
|
|
expect($untouched->fresh()->press_release_quota_used_this_month)->toBe(0);
|
|
});
|