CustomerGroupsTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. use Webkul\Customer\Models\CustomerGroup;
  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 listing page of customer groups', function () {
  8. // Act and Assert.
  9. $this->loginAsAdmin();
  10. get(route('admin.customers.groups.index'))
  11. ->assertOk()
  12. ->assertSeeText(trans('admin::app.customers.groups.index.title'))
  13. ->assertSeeText(trans('admin::app.customers.groups.index.create.create-btn'));
  14. });
  15. it('should fail the validation with errors when certain inputs are not provided when store in customer groups', function () {
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. postJson(route('admin.customers.groups.store'))
  19. ->assertJsonValidationErrorFor('code')
  20. ->assertJsonValidationErrorFor('name')
  21. ->assertUnprocessable();
  22. });
  23. it('should store the newly created customers group', function () {
  24. // Act and Assert.
  25. $this->loginAsAdmin();
  26. postJson(route('admin.customers.groups.store'), [
  27. 'code' => $code = fake()->numerify('code########'),
  28. 'name' => $name = fake()->name(),
  29. ])
  30. ->assertOk()
  31. ->assertSeeText(trans('admin::app.customers.groups.index.create.success'));
  32. $this->assertModelWise([
  33. CustomerGroup::class => [
  34. [
  35. 'code' => $code,
  36. 'name' => $name,
  37. ],
  38. ],
  39. ]);
  40. });
  41. it('should fail the validation with errors when certain inputs are not provided when update in customer groups', function () {
  42. // Arrange.
  43. $customerGroup = CustomerGroup::factory()->create();
  44. // Act and Assert.
  45. $this->loginAsAdmin();
  46. putJson(route('admin.customers.groups.update', $customerGroup->id))
  47. ->assertJsonValidationErrorFor('code')
  48. ->assertJsonValidationErrorFor('name')
  49. ->assertUnprocessable();
  50. });
  51. it('should update the existing customers group', function () {
  52. // Arrange.
  53. $customerGroup = CustomerGroup::factory()->create();
  54. // Act and Assert.
  55. $this->loginAsAdmin();
  56. putJson(route('admin.customers.groups.update'), [
  57. 'name' => $name = fake()->name(),
  58. 'code' => $customerGroup->code,
  59. 'id' => $customerGroup->id,
  60. ])
  61. ->assertOk()
  62. ->assertSeeText(trans('admin::app.customers.groups.index.edit.success'));
  63. $this->assertModelWise([
  64. CustomerGroup::class => [
  65. [
  66. 'name' => $name,
  67. 'code' => $customerGroup->code,
  68. 'id' => $customerGroup->id,
  69. ],
  70. ],
  71. ]);
  72. });
  73. it('should delete the existing customers groups', function () {
  74. // Arrange.
  75. $customerGroup = CustomerGroup::factory()->create([
  76. 'is_user_defined' => true,
  77. ]);
  78. // Act and Assert.
  79. $this->loginAsAdmin();
  80. deleteJson(route('admin.customers.groups.delete', $customerGroup->id))
  81. ->assertOk()
  82. ->assertSeeText(trans('admin::app.customers.groups.index.edit.delete-success'));
  83. $this->assertDatabaseMissing('customer_groups', [
  84. 'id' => $customerGroup->id,
  85. ]);
  86. });