EventsTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. use Webkul\Marketing\Models\Event;
  3. use function Pest\Laravel\deleteJson;
  4. use function Pest\Laravel\get;
  5. use function Pest\Laravel\postJson;
  6. use function Pest\Laravel\putJson;
  7. it('should return the events index page', function () {
  8. // Act and Assert.
  9. $this->loginAsAdmin();
  10. get(route('admin.marketing.communications.events.index'))
  11. ->assertOk()
  12. ->assertSeeText(trans('admin::app.marketing.communications.events.index.title'))
  13. ->assertSeeText(trans('admin::app.marketing.communications.events.index.create-btn'));
  14. });
  15. it('should fail the validation with errors when certain inputs are not provided when store in events', function () {
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. postJson(route('admin.marketing.communications.events.store'))
  19. ->assertJsonValidationErrorFor('name')
  20. ->assertJsonValidationErrorFor('description')
  21. ->assertJsonValidationErrorFor('date')
  22. ->assertUnprocessable();
  23. });
  24. it('should store the newly create event', function () {
  25. // Act and Assert.
  26. $this->loginAsAdmin();
  27. postJson(route('admin.marketing.communications.events.store', $data = [
  28. 'name' => fake()->name(),
  29. 'description' => substr(fake()->paragraph(), 0, 50),
  30. 'date' => fake()->date(),
  31. ]))
  32. ->assertOk()
  33. ->assertSeeText(trans('admin::app.marketing.communications.events.index.create.success'));
  34. $this->assertModelWise([
  35. Event::class => [
  36. [
  37. 'name' => $data['name'],
  38. 'description' => $data['description'],
  39. 'date' => $data['date'],
  40. ],
  41. ],
  42. ]);
  43. });
  44. it('should edit the events template', function () {
  45. // Arrange.
  46. $event = Event::factory()->create();
  47. // Act and Assert.
  48. $this->loginAsAdmin();
  49. get(route('admin.marketing.communications.events.edit', $event->id))
  50. ->assertOk()
  51. ->assertJsonFragment($event->toArray());
  52. });
  53. it('should fail the validation with errors when certain inputs are not provided when update in events', function () {
  54. // Arrange.
  55. $event = Event::factory()->create();
  56. // Act and Assert.
  57. $this->loginAsAdmin();
  58. postJson(route('admin.marketing.communications.events.store', $event->id))
  59. ->assertJsonValidationErrorFor('name')
  60. ->assertJsonValidationErrorFor('description')
  61. ->assertJsonValidationErrorFor('date')
  62. ->assertUnprocessable();
  63. });
  64. it('should update the existing the events', function () {
  65. // Arrange.
  66. $event = Event::factory()->create();
  67. // Act and Assert.
  68. $this->loginAsAdmin();
  69. putJson(route('admin.marketing.communications.events.update'), [
  70. 'id' => $event->id,
  71. 'name' => $event->name,
  72. 'description' => $description = substr(fake()->paragraph(), 0, 50),
  73. 'date' => $date = fake()->date(),
  74. ])
  75. ->assertOk()
  76. ->assertSeeText(trans('admin::app.marketing.communications.events.index.edit.success'));
  77. $this->assertModelWise([
  78. Event::class => [
  79. [
  80. 'id' => $event->id,
  81. 'name' => $event->name,
  82. 'description' => $description,
  83. 'date' => $date,
  84. ],
  85. ],
  86. ]);
  87. });
  88. it('should delete the specified events', function () {
  89. // Arrange.
  90. $event = Event::factory()->create();
  91. // Act and Assert.
  92. $this->loginAsAdmin();
  93. deleteJson(route('admin.marketing.communications.events.delete', $event->id))
  94. ->assertOk()
  95. ->assertSeeText(trans('admin::app.marketing.communications.events.delete-success'));
  96. });