| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
-
- namespace Tests\Feature\Stores;
-
- use App\Models\Store;
- use App\Models\User;
- use App\StorePlan\SamplePlan;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Inertia\Testing\AssertableInertia as Assert;
- use Tests\TestCase;
-
- class StoreDesignTest extends TestCase
- {
- use RefreshDatabase;
-
- public function test_a_new_store_has_no_design()
- {
- $user = User::factory()->create();
- $store = Store::factory()->for($user)->create();
-
- $this->actingAs($user)
- ->get(route('stores.show', $store->slug))
- ->assertInertia(fn (Assert $page) => $page->where('store.has_design', false));
-
- $this->actingAs($user)->get(route('stores.preview', $store->slug))->assertNotFound();
- }
-
- public function test_a_user_can_preview_a_store_that_has_a_design()
- {
- $user = User::factory()->create();
- $store = Store::factory()->for($user)->create(['name' => 'Sambal Nenek']);
- $store->plan = SamplePlan::for($store);
- $store->save();
-
- $this->actingAs($user)
- ->get(route('stores.preview', $store->slug))
- ->assertOk()
- ->assertInertia(fn (Assert $page) => $page
- ->component('stores/preview')
- ->where('storeName', 'Sambal Nenek')
- ->has('plan.pages.0.sections', 8)
- ->where('plan.header.content.logoText', 'Sambal Nenek')
- ->where('view.type', 'page')
- ->where('view.pageId', 'home')
- ->where('baseUrl', '/stores/'.$store->slug.'/preview')
- ->has('fonts.inter'));
- }
-
- public function test_a_user_cannot_preview_someone_elses_store()
- {
- $user = User::factory()->create();
- $store = Store::factory()->create();
- $store->plan = SamplePlan::for($store);
- $store->save();
-
- $this->actingAs($user)->get(route('stores.preview', $store->slug))->assertNotFound();
- }
-
- public function test_extra_pages_open_at_their_own_address()
- {
- $user = User::factory()->create();
- $store = Store::factory()->for($user)->create();
- $plan = SamplePlan::for($store);
- $plan['pages'][] = [
- 'id' => 'about',
- 'title' => 'About us',
- 'sections' => [[
- 'id' => 'about-main',
- 'type' => 'about',
- 'variant' => 'simple',
- 'content' => ['heading' => 'Our story', 'body' => 'We started small.', 'stats' => []],
- ]],
- ];
- $store->plan = $plan;
- $store->save();
-
- $this->actingAs($user)
- ->get(route('stores.preview.page', [$store->slug, 'about']))
- ->assertOk()
- ->assertInertia(fn (Assert $page) => $page
- ->component('stores/preview')
- ->where('view.type', 'page')
- ->where('view.pageId', 'about')
- ->where('plan.pages.1.title', 'About us'));
-
- $this->actingAs($user)->get(route('stores.preview.page', [$store->slug, 'home']))->assertRedirect(route('stores.preview', $store->slug));
- $this->actingAs($user)->get(route('stores.preview.page', [$store->slug, 'no-such-page']))->assertNotFound();
- $this->actingAs(User::factory()->create())->get(route('stores.preview.page', [$store->slug, 'about']))->assertNotFound();
-
- // The store's own pages keep their addresses.
- $this->actingAs($user)->get(route('stores.preview.shop', $store->slug))
- ->assertInertia(fn (Assert $page) => $page->where('view.type', 'shop'));
- $this->actingAs($user)->get(route('stores.preview.cart', $store->slug))
- ->assertInertia(fn (Assert $page) => $page->where('view.type', 'cart'));
- }
-
- public function test_guests_cannot_preview_a_store()
- {
- $store = Store::factory()->create();
-
- $this->get(route('stores.preview', $store->slug))->assertRedirect(route('login'));
- }
- }
|