123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace Tests\Feature\API;
- use App\Models\Task;
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Illuminate\Support\Facades\Auth;
- use Tests\Feature\TestCase;
- class TaskTest extends TestCase
- {
- public function test_create_task(): void
- {
- $form = Task::factory()->make();
- $form->whitelist = [
- Auth::id(),
- ];
- $response = $this->postJson(route('task.store'), $form->toArray());
- $response->assertStatus(201);
- }
- public function test_task_list()
- {
- Task::factory(30)->create();
- $response = $this->get(route('task.index'));
- $response->assertStatus(200)
- ->assertJsonStructure([
- 'data' => [
- '*' => [
- "id",
- "name",
- "parent_id",
- "begin",
- "end",
- "status",
- "assign_to",
- "created_by",
- ]
- ]
- ]);
- }
- public function test_task_show(): void
- {
- $task = Task::factory()->create();
- $response = $this->get(route('task.show', ['task' => $task->id]));
- $response->assertStatus(200)
- ->assertJsonStructure([
- 'data' => [
- "id",
- "name",
- "project_id",
- "project",
- "requirement_id",
- "naming_rule_id",
- "parent_id",
- "task_type",
- "doc_stage",
- "doc_type",
- "status",
- "assign",
- "description",
- "begin",
- "end",
- "mailto",
- "email_subject",
- "acl",
- "whitelist",
- "closed_by",
- "closed_at",
- "canceled_by",
- "canceled_at",
- "approve_by",
- "approve_at",
- "finished_by",
- "finished_at",
- "review_by",
- "review_at",
- "created_by",
- "custom_fields",
- "created_at",
- "updated_at"
- ]
- ]);
- }
- public function test_task_update(): void
- {
- $task = Task::factory()->create();
- $form = Task::factory()->make();
- $form->whitelist = [
- Auth::id(),
- ];
- $response = $this->putJson(route('task.update', ['task' => $task->id]), $form->toArray());
- $response->assertStatus(204);
- $newTask = Task::find($task->id);
- $this->assertEquals($form->name, $newTask->name);
- }
- public function test_task_delete(): void
- {
- $task = Task::factory()->create();
- $response = $this->delete(route('task.destroy', ['task' => $task->id]));
- $response->assertStatus(204);
- $this->assertNull(Task::find($task->id));
- }
- }
|