ProjectTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Tests\Feature\API;
  3. use App\Models\Asset;
  4. use App\Models\Plan;
  5. use App\Models\Project;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Foundation\Testing\WithFaker;
  8. use Tests\Feature\TestCase;
  9. class ProjectTest extends TestCase
  10. {
  11. public function test_project_list()
  12. {
  13. Project::factory(30)->create();
  14. $response = $this->get(route('project.index'));
  15. $response->assertStatus(200)
  16. ->assertJsonStructure([
  17. 'data' => [
  18. '*' => [
  19. 'id',
  20. 'name',
  21. 'code',
  22. 'status',
  23. 'const',
  24. 'begin',
  25. 'end',
  26. 'available_days',
  27. ]
  28. ]
  29. ]);
  30. }
  31. public function test_project_create(): void
  32. {
  33. $form = Project::factory()->make();
  34. $form->whitelist = [
  35. 1
  36. ];
  37. $form->plans = [
  38. Plan::factory()->create()->id,
  39. Plan::factory()->create()->id,
  40. ];
  41. $form->assets = [
  42. Asset::factory()->create()->id,
  43. Asset::factory()->create()->id,
  44. ];
  45. $response = $this->post(route('project.store'), $form->toArray());
  46. $response->assertStatus(201);
  47. }
  48. }