ResidenceAreaTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Tests\Application\Billing;
  3. use App\Tests\Application\OtWebTestCase;
  4. class ResidenceAreaTest extends OtWebTestCase
  5. {
  6. public function setUp(): void
  7. {
  8. parent::setUp();
  9. }
  10. public function testResidenceAreaResource(): void
  11. {
  12. $this->logger->info("\033[1;34mStarting test... Retrieve the list of all residence area for an admin user\033[0m");
  13. $this->loginAs($this->user);
  14. $this->get('/api/residence_areas');
  15. $this->assertResponseStatusCodeSame(200);
  16. $this->logger->info("\033[1;32mTest 'testGetResidenceAreaCollection' succeed\033[0m");
  17. $this->logger->info("\033[1;34mStarting test... try to put a new label on R-A as an admin user \033[0m");
  18. $this->loginAs($this->user);
  19. $this->put('/api/residence_areas/1', [
  20. 'label' => 'tata',
  21. ]);
  22. $this->assertResponseStatusCodeSame(200);
  23. $this->assertJsonContains([
  24. '@context' => '/api/contexts/ResidenceArea',
  25. '@type' => 'ResidenceArea',
  26. 'label' => 'tata',
  27. 'billingSetting' => '/api/billing_settings/1',
  28. ]);
  29. $this->logger->info("\033[1;32mTest 'testPutResidenceArea' succeed\033[0m");
  30. $this->logger->info("\033[1;34mStarting test... Add a residence area as an admin\033[0m");
  31. $this->loginAs($this->user);
  32. $this->post('/api/residence_areas', [
  33. 'label' => 'toto',
  34. 'billingSetting' => '/api/billing_settings/1',
  35. ]);
  36. $this->assertResponseStatusCodeSame(201);
  37. $this->assertJsonContains([
  38. '@context' => '/api/contexts/ResidenceArea',
  39. '@type' => 'ResidenceArea',
  40. 'label' => 'toto',
  41. ]);
  42. $this->logger->info("\033[1;32mTest 'testPostResidenceArea' succeed\033[0m");
  43. $this->logger->info("\033[1;34mStarting test... delete a residence area as an admin\033[0m");
  44. $this->loginAs($this->user);
  45. $this->delete('/api/residence_areas/1');
  46. $this->assertResponseStatusCodeSame(204);
  47. $this->logger->info("\033[1;32mTest 'testDeleteResidenceArea' succeed\033[0m");
  48. $this->logger->info("\033[1;34mStarting test... get all residence area as an non-admin\033[0m");
  49. $this->loginAsStudent($this->user);
  50. $this->get('/api/residence_areas');
  51. $this->assertResponseStatusCodeSame(403);
  52. $this->logger->info("\033[1;32mTest 'testGetResidenceCollectionWithBadRoles' succeed\033[0m");
  53. }
  54. // public function testPutResidenceArea()
  55. // {
  56. // $this->logger->info("\033[1;34mStarting test... try to put a new label on R-A as an admin user \033[0m");
  57. // $this->loginAs($this->user);
  58. // $this->put('/api/residence_areas/1', [
  59. // 'label' => 'tata',
  60. // ]);
  61. // $this->assertResponseStatusCodeSame(200);
  62. // $this->assertJsonContains([
  63. // '@context' => '/api/contexts/ResidenceArea',
  64. // '@type' => 'ResidenceArea',
  65. // 'label' => 'tata',
  66. // 'billingSetting' => '/api/billing_settings/1'
  67. // ]);
  68. // $this->logger->info("\033[1;32mTest 'testPutResidenceArea' succeed\033[0m");
  69. // }
  70. // public function testPostResidenceArea()
  71. // {
  72. // $this->logger->info("\033[1;34mStarting test... Add a residence area as an admin\033[0m");
  73. // $this->loginAs($this->user);
  74. // $this->assertResponseIsSuccessful();
  75. // $this->post('/api/residence_areas', [
  76. // 'label' => 'toto',
  77. // 'billingSetting' => '/api/billing_settings/1'
  78. // ]);
  79. // $this->assertResponseStatusCodeSame(201);
  80. // $this->assertJsonContains([
  81. // '@context' => '/api/contexts/ResidenceArea',
  82. // '@type' => 'ResidenceArea',
  83. // 'label' => 'toto'
  84. // ]);
  85. // $this->logger->info("\033[1;32mTest 'testPostResidenceArea' succeed\033[0m");
  86. // }
  87. // public function testDeleteResidenceArea()
  88. // {
  89. // $this->logger->info("\033[1;34mStarting test... delete a residence area as an admin\033[0m");
  90. // $this->loginAs($this->user);
  91. // $this->delete('/api/residence_areas/1');
  92. // $this->assertResponseStatusCodeSame(204);
  93. // $this->logger->info("\033[1;32mTest 'testDeleteResidenceArea' succeed\033[0m");
  94. // }
  95. // /// change adminAccess to false and retest
  96. // public function testGetResidenceCollectionWithBadRoles()
  97. // {
  98. // $this->logger->info("\033[1;34mStarting test... get all residence area as an non-admin\033[0m");
  99. // $this->loginAsStudent($this->user);
  100. // $this->get('/api/residence_areas');
  101. // $this->assertResponseStatusCodeSame(403);
  102. // $this->logger->info("\033[1;32mTest 'testGetResidenceCollectionWithBadRoles' succeed\033[0m");
  103. // }
  104. }