Selaa lähdekoodia

BTTF-51 : tests

Vincent GUFFON 4 vuotta sitten
vanhempi
commit
b5df193a76

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

@@ -3,6 +3,8 @@
 namespace App\Tests\Service\Cotisation;
 
 use App\Entity\Organization\Organization;
+use App\Enum\Cotisation\AlertStateEnum;
+use App\Repository\Cotisation\CotisationApiResourcesRepository;
 use App\Repository\Network\NetworkOrganizationRepository;
 use App\Service\Cotisation\Utils;
 use App\Service\Organization\Utils as OrganizationUtils;
@@ -11,6 +13,10 @@ use \App\Service\Network\Utils as NetworkUtils;
 
 class UtilsTest extends TestCase
 {
+    const MEMBERSHIP_WAITING = 495; // Affiliation in progress
+    const MEMBERSHIP_NOPAYMENT = 517; // Waiting paiement
+    const SUBMIT_IN_PROGRESS = 540; // Affiliation in progress
+
     private NetworkOrganizationRepository $networkOrganizationRepositoryMock;
     private NetworkUtils $networkUtilsMock;
     private OrganizationUtils $organizationUtilsMock;
@@ -33,6 +39,11 @@ class UtilsTest extends TestCase
             $this
                 ->getMockBuilder(OrganizationUtils::class)
                 ->getMock();
+
+        $this->cotisationApiResourcesRepositoryMock =
+            $this
+                ->getMockBuilder(CotisationApiResourcesRepository::class)
+                ->getMock();
     }
 
     /**
@@ -57,7 +68,12 @@ class UtilsTest extends TestCase
                 ->with($organizationMock)
                 ->willReturn(true);
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertTrue($utils->isLastParentAndCMF($organizationMock));
     }
 
@@ -81,7 +97,12 @@ class UtilsTest extends TestCase
             ->expects($this->never())
             ->method('isCMF');
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
     }
 
@@ -104,7 +125,12 @@ class UtilsTest extends TestCase
             ->with($organizationMock)
             ->willReturn(true);
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertTrue($utils->isStructureAndCMF($organizationMock));
     }
 
@@ -125,7 +151,12 @@ class UtilsTest extends TestCase
             ->expects($this->never())
             ->method('isCMF');
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertFalse($utils->isStructureAndCMF($organizationMock));
     }
 
@@ -148,7 +179,12 @@ class UtilsTest extends TestCase
             ->with($organizationMock)
             ->willReturn(true);
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertTrue($utils->isManagerAndCMF($organizationMock));
     }
 
@@ -169,7 +205,12 @@ class UtilsTest extends TestCase
             ->expects($this->never())
             ->method('isCMF');
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertFalse($utils->isManagerAndCMF($organizationMock));
     }
 
@@ -199,7 +240,12 @@ class UtilsTest extends TestCase
             ->expects($this->never())
             ->method('isCMF');
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertTrue($utils->isManagerAndNotLastParentAndCMF($organizationMock));
     }
 
@@ -230,7 +276,147 @@ class UtilsTest extends TestCase
             ->method('isCMF')
             ->willReturn(true);
 
-        $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock);
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
         $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
     }
+
+    /**
+     * @see Utils::getAlertState()
+     */
+    public function testGetAlertStateAffiliation(): void
+    {
+        $year = 2022;
+
+        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
+        $organizationMock
+            ->method('getId')
+            ->willReturn(1);
+
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
+
+        $this->cotisationApiResourcesRepositoryMock
+            ->method('getAffiliationState')
+            ->with($organizationMock->getId(), $year)
+            ->willReturn(self::MEMBERSHIP_WAITING);
+
+        $this->assertEquals(AlertStateEnum::AFFILIATION()->getValue(), $utils->getAlertState($organizationMock, $year) );
+
+        $this->cotisationApiResourcesRepositoryMock
+            ->method('getAffiliationState')
+            ->with($organizationMock->getId(), $year)
+            ->willReturn(self::SUBMIT_IN_PROGRESS);
+
+        $this->assertEquals(AlertStateEnum::AFFILIATION()->getValue(), $utils->getAlertState($organizationMock, $year) );
+
+    }
+
+    /**
+     * @see Utils::getAlertState()
+     */
+    public function testGetAlertStateInvoice(): void
+    {
+        $year = 2022;
+
+        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
+        $organizationMock
+            ->method('getId')
+            ->willReturn(1);
+
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
+
+        $this->cotisationApiResourcesRepositoryMock
+            ->method('getAffiliationState')
+            ->with($organizationMock->getId(), $year)
+            ->willReturn(self::MEMBERSHIP_NOPAYMENT);
+
+        $this->assertEquals(AlertStateEnum::INVOICE()->getValue(), $utils->getAlertState($organizationMock, $year) );
+    }
+
+    /**
+     * @see Utils::getAlertState()
+     */
+    public function testGetAlertStateInsurance(): void
+    {
+        $year = 2022;
+
+        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
+        $organizationMock
+            ->method('getId')
+            ->willReturn(1);
+
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
+
+        $this->cotisationApiResourcesRepositoryMock
+            ->method('isInsuranceNotDone')
+            ->with($organizationMock->getId(), $year)
+            ->willReturn(true);
+
+        $this->assertEquals(AlertStateEnum::INSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) );
+    }
+
+    /**
+     * @see Utils::getAlertState()
+     */
+    public function testGetAlertStateAdvertisingInsurance(): void
+    {
+        $year = 2022;
+
+        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
+        $organizationMock
+            ->method('getId')
+            ->willReturn(1);
+
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
+
+        $this->cotisationApiResourcesRepositoryMock
+            ->method('isNotDGVCustomer')
+            ->with($organizationMock->getId(), $year)
+            ->willReturn(true);
+
+        $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) );
+    }
+
+    /**
+     * @see Utils::getCurrentCotisationYear()
+     */
+    public function testGetCurrentCotisationYear(): void
+    {
+        $utils = new Utils(
+            $this->networkUtilsMock,
+            $this->organizationUtilsMock,
+            $this->networkOrganizationRepositoryMock,
+            $this->cotisationApiResourcesRepositoryMock
+        );
+        $today = new \DateTime('now');
+        if($today->format('m') <= 9)
+            $this->assertEquals($today->format('Y'), $utils->getCurrentCotisationYear());
+        else
+            $this->assertEquals(($today->format('Y') + 1), $utils->getCurrentCotisationYear());
+
+    }
 }

