diff --git a/packages/Webkul/Shop/tests/Feature/API/ProductTest.php b/packages/Webkul/Shop/tests/Feature/API/ProductTest.php index 15dc32870ff..d62fbe5a791 100644 --- a/packages/Webkul/Shop/tests/Feature/API/ProductTest.php +++ b/packages/Webkul/Shop/tests/Feature/API/ProductTest.php @@ -1,7 +1,7 @@ [ 5 => 'new', @@ -27,10 +27,12 @@ ], ]; - (new Product($newProductOptions))->create(1, 'simple'); + (new ProductFaker($newProductOptions))->create(1, 'simple'); // Act - $response = getJson(route('shop.api.products.index', ['new' => 1]))->collect(); + $response = getJson(route('shop.api.products.index', ['new' => 1])) + ->assertOk() + ->collect(); // Assert expect($response['data'])->each(function (Expectation $product) { @@ -39,7 +41,7 @@ }); it('returns a featured products listing', function () { - // Prepare + // Arrange $featuredProductOptions = [ 'attributes' => [ 6 => 'featured', @@ -52,10 +54,12 @@ ], ]; - (new Product($featuredProductOptions))->create(1, 'simple'); + (new ProductFaker($featuredProductOptions))->create(1, 'simple'); // Act - $response = getJson(route('shop.api.products.index', ['featured' => 1]))->collect(); + $response = getJson(route('shop.api.products.index', ['featured' => 1])) + ->assertOk() + ->collect(); // Assert expect($response['data'])->each(function (Expectation $product) { @@ -64,11 +68,12 @@ }); it('returns all products listing', function () { - // Prepare - $product = (new Product())->create(1, 'simple')->first(); + // Arrange + $product = (new ProductFaker())->create(1, 'simple')->first(); // Act & Assert getJson(route('shop.api.products.index')) + ->assertOk() ->assertJsonIsArray('data') ->assertJsonFragment([ 'id' => $product->id, diff --git a/packages/Webkul/Shop/tests/Feature/HomePageTest.php b/packages/Webkul/Shop/tests/Feature/HomePageTest.php index c93780160f4..0ddc4ff6348 100644 --- a/packages/Webkul/Shop/tests/Feature/HomePageTest.php +++ b/packages/Webkul/Shop/tests/Feature/HomePageTest.php @@ -1,9 +1,41 @@ delete(); +}); + it('returns a successful response', function () { // Act & Assert get(route('shop.home.index')) ->assertOk(); }); + +it('displays the "Sign In" and "Sign Up" buttons when the customer is not logged in', function () { + // Act & Assert + get(route('shop.home.index')) + ->assertOk() + ->assertSeeText(trans('shop::app.components.layouts.header.sign-in')) + ->assertSeeText(trans('shop::app.components.layouts.header.sign-up')); +}); + +it('displays navigation buttons when the customer is logged in', function () { + // Act + $this->loginAsCustomer(); + + // Assert + get(route('shop.home.index')) + ->assertOk() + ->assertSee([ + trans('shop::app.components.layouts.header.profile'), + trans('shop::app.components.layouts.header.orders'), + trans('shop::app.components.layouts.header.wishlist'), + trans('shop::app.components.layouts.header.logout'), + ]); +}); diff --git a/packages/Webkul/Shop/tests/ShopTestCase.php b/packages/Webkul/Shop/tests/ShopTestCase.php index 3089547630b..cc130f92166 100644 --- a/packages/Webkul/Shop/tests/ShopTestCase.php +++ b/packages/Webkul/Shop/tests/ShopTestCase.php @@ -3,7 +3,20 @@ namespace Webkul\Shop\Tests; use Tests\TestCase; +use Webkul\Customer\Contracts\Customer as CustomerContract; +use Webkul\Faker\Helpers\Customer as CustomerFaker; class ShopTestCase extends TestCase { + /** + * Login as customer. + */ + public function loginAsCustomer(CustomerContract $customer = null): CustomerContract + { + $customer = $customer ?? (new CustomerFaker())->create(1)->first(); + + $this->actingAs($customer); + + return $customer; + } }