TaskTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Tests\Feature\API;
  3. use App\Models\Task;
  4. use App\Models\User;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Foundation\Testing\WithFaker;
  7. use Illuminate\Support\Facades\Auth;
  8. use Tests\Feature\TestCase;
  9. class TaskTest extends TestCase
  10. {
  11. public function test_create_task(): void
  12. {
  13. $form = Task::factory()->make();
  14. $form->whitelist = [
  15. Auth::id(),
  16. ];
  17. $response = $this->postJson(route('task.store'), $form->toArray());
  18. $response->assertStatus(201);
  19. }
  20. protected function test_task_list()
  21. {
  22. Task::factory(30)->create();
  23. $response = $this->get(route('task.index'));
  24. $response->assertStatus(200)
  25. ->assertJsonStructure([
  26. 'data' => [
  27. '*' => [
  28. 'id',
  29. 'name',
  30. 'global',
  31. 'status',
  32. 'company'
  33. ]
  34. ]
  35. ]);
  36. }
  37. public function test_task_show(): void
  38. {
  39. $task = Task::factory()->create();
  40. $response = $this->get(route('task.show', ['task' => $task->id]));
  41. $response->assertStatus(200)
  42. ->assertJsonStructure([
  43. 'data' => [
  44. "id",
  45. "name",
  46. "project_id",
  47. "project",
  48. "requirement_id",
  49. "naming_rule_id",
  50. "parent_id",
  51. "task_type",
  52. "doc_stage",
  53. "doc_type",
  54. "status",
  55. "assign",
  56. "description",
  57. "begin",
  58. "end",
  59. "mailto",
  60. "email_subject",
  61. "acl",
  62. "whitelist",
  63. "closed_by",
  64. "closed_at",
  65. "canceled_by",
  66. "canceled_at",
  67. "approve_by",
  68. "approve_at",
  69. "finished_by",
  70. "finished_at",
  71. "review_by",
  72. "review_at",
  73. "created_by",
  74. "custom_fields",
  75. "created_at",
  76. "updated_at"
  77. ]
  78. ]);
  79. }
  80. protected function test_task_update(): void
  81. {
  82. $task = Task::factory()->create();
  83. $form = Task::factory()->make();
  84. $response = $this->put(route('task.update', ['task' => $task->id]), $form->toArray());
  85. $response->assertStatus(204);
  86. $newAsset = Task::find($task->id);
  87. $this->assertEquals($form->name, $newAsset->name);
  88. }
  89. protected function test_task_delete(): void
  90. {
  91. $task = Task::factory()->create();
  92. $response = $this->delete(route('task.destroy', ['task' => $task->id]));
  93. $response->assertStatus(204);
  94. $this->assertNull(Task::find($task->id));
  95. }
  96. }