TaxRatesTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. use Webkul\Tax\Models\TaxRate;
  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 tax rate index page', function () {
  8. // Act and Assert.
  9. $this->loginAsAdmin();
  10. get(route('admin.settings.taxes.rates.index'))
  11. ->assertOk()
  12. ->assertSeeText(trans('admin::app.settings.taxes.rates.index.title'))
  13. ->assertSeeText(trans('admin::app.settings.taxes.rates.index.button-title'));
  14. });
  15. it('should returns the create page of tax rate', function () {
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. get(route('admin.settings.taxes.rates.create'))
  19. ->assertOk()
  20. ->assertSeeText(trans('admin::app.settings.taxes.rates.create.title'))
  21. ->assertSeeText(trans('admin::app.settings.taxes.rates.create.back-btn'));
  22. });
  23. it('should fail the validation with errors when certain field not provided when store the tax rates', function () {
  24. // Act and Assert.
  25. $this->loginAsAdmin();
  26. postJson(route('admin.settings.taxes.rates.store'))
  27. ->assertJsonValidationErrorFor('identifier')
  28. ->assertJsonValidationErrorFor('country')
  29. ->assertJsonValidationErrorFor('tax_rate')
  30. ->assertUnprocessable();
  31. });
  32. it('should store the newly created tax rates', function () {
  33. // Act and Assert.
  34. $this->loginAsAdmin();
  35. postJson(route('admin.settings.taxes.rates.store'), $data = [
  36. 'identifier' => strtolower(fake()->name()),
  37. 'country' => fake()->country(),
  38. 'tax_rate' => rand(1, 50),
  39. ])
  40. ->assertRedirect(route('admin.settings.taxes.rates.index'))
  41. ->isRedirection();
  42. $this->assertModelWise([
  43. TaxRate::class => [
  44. [
  45. 'identifier' => $data['identifier'],
  46. 'country' => $data['country'],
  47. 'tax_rate' => $data['tax_rate'],
  48. ],
  49. ],
  50. ]);
  51. });
  52. it('should returns the edit page of the tax rate', function () {
  53. // Arrange.
  54. $taxRate = TaxRate::factory()->create();
  55. // Act and Assert.
  56. $this->loginAsAdmin();
  57. get(route('admin.settings.taxes.rates.edit', $taxRate->id))
  58. ->assertOk()
  59. ->assertSeeText(trans('admin::app.settings.taxes.rates.edit.title'))
  60. ->assertSeeText(trans('admin::app.settings.taxes.rates.edit.back-btn'));
  61. });
  62. it('should fail the validation with errors when certain field not provided when update the tax rates', function () {
  63. // Arrange.
  64. $taxRate = TaxRate::factory()->create();
  65. // Act and Assert.
  66. $this->loginAsAdmin();
  67. putJson(route('admin.settings.taxes.rates.update', $taxRate->id))
  68. ->assertJsonValidationErrorFor('identifier')
  69. ->assertJsonValidationErrorFor('country')
  70. ->assertJsonValidationErrorFor('tax_rate')
  71. ->assertUnprocessable();
  72. });
  73. it('should update the tax rate', function () {
  74. // Arrange.
  75. $taxRate = TaxRate::factory()->create();
  76. // Act and Assert.
  77. $this->loginAsAdmin();
  78. putJson(route('admin.settings.taxes.rates.update', $taxRate->id), $data = [
  79. 'identifier' => fake()->name(),
  80. 'country' => fake()->country(),
  81. 'tax_rate' => $taxRate->tax_rate,
  82. ])
  83. ->assertRedirect(route('admin.settings.taxes.rates.index'))
  84. ->isRedirection();
  85. $this->assertModelWise([
  86. TaxRate::class => [
  87. [
  88. 'identifier' => $data['identifier'],
  89. 'country' => $data['country'],
  90. 'tax_rate' => $taxRate->tax_rate,
  91. ],
  92. ],
  93. ]);
  94. });
  95. it('should delete the tax rate', function () {
  96. // Arrange.
  97. $taxRate = TaxRate::factory()->create();
  98. // Act and Assert.
  99. $this->loginAsAdmin();
  100. deleteJson(route('admin.settings.taxes.rates.delete', $taxRate->id))
  101. ->assertOk()
  102. ->assertJsonPath('message', trans('admin::app.settings.taxes.rates.delete-success'));
  103. $this->assertDatabaseMissing('tax_rates', [
  104. 'id' => $taxRate->id,
  105. ]);
  106. });