TaskTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. public 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. "parent_id",
  31. "begin",
  32. "end",
  33. "status",
  34. "assign_to",
  35. "created_by",
  36. ]
  37. ]
  38. ]);
  39. }
  40. public function test_task_show(): void
  41. {
  42. $task = Task::factory()->create();
  43. $response = $this->get(route('task.show', ['task' => $task->id]));
  44. $response->assertStatus(200)
  45. ->assertJsonStructure([
  46. 'data' => [
  47. "id",
  48. "name",
  49. "project_id",
  50. "project",
  51. "requirement_id",
  52. "naming_rule_id",
  53. "parent_id",
  54. "task_type",
  55. "doc_stage",
  56. "doc_type",
  57. "status",
  58. "assign",
  59. "description",
  60. "begin",
  61. "end",
  62. "mailto",
  63. "email_subject",
  64. "acl",
  65. "whitelist",
  66. "closed_by",
  67. "closed_at",
  68. "canceled_by",
  69. "canceled_at",
  70. "approve_by",
  71. "approve_at",
  72. "finished_by",
  73. "finished_at",
  74. "review_by",
  75. "review_at",
  76. "created_by",
  77. "custom_fields",
  78. "created_at",
  79. "updated_at"
  80. ]
  81. ]);
  82. }
  83. public function test_task_update(): void
  84. {
  85. $task = Task::factory()->create();
  86. $form = Task::factory()->make();
  87. $form->whitelist = [
  88. Auth::id(),
  89. ];
  90. $response = $this->putJson(route('task.update', ['task' => $task->id]), $form->toArray());
  91. $response->assertStatus(204);
  92. $newTask = Task::find($task->id);
  93. $this->assertEquals($form->name, $newTask->name);
  94. }
  95. public function test_task_delete(): void
  96. {
  97. $task = Task::factory()->create();
  98. $response = $this->delete(route('task.destroy', ['task' => $task->id]));
  99. $response->assertStatus(204);
  100. $this->assertNull(Task::find($task->id));
  101. }
  102. }