+ 29 - 0
tests/Service/Network/UtilsTest.php

@@ -21,6 +21,7 @@ class UtilsTest extends TestCase
         $networkCmf->setName('CMF');
         $networkOrganization = new NetworkOrganization();
         $networkOrganization->setNetwork($networkCmf);
+        $networkOrganization->setStartDate(new \DateTime('2000-09-11'));
         $this->organizationCmf = new Organization();
         $this->organizationCmf->addNetworkOrganization($networkOrganization);
 
@@ -53,6 +54,34 @@ class UtilsTest extends TestCase
         $this->assertFalse($result);
     }
 
+    /**
+     * @see Utils::isCMFAndActiveNow()
+     */
+    public function testIsCmfAndActiveNow():void
+    {
+        $result = $this->utils->isCMFAndActiveNow($this->organizationCmf);
+        $this->assertTrue($result);
+    }
+
+    /**
+     * @see Utils::isCMFAndActiveNow()
+     */
+    public function testIsCmfAndNotActiveNow():void
+    {
+        $networkCmf = new Network();
+        $networkCmf->setId(3);
+        $networkCmf->setName('CMF');
+        $networkOrganization = new NetworkOrganization();
+        $networkOrganization->setNetwork($networkCmf);
+        $networkOrganization->setStartDate(new \DateTime('2000-09-11'));
+        $networkOrganization->setEndDate(new \DateTime('2020-09-11'));
+        $organizationCmfNotActive = new Organization();
+        $organizationCmfNotActive->addNetworkOrganization($networkOrganization);
+
+        $result = $this->utils->isCMFAndActiveNow($organizationCmfNotActive);
+        $this->assertFalse($result);
+    }
+
     /**
      * @see Utils::isOrganizationBelongToTheNetwork()
      */

