DiscussionTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Tests\Feature;
  3. use Illuminate\Foundation\Testing\RefreshDatabase;
  4. use Illuminate\Foundation\Testing\WithFaker;
  5. use Tests\TestCase;
  6. use Illuminate\Support\Str;
  7. class DiscussionTest extends TestCase
  8. {
  9. /**
  10. * A basic feature test example.
  11. *
  12. * @return void
  13. */
  14. public function test_example()
  15. {
  16. $token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJuYmYiOjE2NjgyMzE3MTksImV4cCI6MTY5OTc2NzcxOSwidWlkIjoiYmE1NDYzZjMtNzJkMS00NDEwLTg1OGUtZWFkZDEwODg0NzEzIiwiaWQiOiI0In0.LV4ItC5VCqXpbKIXT1zePcnfi-heCf3Df63w7qbXsT1i5KJtwJJC938CLgANjqwcQFa3lrR5TqvT1kkqD-Mmgg';
  17. //testing index
  18. $response = $this->get('/api/v2/discussion?view=question&id=eae9fd6f-7bac-4940-b80d-ad6cd6f433bf');
  19. $response->assertStatus(200);
  20. //testing store
  21. $response = $this->withHeaders([
  22. 'Authorization' => $token,
  23. ])->json('POST', '/api/v2/discussion',
  24. [
  25. 'title'=>'test',
  26. 'res_id'=>'eae9fd6f-7bac-4940-b80d-ad6cd6f433bf',
  27. 'res_type'=>'wbw',
  28. ]);
  29. $response->assertOk();
  30. $id = $response['data']['id'];
  31. $this->assertTrue(Str::isUuid($id));
  32. //testing answer
  33. $response = $this->withHeaders([
  34. 'Authorization' => $token,
  35. ])->json('POST', '/api/v2/discussion',
  36. [
  37. 'parent' => $id,
  38. 'content'=>'answer',
  39. 'res_id'=>'eae9fd6f-7bac-4940-b80d-ad6cd6f433bf',
  40. 'res_type'=>'wbw',
  41. ]);
  42. $response->assertOk();
  43. $id = $response['data']['id'];
  44. $this->assertTrue(Str::isUuid($id));
  45. }
  46. }