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', 9) ->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')); } }