adding a cart
This commit is contained in:
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user