47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Models\Supplier;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class);
|
||
|
|
|
||
|
|
it('GET /api/admin/suppliers returns 3 suppliers B1/B2/B3', function () {
|
||
|
|
$response = $this->getJson('/api/admin/suppliers');
|
||
|
|
$response->assertOk();
|
||
|
|
$data = $response->json('data');
|
||
|
|
expect($data)->toHaveCount(3);
|
||
|
|
expect(collect($data)->pluck('code')->all())->toContain('b1', 'b2', 'b3');
|
||
|
|
});
|
||
|
|
|
||
|
|
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();
|
||
|
|
});
|