LibraryTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Tests\Feature\API;
  3. use App\Models\Library;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Foundation\Testing\WithFaker;
  6. use Illuminate\Support\Facades\Auth;
  7. use Tests\Feature\TestCase;
  8. class LibraryTest extends TestCase
  9. {
  10. public function test_create_library(): void
  11. {
  12. $form = Library::factory()->make();
  13. $form->whitelist = [
  14. Auth::id(),
  15. ];
  16. $response = $this->post(route('library.store'), $form->toArray());
  17. $response->assertStatus(201);
  18. }
  19. public function test_library_update(): void
  20. {
  21. $library = Library::factory()->create();
  22. $form = Library::factory()->make();
  23. $response = $this->put(route('library.update', ['library' => $library->id]), $form->toArray());
  24. $response->assertStatus(204);
  25. $newAsset = Library::find($library->id);
  26. $this->assertEquals($form->name, $newAsset->name);
  27. }
  28. public function test_library_show(): void
  29. {
  30. $library = Library::factory()->create();
  31. $response = $this->get(route('library.show', ['library' => $library->id]));
  32. $response->assertStatus(200)
  33. ->assertJsonStructure([
  34. 'data' => [
  35. 'id',
  36. 'name',
  37. 'asset_id',
  38. 'project_id',
  39. 'acl',
  40. 'whitelist'
  41. ]
  42. ]);
  43. }
  44. }