| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <?php
- use Illuminate\Support\Facades\Mail;
- use Illuminate\Support\Str;
- use Webkul\Core\Models\SubscribersList;
- use Webkul\Customer\Models\CompareItem;
- use Webkul\Faker\Helpers\Product as ProductFaker;
- use Webkul\Shop\Mail\Customer\SubscriptionNotification;
- use function Pest\Laravel\deleteJson;
- use function Pest\Laravel\get;
- use function Pest\Laravel\postJson;
- it('returns a successful response', function () {
- // Act and Assert.
- get(route('shop.home.index'))
- ->assertOk();
- });
- it('displays the current currency code and channel code', function () {
- // Act
- $response = get(route('shop.home.index'));
- // Assert
- $response->assertOk();
- /**
- * We avoid using the `assertSeeText` method of the response because it may sometimes
- * produce false positive results when dealing with large DOM sizes.
- */
- expect(Str::contains($response->content(), core()->getCurrentChannelCode()))
- ->toBeTruthy();
- expect(Str::contains($response->content(), core()->getCurrentCurrencyCode()))
- ->toBeTruthy();
- });
- it('displays the "Sign In" and "Sign Up" buttons when the customer is not logged in', function () {
- // Act
- $response = get(route('shop.home.index'));
- // Assert
- $response->assertOk();
- /**
- * We avoid using the `assertSeeText` method of the response because it may sometimes
- * produce false positive results when dealing with large DOM sizes.
- */
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.sign-in')))
- ->toBeTruthy();
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.sign-up')))
- ->toBeTruthy();
- });
- it('displays navigation buttons when the customer is logged in', function () {
- // Act
- $this->loginAsCustomer();
- $response = get(route('shop.home.index'));
- // Assert
- $response->assertOk();
- /**
- * We avoid using the `assertSeeText` method of the response because it may sometimes
- * produce false positive results when dealing with large DOM sizes.
- */
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.profile')))
- ->toBeTruthy();
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.orders')))
- ->toBeTruthy();
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.wishlist')))
- ->toBeTruthy();
- expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.logout')))
- ->toBeTruthy();
- });
- it('should returns the home page of the store', function () {
- get(route('shop.home.index'))
- ->assertOk()
- ->assertSeeText('The game with our new additions!')
- ->assertSeeText('Our Collections')
- ->assertSeeText('Get Ready for our new Bold Collections!')
- ->assertSeeText('Get UPTO 40% OFF on your 1st order SHOP NOW');
- });
- it('should returns the search page of the products', function () {
- // Arrange.
- $product = (new ProductFaker([
- 'attributes' => [
- 5 => 'new',
- 6 => 'featured',
- 11 => 'price',
- 26 => 'guest_checkout',
- ],
- 'attribute_value' => [
- 'new' => [
- 'boolean_value' => true,
- ],
- 'featured' => [
- 'boolean_value' => true,
- ],
- 'price' => [
- 'float_value' => fake()->randomFloat(2, 1000, 5000),
- ],
- 'guest_checkout' => [
- 'boolean_value' => true,
- ],
- ],
- ]))->getSimpleProductFactory()->create();
- // Act and Assert.
- get(route('shop.search.index', [
- 'query' => $query = $product->name,
- ]))
- ->assertOk()
- ->assertSeeText($query)
- ->assertSeeText(trans('shop::app.search.title', ['query' => $query]));
- });
- it('should fails the validation error when provided wrong email address when subscribe to the shop', function () {
- // Act and Assert.
- postJson(route('shop.subscription.store'))
- ->assertJsonValidationErrorFor('email')
- ->assertUnprocessable();
- });
- it('should store the subscription of the shop', function () {
- // Act and Assert.
- postJson(route('shop.subscription.store'), [
- 'email' => $email = fake()->email(),
- ])
- ->assertRedirect();
- $this->assertModelWise([
- SubscribersList::class => [
- [
- 'email' => $email,
- 'is_subscribed' => 1,
- ],
- ],
- ]);
- });
- it('should store the subscription of the shop and send the mail to the admin', function () {
- // Act and Assert.
- Mail::fake();
- postJson(route('shop.subscription.store'), [
- 'email' => $email = fake()->email(),
- ])
- ->assertRedirect();
- $this->assertModelWise([
- SubscribersList::class => [
- [
- 'email' => $email,
- 'is_subscribed' => 1,
- ],
- ],
- ]);
- Mail::assertQueued(SubscriptionNotification::class);
- Mail::assertQueuedCount(1);
- });
- it('should unsubscribe from the shop', function () {
- // Arrange.
- $subscriber = SubscribersList::factory()->create();
- // Act and Assert.
- get(route('shop.subscription.destroy', [
- 'token' => $subscriber->token,
- ]))
- ->assertRedirect();
- $this->assertDatabaseMissing('subscribers_list', [
- 'id' => $subscriber->id,
- ]);
- });
- it('should store the products to the compare list', function () {
- // Arrange.
- $product = (new ProductFaker([
- 'attributes' => [
- 5 => 'new',
- 6 => 'featured',
- 11 => 'price',
- 26 => 'guest_checkout',
- ],
- 'attribute_value' => [
- 'new' => [
- 'boolean_value' => true,
- ],
- 'featured' => [
- 'boolean_value' => true,
- ],
- 'price' => [
- 'float_value' => fake()->randomFloat(2, 1000, 5000),
- ],
- 'guest_checkout' => [
- 'boolean_value' => true,
- ],
- ],
- ]))->getSimpleProductFactory()->create();
- // Act and Assert.
- $this->loginAsCustomer();
- postJson(route('shop.api.compare.store'), [
- 'product_id' => $product->id,
- ])
- ->assertOk()
- ->assertSeeText(trans('shop::app.compare.item-add-success'));
- });
- it('should fails the validation error when not provided product id when move the compare list item', function () {
- // Act and Assert.
- $this->loginAsCustomer();
- postJson(route('shop.api.compare.store'))
- ->assertJsonValidationErrorFor('product_id')
- ->assertUnprocessable();
- });
- it('should remove product from compare list', function () {
- // Arrange.
- $product = (new ProductFaker([
- 'attributes' => [
- 5 => 'new',
- 6 => 'featured',
- 11 => 'price',
- 26 => 'guest_checkout',
- ],
- 'attribute_value' => [
- 'new' => [
- 'boolean_value' => true,
- ],
- 'featured' => [
- 'boolean_value' => true,
- ],
- 'price' => [
- 'float_value' => fake()->randomFloat(2, 1000, 5000),
- ],
- 'guest_checkout' => [
- 'boolean_value' => true,
- ],
- ],
- ]))->getSimpleProductFactory()->create();
- // Act and Assert.
- $this->loginAsCustomer();
- CompareItem::factory()->create([
- 'customer_id' => auth()->guard('customer')->user()->id,
- 'product_id' => $product->id,
- ]);
- deleteJson(route('shop.api.compare.destroy'), [
- 'product_id' => $product->id,
- ])
- ->assertOk()
- ->assertJsonPath('message', trans('shop::app.compare.remove-success'));
- });
- it('should remove all the products from compare list', function () {
- // Arrange.
- $products = (new ProductFaker([
- 'attributes' => [
- 5 => 'new',
- 6 => 'featured',
- 11 => 'price',
- 26 => 'guest_checkout',
- ],
- 'attribute_value' => [
- 'new' => [
- 'boolean_value' => true,
- ],
- 'featured' => [
- 'boolean_value' => true,
- ],
- 'price' => [
- 'float_value' => fake()->randomFloat(2, 1000, 5000),
- ],
- 'guest_checkout' => [
- 'boolean_value' => true,
- ],
- ],
- ]))->getSimpleProductFactory()->count(5)->create();
- // Act and Assert.
- $this->loginAsCustomer();
- foreach ($products as $product) {
- CompareItem::factory()->create([
- 'customer_id' => auth()->guard('customer')->user()->id,
- 'product_id' => $product->id,
- ]);
- }
- deleteJson(route('shop.api.compare.destroy_all'))
- ->assertOk()
- ->assertJsonPath('data.message', trans('shop::app.compare.remove-all-success'));
- });
|