67 lines
2.5 KiB
PHP
67 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Jobs\SyncSupplierProjectJob;
|
||
|
|
use App\Models\PricingTier;
|
||
|
|
use App\Models\Tenant;
|
||
|
|
use App\Services\Project\ProjectService;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
use Illuminate\Support\Facades\Queue;
|
||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class);
|
||
|
|
uses(SharesSupplierPdo::class);
|
||
|
|
|
||
|
|
beforeEach(function () {
|
||
|
|
PricingTier::create([
|
||
|
|
'tier_no' => 1,
|
||
|
|
'leads_in_tier' => null,
|
||
|
|
'price_per_lead_kopecks' => 10000,
|
||
|
|
'is_active' => true,
|
||
|
|
'effective_from' => now()->toDateString(),
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('creates paused and blocked, no supplier sync, when balance insufficient', function () {
|
||
|
|
Queue::fake();
|
||
|
|
$t = Tenant::factory()->create(['balance_rub' => '100.00', 'delivered_in_month' => 0]); // 1 лид ёмкость
|
||
|
|
$p = app(ProjectService::class)->create($t, [
|
||
|
|
'name' => 'X', 'signal_type' => 'site', 'signal_identifier' => 'x.ru',
|
||
|
|
'daily_limit_target' => 5, 'delivery_days_mask' => 127,
|
||
|
|
], launch: true);
|
||
|
|
|
||
|
|
expect($p->is_active)->toBeFalse();
|
||
|
|
expect($p->preflight_blocked_at)->not->toBeNull();
|
||
|
|
expect($p->launch_deferred)->toBeTrue();
|
||
|
|
expect($p->gate_payload['deficit_leads'])->toBe(4);
|
||
|
|
Queue::assertNotPushed(SyncSupplierProjectJob::class);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('creates active and syncs when balance sufficient', function () {
|
||
|
|
Queue::fake();
|
||
|
|
$t = Tenant::factory()->create(['balance_rub' => '1000.00', 'delivered_in_month' => 0]);
|
||
|
|
$p = app(ProjectService::class)->create($t, [
|
||
|
|
'name' => 'Y', 'signal_type' => 'site', 'signal_identifier' => 'y.ru',
|
||
|
|
'daily_limit_target' => 5, 'delivery_days_mask' => 127,
|
||
|
|
], launch: true);
|
||
|
|
|
||
|
|
expect($p->is_active)->toBeTrue();
|
||
|
|
expect($p->launch_deferred)->toBeFalse();
|
||
|
|
Queue::assertPushed(SyncSupplierProjectJob::class);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('creates draft paused without gate when launch=false', function () {
|
||
|
|
Queue::fake();
|
||
|
|
$t = Tenant::factory()->create(['balance_rub' => '0.00', 'delivered_in_month' => 0]);
|
||
|
|
$p = app(ProjectService::class)->create($t, [
|
||
|
|
'name' => 'Z', 'signal_type' => 'site', 'signal_identifier' => 'z.ru',
|
||
|
|
'daily_limit_target' => 5, 'delivery_days_mask' => 127,
|
||
|
|
], launch: false);
|
||
|
|
|
||
|
|
expect($p->is_active)->toBeFalse();
|
||
|
|
expect($p->preflight_blocked_at)->toBeNull(); // черновик, не «удержан балансом»
|
||
|
|
expect($p->launch_deferred)->toBeFalse();
|
||
|
|
Queue::assertNotPushed(SyncSupplierProjectJob::class);
|
||
|
|
});
|