Phase 9 Block 1: Gelb-Routing Direkt-Live, Slot-Verbrauch bei Veroeffentlichung, Submit-Gate
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>
This commit is contained in:
parent
8d8d957884
commit
4419d9ff43
21 changed files with 551 additions and 114 deletions
|
|
@ -31,7 +31,7 @@ test('api create always produces a draft and ignores any status input', function
|
|||
->assertJsonPath('data.status', PressReleaseStatus::Draft->value);
|
||||
});
|
||||
|
||||
test('api submit route raises a draft to review and counts quota and writes a log', function () {
|
||||
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.
|
||||
|
||||
|
|
@ -50,12 +50,54 @@ test('api submit route raises a draft to review and counts quota and writes a lo
|
|||
->assertJsonPath('data.status', PressReleaseStatus::Review->value);
|
||||
|
||||
expect($pressRelease->fresh()->status)->toBe(PressReleaseStatus::Review);
|
||||
expect($user->fresh()->press_release_quota_used_this_month)->toBe(1);
|
||||
// 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']);
|
||||
|
|
|
|||
|
|
@ -166,11 +166,36 @@ test('classify job leaves a green scheduled press release in review for the sche
|
|||
expect($fresh->status)->toBe(PressReleaseStatus::Review);
|
||||
});
|
||||
|
||||
test('classify job keeps a yellow classification in the manual review queue', function () {
|
||||
test('classify job auto-publishes a yellow classification like green', function () {
|
||||
// Entscheidung 12.06.2026 (Decision-Update §5.0): Gelb geht direkt live,
|
||||
// es gibt keine manuelle Prüf-Queue — nur Rot wird abgelehnt.
|
||||
Mail::fake();
|
||||
fakeOpenAiClassification('yellow', ['grenzwertig']);
|
||||
|
||||
$pressRelease = PressRelease::factory()->create([
|
||||
'status' => PressReleaseStatus::Review->value,
|
||||
'scheduled_at' => null,
|
||||
'title' => 'Grenzfall',
|
||||
'text' => 'Inhalt',
|
||||
]);
|
||||
|
||||
(new ClassifyPressRelease($pressRelease->id))->handle(
|
||||
app(ClassificationManager::class),
|
||||
app(PressReleaseService::class),
|
||||
);
|
||||
|
||||
$fresh = $pressRelease->fresh();
|
||||
expect($fresh->classification)->toBe(PressReleaseClassification::Yellow);
|
||||
expect($fresh->status)->toBe(PressReleaseStatus::Published);
|
||||
Mail::assertQueued(PressReleasePublished::class);
|
||||
});
|
||||
|
||||
test('classify job leaves a yellow scheduled press release in review for the scheduler', function () {
|
||||
fakeOpenAiClassification('yellow', ['grenzwertig']);
|
||||
|
||||
$pressRelease = PressRelease::factory()->create([
|
||||
'status' => PressReleaseStatus::Review->value,
|
||||
'scheduled_at' => now()->addWeek(),
|
||||
'title' => 'Grenzfall',
|
||||
'text' => 'Inhalt',
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ test('customer show renders the publish confirmation modal with legal note and q
|
|||
->assertSee('2 / 3');
|
||||
});
|
||||
|
||||
test('submitting from the show modal moves the draft into review and counts quota', function () {
|
||||
test('submitting from the show modal moves the draft into review without consuming quota', function () {
|
||||
/** @var TestCase $this */
|
||||
['customer' => $customer, 'pr' => $pr] = makeCustomerForShowPhase8a();
|
||||
$customer->update(['press_release_quota' => 3, 'press_release_quota_used_this_month' => 0]);
|
||||
|
|
@ -39,5 +39,18 @@ test('submitting from the show modal moves the draft into review and counts quot
|
|||
->assertHasNoErrors();
|
||||
|
||||
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Review);
|
||||
expect($customer->fresh()->press_release_quota_used_this_month)->toBe(1);
|
||||
// Slot-Verbrauch erst bei Veröffentlichung (Decision-Update §3.2).
|
||||
expect($customer->fresh()->press_release_quota_used_this_month)->toBe(0);
|
||||
});
|
||||
|
||||
test('the modal shows a booking notice instead of the submit flow when the gate is enforced', function () {
|
||||
/** @var TestCase $this */
|
||||
config()->set('billing.enforce_booking', true);
|
||||
|
||||
['customer' => $customer, 'pr' => $pr] = makeCustomerForShowPhase8a();
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
|
||||
->assertSee('Buchung erforderlich')
|
||||
->assertDontSee('Mit dem Einreichen versichern Sie:');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
<?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 {
|
||||
|
|
@ -14,6 +17,20 @@ beforeEach(function (): void {
|
|||
$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,
|
||||
|
|
@ -23,29 +40,88 @@ test('remaining quota reflects the used counter', function () {
|
|||
expect($user->pressReleaseQuotaRemaining())->toBe(2);
|
||||
});
|
||||
|
||||
test('submitting a press release for review increments the monthly quota usage', function () {
|
||||
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');
|
||||
|
||||
$company = Company::factory()->presseecho()->create();
|
||||
$user->companies()->attach($company->id, ['role' => 'owner']);
|
||||
|
||||
$pr = PressRelease::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'category_id' => Category::factory()->create()->id,
|
||||
'portal' => $company->portal->value,
|
||||
'status' => 'draft',
|
||||
]);
|
||||
$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]);
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ test('Command publisht fällige Review-PMs mit scheduled_at <= now', function ()
|
|||
expect($fresh->published_at?->toDateTimeString())->toBe('2026-06-01 11:55:00');
|
||||
});
|
||||
|
||||
test('Command ignoriert fällige gelbe PMs (manuelle Prüfung)', function () {
|
||||
test('Command publisht fällige gelbe PMs wie grüne (Direkt-Live)', function () {
|
||||
/** @var TestCase $this */
|
||||
Carbon::setTestNow('2026-06-01 12:00:00');
|
||||
|
||||
|
|
@ -144,7 +144,23 @@ test('Command ignoriert fällige gelbe PMs (manuelle Prüfung)', function () {
|
|||
|
||||
Artisan::call(PublishScheduledPressReleases::class);
|
||||
|
||||
expect($yellow->fresh()->status)->toBe(PressReleaseStatus::Review);
|
||||
expect($yellow->fresh()->status)->toBe(PressReleaseStatus::Published);
|
||||
});
|
||||
|
||||
test('Command ignoriert fällige unklassifizierte PMs (Fallback: manuelle Queue)', function () {
|
||||
/** @var TestCase $this */
|
||||
Carbon::setTestNow('2026-06-01 12:00:00');
|
||||
|
||||
$unclassified = PressRelease::factory()->create([
|
||||
'status' => PressReleaseStatus::Review->value,
|
||||
'classification' => null,
|
||||
'scheduled_at' => '2026-06-01 11:55:00',
|
||||
'published_at' => null,
|
||||
]);
|
||||
|
||||
Artisan::call(PublishScheduledPressReleases::class);
|
||||
|
||||
expect($unclassified->fresh()->status)->toBe(PressReleaseStatus::Review);
|
||||
});
|
||||
|
||||
test('Command ignoriert PMs mit scheduled_at in der Zukunft', function () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue