Files
portal/app/tests/Feature/Project/ProjectUpdateDedupTest.php
T

29 lines
1.4 KiB
PHP
Raw Normal View History

2026-05-21 07:35:11 +03:00
<?php
declare(strict_types=1);
use App\Models\Tenant;
use App\Services\Project\ProjectService;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Queue;
beforeEach(fn () => Queue::fake());
it('blocks update that collides source with another project of same tenant', function () {
$tenant = Tenant::factory()->create(['balance_leads' => 100]);
$svc = app(ProjectService::class);
$a = $svc->create($tenant, ['name' => 'A', 'signal_type' => 'call', 'signal_identifier' => '79991110000', 'daily_limit_target' => 5, 'regions' => [], 'delivery_days_mask' => 31]);
$b = $svc->create($tenant, ['name' => 'B', 'signal_type' => 'call', 'signal_identifier' => '79992220000', 'daily_limit_target' => 5, 'regions' => [], 'delivery_days_mask' => 31]);
expect(fn () => $svc->update($b, ['signal_identifier' => '79991110000']))
->toThrow(HttpResponseException::class);
});
it('allows update keeping same source on the same project', function () {
$tenant = Tenant::factory()->create(['balance_leads' => 100]);
$svc = app(ProjectService::class);
$a = $svc->create($tenant, ['name' => 'A', 'signal_type' => 'call', 'signal_identifier' => '79991110000', 'daily_limit_target' => 5, 'regions' => [], 'delivery_days_mask' => 31]);
$updated = $svc->update($a, ['signal_identifier' => '79991110000', 'daily_limit_target' => 7]);
expect($updated->daily_limit_target)->toBe(7);
});