| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?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_apply_the_sample_design_and_preview_it()
- {
- $user = User::factory()->create();
- $store = Store::factory()->for($user)->create(['name' => 'Sambal Nenek']);
-
- $this->actingAs($user)
- ->post(route('stores.sample-design', $store->slug))
- ->assertRedirect(route('stores.show', $store->slug));
-
- $this->assertSame('Sambal Nenek', $store->fresh()->plan['sections'][0]['content']['logoText']);
-
- $this->actingAs($user)
- ->get(route('stores.preview', $store->slug))
- ->assertOk()
- ->assertInertia(fn (Assert $page) => $page
- ->component('stores/preview')
- ->where('storeName', 'Sambal Nenek')
- ->has('plan.sections', 10)
- ->has('fonts.inter'));
- }
-
- public function test_a_user_cannot_preview_or_change_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();
- $this->actingAs($user)->post(route('stores.sample-design', $store->slug))->assertNotFound();
- }
-
- public function test_guests_cannot_preview_a_store()
- {
- $store = Store::factory()->create();
-
- $this->get(route('stores.preview', $store->slug))->assertRedirect(route('login'));
- }
- }
|