ChannelsTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. use Illuminate\Http\UploadedFile;
  3. use Webkul\Core\Models\Channel;
  4. use function Pest\Laravel\deleteJson;
  5. use function Pest\Laravel\get;
  6. use function Pest\Laravel\postJson;
  7. use function Pest\Laravel\putJson;
  8. it('should returns the channel index page', function () {
  9. // Act and Assert.
  10. $this->loginAsAdmin();
  11. get(route('admin.settings.channels.index'))
  12. ->assertOk()
  13. ->assertSeeText(trans('admin::app.settings.channels.index.title'))
  14. ->assertSeeText(trans('admin::app.settings.channels.index.create-btn'));
  15. });
  16. it('should return the create page of channel', function () {
  17. // Act and Assert.
  18. $this->loginAsAdmin();
  19. get(route('admin.settings.channels.create'))
  20. ->assertOk()
  21. ->assertSeeText(trans('admin::app.settings.channels.create.title'))
  22. ->assertSeeText(trans('admin::app.settings.channels.create.save-btn'));
  23. });
  24. it('should fail the validation with errors when certain field not provided when store the channels', function () {
  25. // Act and Assert.
  26. $this->loginAsAdmin();
  27. postJson(route('admin.settings.channels.store'))
  28. ->assertJsonValidationErrorFor('code')
  29. ->assertJsonValidationErrorFor('name')
  30. ->assertJsonValidationErrorFor('inventory_sources')
  31. ->assertJsonValidationErrorFor('root_category_id')
  32. ->assertJsonValidationErrorFor('locales')
  33. ->assertJsonValidationErrorFor('default_locale_id')
  34. ->assertJsonValidationErrorFor('currencies')
  35. ->assertJsonValidationErrorFor('base_currency_id')
  36. ->assertJsonValidationErrorFor('seo_title')
  37. ->assertJsonValidationErrorFor('seo_description')
  38. ->assertJsonValidationErrorFor('seo_keywords')
  39. ->assertUnprocessable();
  40. });
  41. it('should store the newly created channels', function () {
  42. // Act and Assert.
  43. $this->loginAsAdmin();
  44. postJson(route('admin.settings.channels.store'), $data = [
  45. 'code' => $code = fake()->numerify('code######'),
  46. 'theme' => $code,
  47. 'hostname' => 'http://'.fake()->ipv4(),
  48. 'root_category_id' => 1,
  49. 'default_locale_id' => 1,
  50. 'base_currency_id' => 1,
  51. 'name' => fake()->name(),
  52. 'description' => substr(fake()->paragraph, 0, 50),
  53. 'inventory_sources' => [1],
  54. 'locales' => [1],
  55. 'currencies' => [1],
  56. 'seo_title' => fake()->title(),
  57. 'seo_description' => substr(fake()->paragraph(), 0, 50),
  58. 'seo_keywords' => fake()->name(),
  59. 'is_maintenance_on' => fake()->boolean(),
  60. 'logo' => [
  61. UploadedFile::fake()->image('logo.png'),
  62. ],
  63. 'favicon' => [
  64. UploadedFile::fake()->image('favicon.png'),
  65. ],
  66. ])
  67. ->assertRedirect(route('admin.settings.channels.index'))
  68. ->isRedirection();
  69. $this->assertModelWise([
  70. Channel::class => [
  71. [
  72. 'code' => $data['code'],
  73. 'theme' => $data['theme'],
  74. 'hostname' => $data['hostname'],
  75. 'root_category_id' => $data['root_category_id'],
  76. 'default_locale_id' => $data['default_locale_id'],
  77. 'base_currency_id' => $data['base_currency_id'],
  78. ],
  79. ],
  80. ]);
  81. });
  82. it('should returns the edit page of channels', function () {
  83. // Arrange.
  84. $channel = Channel::factory()->create();
  85. // Act and Assert.
  86. $this->loginAsAdmin();
  87. get(route('admin.settings.channels.edit', $channel->id))
  88. ->assertOk()
  89. ->assertSeeText(trans('admin::app.settings.channels.edit.title'))
  90. ->assertSeeText(trans('admin::app.settings.channels.edit.save-btn'));
  91. });
  92. it('should fail the validation with errors when certain field not provided when update the channels', function () {
  93. // Arrange.
  94. $channel = Channel::factory()->create();
  95. // Act and Assert.
  96. $this->loginAsAdmin();
  97. putJson(route('admin.settings.channels.update', $channel->id))
  98. ->assertJsonValidationErrorFor('code')
  99. ->assertJsonValidationErrorFor('en.name')
  100. ->assertJsonValidationErrorFor('en.seo_title')
  101. ->assertJsonValidationErrorFor('en.seo_description')
  102. ->assertJsonValidationErrorFor('en.seo_keywords')
  103. ->assertJsonValidationErrorFor('inventory_sources')
  104. ->assertJsonValidationErrorFor('root_category_id')
  105. ->assertJsonValidationErrorFor('locales')
  106. ->assertJsonValidationErrorFor('default_locale_id')
  107. ->assertJsonValidationErrorFor('currencies')
  108. ->assertJsonValidationErrorFor('base_currency_id')
  109. ->assertUnprocessable();
  110. });
  111. it('should update the existing channel', function () {
  112. // Arrange.
  113. $channel = Channel::factory()->create();
  114. // Act and Assert.
  115. $this->loginAsAdmin();
  116. putJson(route('admin.settings.channels.update', $channel->id), $data = [
  117. 'code' => $channel->code,
  118. app()->getLocale() => [
  119. 'name' => fake()->name(),
  120. 'seo_title' => fake()->title(),
  121. 'seo_description' => substr(fake()->paragraph(), 0, 50),
  122. 'seo_keywords' => fake()->name(),
  123. 'description' => substr(fake()->paragraph, 0, 50),
  124. ],
  125. 'hostname' => 'http://'.fake()->ipv4(),
  126. 'root_category_id' => 1,
  127. 'default_locale_id' => 1,
  128. 'base_currency_id' => 1,
  129. 'inventory_sources' => [1],
  130. 'locales' => [1],
  131. 'currencies' => [1],
  132. 'is_maintenance_on' => fake()->boolean(),
  133. ])
  134. ->assertRedirect(route('admin.settings.channels.index'))
  135. ->isRedirection();
  136. $this->assertModelWise([
  137. Channel::class => [
  138. [
  139. 'code' => $data['code'],
  140. 'hostname' => $data['hostname'],
  141. 'is_maintenance_on' => $data['is_maintenance_on'],
  142. 'base_currency_id' => 1,
  143. 'root_category_id' => 1,
  144. 'default_locale_id' => 1,
  145. ],
  146. ],
  147. ]);
  148. });
  149. it('should delete the existing channel', function () {
  150. // Arrange.
  151. $channel = Channel::factory()->create();
  152. // Act and Assert.
  153. $this->loginAsAdmin();
  154. deleteJson(route('admin.settings.channels.delete', $channel->id))
  155. ->assertOk()
  156. ->assertSeeText(trans('admin::app.settings.channels.index.delete-success'));
  157. $this->assertDatabaseMissing('channels', ['id' => $channel->id]);
  158. });