PlanTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Tests\Feature\API;
  3. use App\Models\Plan;
  4. use Tests\Feature\TestCase;
  5. class PlanTest extends TestCase
  6. {
  7. public function test_create_plan(): void
  8. {
  9. $form = Plan::factory()->make();
  10. $response = $this->post(route('plan.store'), $form->toArray());
  11. $response->assertStatus(201);
  12. }
  13. public function test_plan_list()
  14. {
  15. Plan::factory(30)->create();
  16. $response = $this->get(route('plan.index'));
  17. $response->assertStatus(200)
  18. ->assertJsonStructure([
  19. 'data' => [
  20. '*' => [
  21. 'id',
  22. 'title',
  23. 'requirement_total',
  24. 'project_total',
  25. 'begin',
  26. 'end',
  27. 'description',
  28. ]
  29. ]
  30. ]);
  31. }
  32. public function test_plan_show()
  33. {
  34. $plan = Plan::factory()->create();
  35. $response = $this->get(route('plan.show', ['plan' => $plan->id]));
  36. $response->assertStatus(200)
  37. ->assertJsonStructure([
  38. 'data' => [
  39. 'id',
  40. 'title',
  41. 'requirement_total',
  42. 'asset_id',
  43. 'parent_id',
  44. 'project_total',
  45. 'begin',
  46. 'end',
  47. 'description',
  48. ]
  49. ]);
  50. }
  51. public function test_plan_update(): void
  52. {
  53. $plan = Plan::factory()->create();
  54. $form = Plan::factory()->make();
  55. $response = $this->put(route('plan.update', ['plan' => $plan->id]), $form->toArray());
  56. $response->assertStatus(204);
  57. $newAsset = Plan::find($plan->id);
  58. $this->assertEquals($form->name, $newAsset->name);
  59. }
  60. public function test_plan_delete(): void
  61. {
  62. $plan = Plan::factory()->create();
  63. $response = $this->delete(route('plan.destroy', ['plan' => $plan->id]));
  64. $response->assertStatus(204);
  65. $this->assertNull(Plan::find($plan->id));
  66. }
  67. }