RelationTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Feature;
  3. use Illuminate\Foundation\Testing\RefreshDatabase;
  4. use Illuminate\Foundation\Testing\WithFaker;
  5. use Tests\TestCase;
  6. use App\Models\Relation;
  7. class RelationTest extends TestCase
  8. {
  9. private $token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJuYmYiOjE2NjgyMzE3MTksImV4cCI6MTY5OTc2NzcxOSwidWlkIjoiYmE1NDYzZjMtNzJkMS00NDEwLTg1OGUtZWFkZDEwODg0NzEzIiwiaWQiOiI0In0.LV4ItC5VCqXpbKIXT1zePcnfi-heCf3Df63w7qbXsT1i5KJtwJJC938CLgANjqwcQFa3lrR5TqvT1kkqD-Mmgg';
  10. /**
  11. * A basic feature test example.
  12. *
  13. * @return void
  14. */
  15. public function test_index()
  16. {
  17. $response = $this->get('/api/v2/relation?search=a');
  18. $response->assertStatus(200);
  19. }
  20. public function test_store()
  21. {
  22. //testing store
  23. $response = $this->withHeaders([
  24. 'Authorization' => $this->token,
  25. ])->json('POST', '/api/v2/relation',
  26. [
  27. 'name'=>'isv',
  28. 'case'=>['gen'],
  29. ]);
  30. $response->assertOk();
  31. $response = $this->withHeaders([
  32. 'Authorization' => $this->token,
  33. ])->json('POST', '/api/v2/relation',
  34. [
  35. 'name'=>'iov',
  36. ]);
  37. $response->assertOk();
  38. }
  39. public function test_show()
  40. {
  41. //testing store
  42. $id = Relation::value('id');
  43. $response = $this->get("/api/v2/relation/{$id}");
  44. $response->assertStatus(200);
  45. }
  46. public function test_update()
  47. {
  48. //testing store
  49. sleep(1);
  50. $id = Relation::value('id');
  51. $response = $this->withHeaders([
  52. 'Authorization' => $this->token,
  53. ])->json('PUT', "/api/v2/relation/{$id}",
  54. [
  55. 'name'=>'iov_2',
  56. 'case'=>['inst'],
  57. 'to'=>['inst'],
  58. ]);
  59. $response->assertOk();
  60. }
  61. public function test_delete(){
  62. //testing delete
  63. $id = Relation::value("id");
  64. $response = $this->withHeaders([
  65. 'Authorization' => $this->token,
  66. ])->delete("/api/v2/relation/{$id}");
  67. $response->assertOk();
  68. }
  69. }