CurrenciesTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. use Illuminate\Support\Arr;
  3. use Webkul\Core\Models\Currency;
  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 currencies index page', function () {
  9. // Act and Assert.
  10. $this->loginAsAdmin();
  11. get(route('admin.settings.currencies.index'))
  12. ->assertOk()
  13. ->assertSeeText(trans('admin::app.settings.currencies.index.title'))
  14. ->assertSeeText(trans('admin::app.settings.currencies.index.create-btn'));
  15. });
  16. it('should fail the validation with errors when certain field not provided when store the currencies', function () {
  17. // Act and Assert.
  18. $this->loginAsAdmin();
  19. postJson(route('admin.settings.currencies.store'))
  20. ->assertJsonValidationErrorFor('code')
  21. ->assertJsonValidationErrorFor('name')
  22. ->assertUnprocessable();
  23. });
  24. it('should store the newly created currencies', function () {
  25. // Act and Assert.
  26. $this->loginAsAdmin();
  27. postJson(route('admin.settings.currencies.store'), $data = [
  28. 'code' => fake()->randomElement(['EUR', 'GBP', 'JPY', 'AUD', 'CHF', 'CAD', 'CNY', 'BRL']),
  29. 'name' => fake()->name(),
  30. 'symbol' => fake()->randomElement(['€', '£', '¥', 'A$', 'CHF', 'C$', '¥', 'R$']),
  31. 'decimal' => rand(1, 4),
  32. 'group_separator' => '-',
  33. 'decimal_separator' => '-',
  34. 'currency_position' => fake()->randomElement(['left', 'left_with_space', 'right', 'right_with_space']),
  35. ])
  36. ->assertOk()
  37. ->assertSeeText(trans('admin::app.settings.currencies.index.create-success'));
  38. $this->assertModelWise([
  39. Currency::class => [
  40. $data,
  41. ],
  42. ]);
  43. });
  44. it('should return the currencies for edit', function () {
  45. // Arrange.
  46. $currency = Currency::factory()->create();
  47. // Act and Assert.
  48. $this->loginAsAdmin();
  49. get(route('admin.settings.currencies.edit', $currency->id))
  50. ->assertOk()
  51. ->assertJsonFragment($currency->toArray());
  52. });
  53. it('should fail the validation with errors when certain field not provided when update the currencies', function () {
  54. // Arrange.
  55. $currency = Currency::factory()->create();
  56. // Act and Assert.
  57. $this->loginAsAdmin();
  58. putJson(route('admin.settings.currencies.update'), [
  59. 'id' => $currency->id,
  60. ])
  61. ->assertJsonValidationErrorFor('name')
  62. ->assertUnprocessable();
  63. });
  64. it('should update the specified currency', function () {
  65. // Arrange.
  66. $currency = Currency::factory()->create();
  67. // Act and Assert.
  68. $this->loginAsAdmin();
  69. putJson(route('admin.settings.currencies.update'), $data = [
  70. 'id' => $currency->id,
  71. 'name' => fake()->name(),
  72. ])
  73. ->assertOk()
  74. ->assertSeeText(trans('admin::app.settings.currencies.index.update-success'));
  75. $this->assertModelWise([
  76. Currency::class => [
  77. [
  78. ...Arr::except($currency->toArray(), ['updated_at', 'created_at']),
  79. ...$data,
  80. ],
  81. ],
  82. ]);
  83. });
  84. it('should delete the currencies', function () {
  85. // Arrange.
  86. $currency = Currency::factory()->create();
  87. // Act and Assert.
  88. $this->loginAsAdmin();
  89. deleteJson(route('admin.settings.currencies.delete', $currency->id))
  90. ->assertOk()
  91. ->assertSeeText(trans('admin::app.settings.currencies.index.delete-success'));
  92. $this->assertDatabaseMissing('currencies', [
  93. 'id' => $currency->id,
  94. ]);
  95. });