RegistrationPageTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. use Illuminate\Support\Facades\Mail;
  3. use Webkul\Admin\Mail\Customer\RegistrationNotification as AdminRegistrationNotification;
  4. use Webkul\Core\Models\CoreConfig;
  5. use Webkul\Shop\Mail\Customer\EmailVerificationNotification;
  6. use Webkul\Shop\Mail\Customer\RegistrationNotification as ShopRegistrationNotification;
  7. use function Pest\Laravel\get;
  8. use function Pest\Laravel\post;
  9. use function Pest\Laravel\postJson;
  10. it('returns a successful response', function () {
  11. // Act and Assert.
  12. get(route('shop.customers.register.index'))
  13. ->assertOk()
  14. ->assertSeeText(trans('shop::app.customers.signup-form.page-title'));
  15. });
  16. it('should fails validation error when certain inputs are invalid when register', function () {
  17. // Act and Assert.
  18. postJson(route('shop.customers.register.store'))
  19. ->assertJsonValidationErrorFor('first_name')
  20. ->assertJsonValidationErrorFor('last_name')
  21. ->assertJsonValidationErrorFor('email')
  22. ->assertJsonValidationErrorFor('password')
  23. ->assertUnprocessable();
  24. });
  25. it('should fails validation error when email is not valid when register', function () {
  26. // Act and Assert.
  27. postJson(route('shop.customers.register.store'), [
  28. 'email' => 'invalid.email.com',
  29. ])
  30. ->assertJsonValidationErrorFor('first_name')
  31. ->assertJsonValidationErrorFor('last_name')
  32. ->assertJsonValidationErrorFor('email')
  33. ->assertJsonValidationErrorFor('password')
  34. ->assertUnprocessable();
  35. });
  36. it('should fails validation error when password length is not valid when register', function () {
  37. // Act and Assert.
  38. postJson(route('shop.customers.register.store'), [
  39. 'password' => 'shop',
  40. ])
  41. ->assertJsonValidationErrorFor('first_name')
  42. ->assertJsonValidationErrorFor('last_name')
  43. ->assertJsonValidationErrorFor('email')
  44. ->assertJsonValidationErrorFor('password')
  45. ->assertUnprocessable();
  46. });
  47. it('successfully registers a customer', function () {
  48. CoreConfig::where('code', 'customer.settings.email.verification')->update([
  49. 'value' => 0,
  50. ]);
  51. // Arrange.
  52. $requestedCustomer = [
  53. 'first_name' => fake()->firstName(),
  54. 'last_name' => fake()->lastName(),
  55. 'email' => fake()->email(),
  56. 'password' => 'admin123',
  57. 'password_confirmation' => 'admin123',
  58. ];
  59. // Act and Assert.
  60. post(route('shop.customers.register.store'), $requestedCustomer)
  61. ->assertRedirectToRoute('shop.customer.session.index')
  62. ->assertSessionHas('success', trans('shop::app.customers.signup-form.success'));
  63. });
  64. it('successfully registers a customer and send mail to the customer verify the account', function () {
  65. // Arrange.
  66. Mail::fake();
  67. CoreConfig::factory()->create([
  68. 'code' => 'customer.settings.email.verification',
  69. 'value' => 1,
  70. ]);
  71. $requestedCustomer = [
  72. 'first_name' => fake()->firstName(),
  73. 'last_name' => fake()->lastName(),
  74. 'email' => fake()->email(),
  75. 'password' => 'admin123',
  76. 'password_confirmation' => 'admin123',
  77. ];
  78. // Act and Assert.
  79. post(route('shop.customers.register.store'), $requestedCustomer)
  80. ->assertRedirectToRoute('shop.customer.session.index')
  81. ->assertSessionHas('success', trans('shop::app.customers.signup-form.success-verify'));
  82. Mail::assertQueued(EmailVerificationNotification::class);
  83. Mail::assertQueuedCount(1);
  84. });
  85. it('registers a customer successfully and sends a registration email to customer and admin along with a success message', function () {
  86. // Arrange.
  87. Mail::fake();
  88. CoreConfig::where('code', 'emails.general.notifications.emails.general.notifications.registration')->update([
  89. 'value' => 1,
  90. ]);
  91. CoreConfig::where('code', 'emails.general.notifications.emails.general.notifications.customer_registration_confirmation_mail_to_admin')->update([
  92. 'value' => 1,
  93. ]);
  94. CoreConfig::where('code', 'customer.settings.email.verification')->update([
  95. 'value' => 0,
  96. ]);
  97. $requestedCustomer = [
  98. 'first_name' => fake()->firstName(),
  99. 'last_name' => fake()->lastName(),
  100. 'email' => fake()->email(),
  101. 'password' => 'admin123',
  102. 'password_confirmation' => 'admin123',
  103. ];
  104. // Act and Assert.
  105. post(route('shop.customers.register.store'), $requestedCustomer)
  106. ->assertRedirectToRoute('shop.customer.session.index')
  107. ->assertSessionHas('success', trans('shop::app.customers.signup-form.success'));
  108. Mail::assertQueued(AdminRegistrationNotification::class);
  109. Mail::assertQueued(ShopRegistrationNotification::class);
  110. Mail::assertQueuedCount(2);
  111. });