AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

StoreDesignTest.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_preview_a_store_that_has_a_design()
  22. {
  23. $user = User::factory()->create();
  24. $store = Store::factory()->for($user)->create(['name' => 'Sambal Nenek']);
  25. $store->plan = SamplePlan::for($store);
  26. $store->save();
  27. $this->actingAs($user)
  28. ->get(route('stores.preview', $store->slug))
  29. ->assertOk()
  30. ->assertInertia(fn (Assert $page) => $page
  31. ->component('stores/preview')
  32. ->where('storeName', 'Sambal Nenek')
  33. ->has('plan.pages.0.sections', 8)
  34. ->where('plan.header.content.logoText', 'Sambal Nenek')
  35. ->where('view.type', 'page')
  36. ->where('view.pageId', 'home')
  37. ->where('baseUrl', '/stores/'.$store->slug.'/preview')
  38. ->has('fonts.inter'));
  39. }
  40. public function test_a_user_cannot_preview_someone_elses_store()
  41. {
  42. $user = User::factory()->create();
  43. $store = Store::factory()->create();
  44. $store->plan = SamplePlan::for($store);
  45. $store->save();
  46. $this->actingAs($user)->get(route('stores.preview', $store->slug))->assertNotFound();
  47. }
  48. public function test_extra_pages_open_at_their_own_address()
  49. {
  50. $user = User::factory()->create();
  51. $store = Store::factory()->for($user)->create();
  52. $plan = SamplePlan::for($store);
  53. $plan['pages'][] = [
  54. 'id' => 'about',
  55. 'title' => 'About us',
  56. 'sections' => [[
  57. 'id' => 'about-main',
  58. 'type' => 'about',
  59. 'variant' => 'simple',
  60. 'content' => ['heading' => 'Our story', 'body' => 'We started small.', 'stats' => []],
  61. ]],
  62. ];
  63. $store->plan = $plan;
  64. $store->save();
  65. $this->actingAs($user)
  66. ->get(route('stores.preview.page', [$store->slug, 'about']))
  67. ->assertOk()
  68. ->assertInertia(fn (Assert $page) => $page
  69. ->component('stores/preview')
  70. ->where('view.type', 'page')
  71. ->where('view.pageId', 'about')
  72. ->where('plan.pages.1.title', 'About us'));
  73. $this->actingAs($user)->get(route('stores.preview.page', [$store->slug, 'home']))->assertRedirect(route('stores.preview', $store->slug));
  74. $this->actingAs($user)->get(route('stores.preview.page', [$store->slug, 'no-such-page']))->assertNotFound();
  75. $this->actingAs(User::factory()->create())->get(route('stores.preview.page', [$store->slug, 'about']))->assertNotFound();
  76. // The store's own pages keep their addresses.
  77. $this->actingAs($user)->get(route('stores.preview.shop', $store->slug))
  78. ->assertInertia(fn (Assert $page) => $page->where('view.type', 'shop'));
  79. $this->actingAs($user)->get(route('stores.preview.cart', $store->slug))
  80. ->assertInertia(fn (Assert $page) => $page->where('view.type', 'cart'));
  81. }
  82. public function test_guests_cannot_preview_a_store()
  83. {
  84. $store = Store::factory()->create();
  85. $this->get(route('stores.preview', $store->slug))->assertRedirect(route('login'));
  86. }
  87. }