|
|
@@ -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());
|
|
|
+
|
|
|
+ }
|
|
|
}
|