+ 17 - 0
tests/Service/Organization/UtilsTest.php

@@ -2,8 +2,10 @@
 namespace App\Test\Service\Organization;
 
 use App\Entity\Organization\Organization;
+use App\Entity\Organization\Parameters;
 use App\Entity\Organization\Settings;
 use App\Enum\Organization\SettingsProductEnum;
+use App\Service\Organization\Utils;
 use App\Service\Organization\Utils as OrganizationUtils;
 use PHPUnit\Framework\TestCase;
 
@@ -88,4 +90,19 @@ class UtilsTest extends TestCase
             ->willReturn(12097);
         $this->assertTrue($this->organizationUtils->isOrganizationIsCMF($organizationMock));
     }
+
+    /**
+     * @see OrganizationUtils::getOrganizationCurrentActivityYear()
+     */
+    public function testGetOrganizationCurrentActivityYear(){
+        $parameters = new Parameters();
+        $parameters->setMusicalDate(new \DateTime('2020-09-01'));
+        $this->organization->setParameters($parameters);
+
+        $today = new \DateTime('now');
+        if($today->format('m') < 9)
+            $this->assertEquals( ($today->format('Y') - 1), Utils::getOrganizationCurrentActivityYear($this->organization));
+        else
+            $this->assertEquals($today->format('Y'), Utils::getOrganizationCurrentActivityYear($this->organization));
+    }
 }

+ 0 - 27
tests/Service/Utils/DatesTest.php

@@ -1,27 +0,0 @@
-<?php
-namespace App\Tests\Service\Utils;
-
-use App\Service\Utils\Dates;
-use PHPUnit\Framework\TestCase;
-
-class DatesTest extends TestCase
-{
-    /**
-     * @see Dates::isIntervalIsValidNow()
-     */
-    public function testIsIntervalIsValidNow():void
-    {
-        $dates = new Dates();
-        $this->assertTrue($dates->isIntervalIsValidNow(new \DateTime('2020-01-02'), new \DateTime('2025-01-02')));
-        $this->assertTrue($dates->isIntervalIsValidNow(new \DateTime('2020-01-02'), null));
-    }
-
-    /**
-     * @see Dates::isIntervalIsValidNow()
-     */
-    public function testIsIntervalIsNotValidNow():void
-    {
-        $dates = new Dates();
-        $this->assertFalse($dates->isIntervalIsValidNow(new \DateTime('2019-01-02'), new \DateTime('2020-01-02')));
-    }
-}

+ 26 - 0
tests/Service/Utils/DatesUtilsTest.php

@@ -0,0 +1,26 @@
+<?php
+namespace App\Tests\Service\Utils;
+
+use App\Service\Utils\Dates;
+use App\Service\Utils\DatesUtils;
+use PHPUnit\Framework\TestCase;
+
+class DatesUtilsTest extends TestCase
+{
+    /**
+     * @see DatesUtils::isIntervalIsValidNow()
+     */
+    public function testIsIntervalIsValidNow():void
+    {
+        $this->assertTrue(DatesUtils::isIntervalIsValidNow(new \DateTime('2020-01-02'), new \DateTime('2025-01-02')));
+        $this->assertTrue(DatesUtils::isIntervalIsValidNow(new \DateTime('2020-01-02'), null));
+    }
+
+    /**
+     * @see DatesUtils::isIntervalIsValidNow()
+     */
+    public function testIsIntervalIsNotValidNow():void
+    {
+        $this->assertFalse(DatesUtils::isIntervalIsValidNow(new \DateTime('2019-01-02'), new \DateTime('2020-01-02')));
+    }
+}