NewsletterSubscriptionsTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. use Webkul\Core\Models\SubscribersList;
  3. use function Pest\Laravel\deleteJson;
  4. use function Pest\Laravel\get;
  5. use function Pest\Laravel\putJson;
  6. it('should return the subscription index page', function () {
  7. // Act and Assert.
  8. $this->loginAsAdmin();
  9. get(route('admin.marketing.communications.subscribers.index'))
  10. ->assertOk()
  11. ->assertSeeText(trans('admin::app.marketing.communications.subscribers.index.title'));
  12. });
  13. it('should show the edit page of campaign', function () {
  14. // Arrange.
  15. $subscriber = SubscribersList::factory()->create();
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. get(route('admin.marketing.communications.subscribers.edit', $subscriber->id))
  19. ->assertOk()
  20. ->assertJsonFragment($subscriber->toArray());
  21. });
  22. it('should fail the validation with errors when certain inputs are not provided when update in news letter subscription', function () {
  23. // Act and Assert.
  24. $this->loginAsAdmin();
  25. putJson(route('admin.marketing.communications.subscribers.update'))
  26. ->assertJsonValidationErrorFor('id')
  27. ->assertJsonValidationErrorFor('is_subscribed')
  28. ->assertUnprocessable();
  29. });
  30. it('should fail the validation with errors when is subscribed not passed in update in news letter subscription', function () {
  31. // Arrange.
  32. $subscriber = SubscribersList::factory()->create();
  33. // Act and Assert.
  34. $this->loginAsAdmin();
  35. putJson(route('admin.marketing.communications.subscribers.update'), [
  36. 'id' => $subscriber->id,
  37. ])
  38. ->assertJsonValidationErrorFor('is_subscribed')
  39. ->assertUnprocessable();
  40. });
  41. it('should fail the validation with errors when id is not passed in update in news letter subscription', function () {
  42. // Act and Assert.
  43. $this->loginAsAdmin();
  44. putJson(route('admin.marketing.communications.subscribers.update'), [
  45. 'is_subscribed' => 1,
  46. ])
  47. ->assertJsonValidationErrorFor('id')
  48. ->assertUnprocessable();
  49. });
  50. it('should update the subscriber', function () {
  51. // Arrange.
  52. $subscriber = SubscribersList::factory()->create();
  53. // Act and Assert.
  54. $this->loginAsAdmin();
  55. putJson(route('admin.marketing.communications.subscribers.update'), [
  56. 'id' => $subscriber->id,
  57. 'is_subscribed' => $isSubscribed = rand(0, 1),
  58. ])
  59. ->assertOk()
  60. ->assertSeeText(trans('admin::app.marketing.communications.subscribers.index.edit.success'));
  61. $this->assertModelWise([
  62. SubscribersList::class => [
  63. [
  64. 'id' => $subscriber->id,
  65. 'is_subscribed' => $isSubscribed,
  66. ],
  67. ],
  68. ]);
  69. });
  70. it('should delete the specific subscriber', function () {
  71. // Arrange.
  72. $subscriber = SubscribersList::factory()->create();
  73. // Act and Assert.
  74. $this->loginAsAdmin();
  75. deleteJson(route('admin.marketing.communications.subscribers.delete', $subscriber->id))
  76. ->assertOk()
  77. ->assertSeeText(trans('admin::app.marketing.communications.subscribers.delete-success'));
  78. });