ResidenceAreaTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Tests\Application\Billing;
  3. use App\Tests\Application\OtWebTestCase;
  4. class ResidenceAreaTest extends OtWebTestCase
  5. {
  6. // todo : attention certain tests ne se passent pas comme prévu : probleme de droit
  7. public function testGetResidenceArea(): void
  8. {
  9. $this->loginAs($this->user);
  10. $this->assertResponseIsSuccessful();
  11. $this->get('/api/residence_areas');
  12. $this->assertResponseStatusCodeSame(200);
  13. $this->assertJsonContains([
  14. '@context' => '/api/contexts/ResidenceArea',
  15. '@id' => '/api/residence_areas',
  16. '@type' => 'hydra:Collection',
  17. 'hydra:totalItems' => 1,
  18. 'hydra:member' => [
  19. ["label" => "Résidence 1"]
  20. ],
  21. ]);
  22. }
  23. public function testPostResidenceArea()
  24. {
  25. $this->loginAs($this->user);
  26. $this->assertResponseIsSuccessful();
  27. $this->post('/api/residence_areas', [
  28. 'label' => 'toto',
  29. 'billingSetting' => '/api/billing_settings/1'
  30. ]);
  31. $this->assertResponseStatusCodeSame(201);
  32. $this->assertJsonContains([
  33. '@context' => '/api/contexts/ResidenceArea',
  34. '@type' => 'ResidenceArea',
  35. 'label' => 'toto'
  36. ]);
  37. }
  38. public function testPutResidenceArea()
  39. {
  40. $this->loginAs($this->user);
  41. $this->put('/api/residence_areas/1', [
  42. 'label' => 'tata',
  43. ]);
  44. $this->assertResponseStatusCodeSame(200);
  45. $this->assertJsonContains([
  46. '@context' => '/api/contexts/ResidenceArea',
  47. '@type' => 'ResidenceArea',
  48. 'label' => 'tata',
  49. 'billingSetting' => '/api/billing_settings/1'
  50. ]);
  51. }
  52. public function testDeleteResidenceArea()
  53. {
  54. $this->loginAs($this->user);
  55. $this->delete('/api/residence_areas/1');
  56. $this->assertResponseStatusCodeSame(204);
  57. }
  58. /// change adminAccess to false and retest
  59. public function testGetResidenceCollectionWithBadRoles()
  60. {
  61. $this->loginAsStudent($this->user);
  62. $this->get('/api/residence_areas');
  63. $this->assertResponseStatusCodeSame(403);
  64. }
  65. }