NamingRuleTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Tests\Feature\API;
  3. use App\Models\NamingRule;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Foundation\Testing\WithFaker;
  6. use Tests\Feature\TestCase;
  7. class NamingRuleTest extends TestCase
  8. {
  9. public function test_create_naming_rule(): void
  10. {
  11. $form = NamingRule::factory()->make();
  12. $response = $this->post(route('naming-rule.store'), $form->toArray());
  13. $response->assertStatus(201);
  14. }
  15. public function test_naming_rule_list()
  16. {
  17. NamingRule::factory(30)->create();
  18. $response = $this->get(route('naming-rule.index'));
  19. $response->assertStatus(200)
  20. ->assertJsonStructure([
  21. 'data' => [
  22. '*' => [
  23. 'id',
  24. 'name',
  25. 'global',
  26. 'status',
  27. 'company'
  28. ]
  29. ]
  30. ]);
  31. }
  32. public function test_naming_rule_enabled()
  33. {
  34. NamingRule::factory(30)->create();
  35. $response = $this->get(route('naming-rule.enabled'));
  36. $response->assertStatus(200)
  37. ->assertJsonStructure([
  38. 'data' => [
  39. '*' => [
  40. 'id',
  41. 'name',
  42. ]
  43. ]
  44. ]);
  45. }
  46. public function test_naming_rule_show(): void
  47. {
  48. $namingRule = NamingRule::factory()->create();
  49. $response = $this->get(route('naming-rule.show', ['naming_rule' => $namingRule->id]));
  50. $response->assertStatus(200)
  51. ->assertJsonStructure([
  52. 'data' => [
  53. 'id',
  54. 'name',
  55. 'global',
  56. 'status',
  57. 'company'
  58. ]
  59. ]);
  60. }
  61. public function test_naming_rule_update(): void
  62. {
  63. $namingRule = NamingRule::factory()->create();
  64. $form = NamingRule::factory()->make();
  65. $response = $this->put(route('naming-rule.update', ['naming_rule' => $namingRule->id]), $form->toArray());
  66. $response->assertStatus(204);
  67. $newAsset = NamingRule::find($namingRule->id);
  68. $this->assertEquals($form->name, $newAsset->name);
  69. }
  70. private function test_naming_rule_delete(): void
  71. {
  72. $namingRule = NamingRule::factory()->create();
  73. $response = $this->delete(route('naming-rule.destroy', ['naming_rule' => $namingRule->id]));
  74. $response->assertStatus(204);
  75. $this->assertNull(NamingRule::find($namingRule->id));
  76. }
  77. }