adding a cart
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
2026-04-10 08:54:20 -06:00
parent ebf30d4f5f
commit d9cb44e93c
16 changed files with 559 additions and 39 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
use App\Models\Cart;
use App\Models\Product;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('a cart belongs to a user when one is set', function () {
$user = User::factory()->create();
$cart = Cart::factory()->create(['user_id' => $user->id]);
expect($cart->user->id)->toBe($user->id);
});
test('a cart can exist without a user', function () {
$cart = Cart::factory()->create(['user_id' => null]);
expect($cart->user)->toBeNull();
});
test('a user has one cart', function () {
$user = User::factory()->create();
Cart::factory()->create(['user_id' => $user->id]);
expect($user->cart)->toBeInstanceOf(Cart::class);
});
test('a cart can have products with quantities', function () {
$cart = Cart::factory()->create(['user_id' => null]);
$product = Product::factory()->create();
$cart->products()->attach($product->id, ['quantity' => 3]);
expect($cart->products)->toHaveCount(1);
expect($cart->products->first()->pivot->quantity)->toBe(3);
});