2026-05-11 11:28:03 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Supplier;
|
|
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
|
|
|
2026-06-25 08:19:53 +03:00
|
|
|
|
it('GET /api/admin/suppliers returns B1/B2/B3 suppliers', function () {
|
|
|
|
|
|
// NB: с фазы 3 в suppliers есть и псевдо-поставщик 'direct' (DIRECT-лиды,
|
|
|
|
|
|
// миграция 2026_05_25_120100), поэтому проверяем наличие закупочных b1/b2/b3,
|
|
|
|
|
|
// а не строгий счёт. Если 'direct' не должен быть в этом списке — это правка
|
|
|
|
|
|
// контроллера (фильтр), решение владельца, не тест.
|
2026-05-11 11:28:03 +03:00
|
|
|
|
$response = $this->getJson('/api/admin/suppliers');
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 08:19:53 +03:00
|
|
|
|
$codes = collect($response->json('data'))->pluck('code')->all();
|
|
|
|
|
|
expect($codes)->toContain('b1', 'b2', 'b3');
|
2026-05-11 11:28:03 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('PATCH updates cost_rub for supplier', function () {
|
|
|
|
|
|
$b1 = Supplier::where('code', 'b1')->first();
|
|
|
|
|
|
$oldCost = (string) $b1->cost_rub;
|
|
|
|
|
|
|
|
|
|
|
|
$this->patchJson("/api/admin/suppliers/{$b1->id}", ['cost_rub' => '1.50'])
|
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
|
|
expect((string) $b1->fresh()->cost_rub)->toBe('1.50');
|
|
|
|
|
|
expect((string) $b1->fresh()->cost_rub)->not->toBe($oldCost);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('PATCH validates cost_rub >= 0', function () {
|
|
|
|
|
|
$b1 = Supplier::where('code', 'b1')->first();
|
|
|
|
|
|
|
|
|
|
|
|
$this->patchJson("/api/admin/suppliers/{$b1->id}", ['cost_rub' => '-1.00'])
|
|
|
|
|
|
->assertStatus(422);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('PATCH writes saas_admin_audit_log row', function () {
|
|
|
|
|
|
$b1 = Supplier::where('code', 'b1')->first();
|
|
|
|
|
|
|
|
|
|
|
|
$this->patchJson("/api/admin/suppliers/{$b1->id}", ['cost_rub' => '2.00'])
|
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
|
|
$log = DB::table('saas_admin_audit_log')
|
|
|
|
|
|
->where('action', 'suppliers.update')->first();
|
|
|
|
|
|
expect($log)->not->toBeNull();
|
|
|
|
|
|
});
|