AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreDesignTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Tests\Feature\Stores;
  3. use App\Models\Store;
  4. use App\Models\User;
  5. use App\StorePlan\SamplePlan;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Inertia\Testing\AssertableInertia as Assert;
  8. use Tests\TestCase;
  9. class StoreDesignTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. public function test_a_new_store_has_no_design()
  13. {
  14. $user = User::factory()->create();
  15. $store = Store::factory()->for($user)->create();
  16. $this->actingAs($user)
  17. ->get(route('stores.show', $store->slug))
  18. ->assertInertia(fn (Assert $page) => $page->where('store.has_design', false));
  19. $this->actingAs($user)->get(route('stores.preview', $store->slug))->assertNotFound();
  20. }
  21. public function test_a_user_can_apply_the_sample_design_and_preview_it()
  22. {
  23. $user = User::factory()->create();
  24. $store = Store::factory()->for($user)->create(['name' => 'Sambal Nenek']);
  25. $this->actingAs($user)
  26. ->post(route('stores.sample-design', $store->slug))
  27. ->assertRedirect(route('stores.show', $store->slug));
  28. $this->assertSame('Sambal Nenek', $store->fresh()->plan['sections'][0]['content']['logoText']);
  29. $this->actingAs($user)
  30. ->get(route('stores.preview', $store->slug))
  31. ->assertOk()
  32. ->assertInertia(fn (Assert $page) => $page
  33. ->component('stores/preview')
  34. ->where('storeName', 'Sambal Nenek')
  35. ->has('plan.sections', 10)
  36. ->has('fonts.inter'));
  37. }
  38. public function test_a_user_cannot_preview_or_change_someone_elses_store()
  39. {
  40. $user = User::factory()->create();
  41. $store = Store::factory()->create();
  42. $store->plan = SamplePlan::for($store);
  43. $store->save();
  44. $this->actingAs($user)->get(route('stores.preview', $store->slug))->assertNotFound();
  45. $this->actingAs($user)->post(route('stores.sample-design', $store->slug))->assertNotFound();
  46. }
  47. public function test_guests_cannot_preview_a_store()
  48. {
  49. $store = Store::factory()->create();
  50. $this->get(route('stores.preview', $store->slug))->assertRedirect(route('login'));
  51. }
  52. }