Bladeren bron

ajout de groups de normalization pour addressPostal et fix test

Vincent GUFFON 4 jaren geleden
bovenliggende
commit
4c5e648000
2 gewijzigde bestanden met toevoegingen van 43 en 10 verwijderingen
  1. 35 7
      src/Entity/Core/AddressPostal.php
  2. 8 3
      tests/Service/Cotisation/UtilsTest.php

+ 35 - 7
src/Entity/Core/AddressPostal.php

@@ -3,46 +3,67 @@ declare(strict_types=1);
 
 namespace App\Entity\Core;
 
+use ApiPlatform\Core\Annotation\ApiResource;
 use App\Entity\Organization\OrganizationAddressPostal;
 use App\Repository\Core\AddressPostalRepository;
 use Doctrine\ORM\Mapping as ORM;
-
+use App\Entity\Person\PersonAddressPostal;
+use Symfony\Component\Serializer\Annotation\Groups;
+
+#[ApiResource(
+    collectionOperations: [
+        "get"
+    ],
+    itemOperations: [
+        "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW') and object.getOrganizationAddressPostal().getOrganization().getId() == user.getOrganization().getId()"],
+    ]
+)]
 #[ORM\Entity(repositoryClass: AddressPostalRepository::class)]
 class AddressPostal
 {
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
+    #[Groups(["address", "access_address"])]
     private ?int $id = null;
 
     #[ORM\ManyToOne]
+    #[Groups("address")]
     private ?Country $addressCountry = null;
 
     #[ORM\Column(length: 100, nullable: true)]
+    #[Groups("address")]
     private ?string $addressCity = null;
 
     #[ORM\Column(length: 100, nullable: true)]
+    #[Groups("address")]
     private ?string $addressOwner = null;
 
     #[ORM\Column(length: 20, nullable: true)]
+    #[Groups("address")]
     private ?string $postalCode = null;
 
     #[ORM\Column(length: 255, nullable: true)]
+    #[Groups("address")]
     private ?string $streetAddress = null;
 
     #[ORM\Column(length: 255, nullable: true)]
+    #[Groups("address")]
     private ?string $streetAddressSecond = null;
 
     #[ORM\Column(length: 255, nullable: true)]
+    #[Groups("address")]
     private ?string $streetAddressThird = null;
 
     #[ORM\Column(nullable: true)]
+    #[Groups("address")]
     private ?float $latitude = null;
 
     #[ORM\Column(nullable: true)]
+    #[Groups("address")]
     private ?float $longitude = null;
 
-    #[ORM\OneToOne(mappedBy: 'addressPostal', cascade: ['persist', 'remove'])]
+    #[ORM\OneToOne(mappedBy: 'addressPostal')]
     private OrganizationAddressPostal $organizationAddressPostal;
 
     public function getId(): ?int
@@ -165,13 +186,20 @@ class AddressPostal
 
     public function setOrganizationAddressPostal(OrganizationAddressPostal $organizationAddressPostal): self
     {
-        // set the owning side of the relation if necessary
-        if ($organizationAddressPostal->getAddressPostal() !== $this) {
-            $organizationAddressPostal->setAddressPostal($this);
-        }
-
         $this->organizationAddressPostal = $organizationAddressPostal;
 
         return $this;
     }
+
+    public function getPersonAddressPostal(): ?PersonAddressPostal
+    {
+        return $this->personAddressPostal;
+    }
+
+    public function setPersonAddressPostal(PersonAddressPostal $personAddressPostal): self
+    {
+        $this->personAddressPostal = $personAddressPostal;
+
+        return $this;
+    }
 }

+ 8 - 3
tests/Service/Cotisation/UtilsTest.php

@@ -22,10 +22,14 @@ class UtilsTest extends TestCase
     private OrganizationUtils $organizationUtilsMock;
 
     public function getOrganizationMock(): Organization{
-        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
-        return $organizationMock
+        $organizationMock = $this->getMockBuilder(Organization::class)
+            ->disableOriginalConstructor()
+            ->getMock();
+        $organizationMock
             ->method('getId')
             ->willReturn(1);
+        return $organizationMock;
+
     }
 
     public function getUtilsInstance(){
@@ -59,6 +63,7 @@ class UtilsTest extends TestCase
         $this->cotisationApiResourcesRepositoryMock =
             $this
                 ->getMockBuilder(CotisationApiResourcesRepository::class)
+                ->disableOriginalConstructor()
                 ->getMock();
     }
 
@@ -327,7 +332,7 @@ class UtilsTest extends TestCase
 
         $this->cotisationApiResourcesRepositoryMock
             ->method('isNotDGVCustomer')
-            ->with($organizationMock->getId(), $year)
+            ->with($organizationMock->getId())
             ->willReturn(true);
 
         $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) );