InventorySourcesTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. use Webkul\Inventory\Models\InventorySource;
  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 returns the inventory sources index page', function () {
  8. // Act and Assert.
  9. $this->loginAsAdmin();
  10. get(route('admin.settings.inventory_sources.index'))
  11. ->assertOk()
  12. ->assertSeeText(trans('admin::app.settings.inventory-sources.index.title'))
  13. ->assertSeeText(trans('admin::app.settings.inventory-sources.index.create-btn'));
  14. });
  15. it('should return the inventory sources create page', function () {
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. get(route('admin.settings.inventory_sources.create'))
  19. ->assertOk()
  20. ->assertSeeText(trans('admin::app.settings.inventory-sources.create.add-title'))
  21. ->assertSeeText(trans('admin::app.marketing.communications.campaigns.create.back-btn'));
  22. });
  23. it('should fail the validation with errors when certain field not provided when store the inventory sources', function () {
  24. // Act and Assert.
  25. $this->loginAsAdmin();
  26. postJson(route('admin.settings.inventory_sources.store'))
  27. ->assertJsonValidationErrorFor('code')
  28. ->assertJsonValidationErrorFor('name')
  29. ->assertJsonValidationErrorFor('contact_name')
  30. ->assertJsonValidationErrorFor('contact_email')
  31. ->assertJsonValidationErrorFor('contact_number')
  32. ->assertJsonValidationErrorFor('street')
  33. ->assertJsonValidationErrorFor('country')
  34. ->assertJsonValidationErrorFor('state')
  35. ->assertJsonValidationErrorFor('city')
  36. ->assertJsonValidationErrorFor('postcode')
  37. ->assertUnprocessable();
  38. });
  39. it('should store the newly created inventory sources', function () {
  40. // Act and Assert.
  41. $this->loginAsAdmin();
  42. postJson(route('admin.settings.inventory_sources.store'), [
  43. 'code' => $code = fake()->numerify('code#######'),
  44. 'name' => $name = fake()->name(),
  45. 'priority' => $priority = rand(1, 10),
  46. 'contact_number' => $contactNumber = rand(1111111111, 9999999999),
  47. 'contact_email' => $contactEmail = fake()->email(),
  48. 'latitude' => fake()->latitude(),
  49. 'longitude' => fake()->longitude(),
  50. 'contact_name' => fake()->unique()->regexify('[A-Z0-9]{10}'),
  51. 'street' => fake()->streetName(),
  52. 'country' => preg_replace('/[^a-zA-Z0-9]+/', '', fake()->country()),
  53. 'state' => fake()->state(),
  54. 'city' => fake()->city(),
  55. 'postcode' => fake()->postcode(),
  56. ])
  57. ->assertRedirect(route('admin.settings.inventory_sources.index'))
  58. ->isRedirection();
  59. $this->assertModelWise([
  60. InventorySource::class => [
  61. [
  62. 'code' => $code,
  63. 'name' => $name,
  64. 'priority' => $priority,
  65. 'contact_email' => $contactEmail,
  66. 'contact_number' => $contactNumber,
  67. ],
  68. ],
  69. ]);
  70. });
  71. it('should return the edit of the inventory sources', function () {
  72. // Arrange.
  73. $inventorySource = InventorySource::factory()->create();
  74. // Act and Assert.
  75. $this->loginAsAdmin();
  76. get(route('admin.settings.inventory_sources.edit', $inventorySource->id))
  77. ->assertOk()
  78. ->assertSeeText(trans('admin::app.settings.inventory-sources.edit.title'))
  79. ->assertSeeText(trans('admin::app.settings.inventory-sources.edit.back-btn'))
  80. ->assertSeeText(trans('admin::app.settings.inventory-sources.edit.save-btn'));
  81. });
  82. it('should fail the validation with errors when certain field not provided when update the inventory sources', function () {
  83. // Arrange.
  84. $inventorySources = InventorySource::factory()->create();
  85. // Act and Assert.
  86. $this->loginAsAdmin();
  87. putJson(route('admin.settings.inventory_sources.update', $inventorySources->id))
  88. ->assertJsonValidationErrorFor('code')
  89. ->assertJsonValidationErrorFor('name')
  90. ->assertJsonValidationErrorFor('contact_name')
  91. ->assertJsonValidationErrorFor('contact_email')
  92. ->assertJsonValidationErrorFor('contact_number')
  93. ->assertJsonValidationErrorFor('street')
  94. ->assertJsonValidationErrorFor('country')
  95. ->assertJsonValidationErrorFor('state')
  96. ->assertJsonValidationErrorFor('city')
  97. ->assertJsonValidationErrorFor('postcode')
  98. ->assertUnprocessable();
  99. });
  100. it('should update the inventory sources', function () {
  101. // Arrange.
  102. $inventorySources = InventorySource::factory()->create();
  103. // Act and Assert.
  104. $this->loginAsAdmin();
  105. putJson(route('admin.settings.inventory_sources.update', $inventorySources->id), [
  106. 'code' => $code = strtolower(fake()->numerify('code######')),
  107. 'name' => $name = fake()->name(),
  108. 'priority' => $priority = rand(1, 10),
  109. 'contact_number' => $contactNumber = rand(1111111111, 9999999999),
  110. 'contact_email' => $contactEmail = fake()->email(),
  111. 'latitude' => fake()->latitude(),
  112. 'longitude' => fake()->longitude(),
  113. 'contact_name' => fake()->unique()->regexify('[A-Z0-9]{10}'),
  114. 'street' => fake()->streetName(),
  115. 'country' => preg_replace("/[^a-zA-Z0-9\s]/", '', fake()->country()),
  116. 'state' => fake()->state(),
  117. 'city' => fake()->city(),
  118. 'postcode' => fake()->postcode(),
  119. ])
  120. ->assertRedirect(route('admin.settings.inventory_sources.index'))
  121. ->isRedirection();
  122. $this->assertModelWise([
  123. InventorySource::class => [
  124. [
  125. 'code' => $code,
  126. 'name' => $name,
  127. 'priority' => $priority,
  128. 'contact_email' => $contactEmail,
  129. 'contact_number' => $contactNumber,
  130. ],
  131. ],
  132. ]);
  133. });
  134. it('should delete the inventory source', function () {
  135. // Arrange.
  136. $inventorySource = InventorySource::factory()->create();
  137. // Act and Assert.
  138. $this->loginAsAdmin();
  139. deleteJson(route('admin.settings.inventory_sources.delete', $inventorySource->id))
  140. ->assertOk()
  141. ->assertSeeText(trans('admin::app.settings.inventory-sources.delete-success'));
  142. });