66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use App\Models\Warehouse;
|
|
use App\Models\StockMove;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class StockMoveApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Sanctum::actingAs(User::factory()->create());
|
|
}
|
|
|
|
public function test_can_list_stock_moves(): void
|
|
{
|
|
StockMove::factory()->count(2)->create();
|
|
|
|
$response = $this->getJson('/api/stock-moves');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonCount(2, 'data');
|
|
}
|
|
|
|
public function test_can_create_stock_move(): void
|
|
{
|
|
$product = Product::factory()->create();
|
|
$warehouse = Warehouse::factory()->create();
|
|
|
|
$data = [
|
|
'product_id' => $product->id,
|
|
'to_warehouse_id' => $warehouse->id,
|
|
'qty_base' => 10,
|
|
'move_type' => 'receipt',
|
|
'moved_at' => now()->toDateTimeString(),
|
|
];
|
|
|
|
$response = $this->postJson('/api/stock-moves', $data);
|
|
|
|
$response->assertStatus(201)
|
|
->assertJsonPath('data.qty_base', 10);
|
|
|
|
$this->assertDatabaseHas('stock_moves', [
|
|
'product_id' => $product->id,
|
|
'qty_base' => 10
|
|
]);
|
|
}
|
|
|
|
public function test_valide_french_messages_for_stock_move(): void
|
|
{
|
|
$response = $this->postJson('/api/stock-moves', []);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors(['product_id', 'qty_base', 'move_type'])
|
|
->assertJsonFragment(['product_id' => ['Le produit est requis.']]);
|
|
}
|
|
}
|