9daa94d917
Spec §6.1: ежедневный сброс projects.delivered_today=0 после midnight МСК.
delivered_in_month НЕ трогаем (это месячный счётчик, Plan 4 cron).
Реализация: Artisan-команда `projects:reset-delivered-today` (idempotent
UPDATE без транзакции/локов — отрабатывает за <1 сек), Schedule в
routes/console.php с dailyAt('00:00')->timezone('Europe/Moscow').
NB: `withoutOverlapping()` пропущен — требует таблицу cache_locks, которой
нет в schema.sql (Laravel-default-миграции удалены в фазе 1). Идемпотентность
UPDATE делает overlap-защиту избыточной.
Tests: 2/2 pass, phpstan 0 errors (1 baseline для $this->artisan, как у
прочих Pest-тестов с artisan-helper).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Project;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
beforeEach(function () {
|
|
DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
|
|
});
|
|
|
|
test('resets delivered_today to 0 across all tenants', function () {
|
|
$t1 = Tenant::factory()->create();
|
|
$t2 = Tenant::factory()->create();
|
|
|
|
Project::factory()->create(['tenant_id' => $t1->id, 'delivered_today' => 5]);
|
|
Project::factory()->create(['tenant_id' => $t1->id, 'delivered_today' => 3]);
|
|
Project::factory()->create(['tenant_id' => $t2->id, 'delivered_today' => 10]);
|
|
|
|
$this->artisan('projects:reset-delivered-today')->assertSuccessful();
|
|
|
|
$row = DB::selectOne('SELECT COUNT(*) FILTER (WHERE delivered_today = 0) AS c, COUNT(*) AS total FROM projects');
|
|
expect($row->c)->toBe($row->total);
|
|
});
|
|
|
|
test('does not touch delivered_in_month', function () {
|
|
$t = Tenant::factory()->create();
|
|
Project::factory()->create([
|
|
'tenant_id' => $t->id,
|
|
'delivered_today' => 5,
|
|
'delivered_in_month' => 50,
|
|
]);
|
|
|
|
$this->artisan('projects:reset-delivered-today')->assertSuccessful();
|
|
|
|
$row = DB::selectOne('SELECT delivered_today, delivered_in_month FROM projects ORDER BY id DESC LIMIT 1');
|
|
expect((int) $row->delivered_today)->toBe(0);
|
|
expect((int) $row->delivered_in_month)->toBe(50);
|
|
});
|